CARLA
 
载入中...
搜索中...
未找到
ObstacleDetectionEventSerializer.h
浏览该文件的文档.
1// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8// 这是一个预处理指令,用于确保头文件只被包含一次
9
10#include "carla/Buffer.h"
11// 引入carla项目中的Buffer.h头文件
12
13#include "carla/Debug.h"
14// 引入carla项目中的Debug.h头文件
15
16#include "carla/Memory.h"
17// 引入carla项目中的Memory.h头文件
18
19#include "carla/rpc/Actor.h"
20// 引入carla项目中rpc模块下的Actor.h头文件
22// 引入carla项目中sensor模块下的RawData.h头文件
23
24namespace carla {
25namespace sensor {
26
27 class SensorData;
28// 前置声明SensorData类,告知编译器后续会有这个类的定义,在当前代码位置可以使用该类的指针或引用类型,便于解决类之间相互引用时的编译顺序问题
29
30namespace s11n {
31
32 /// Serializes the current state of the whole episode.
34 public:
35
36 struct Data {
37
39// 定义一个rpc::Actor类型的成员变量self_actor
40
42// 定义一个rpc::Actor类型的成员变量other_actor
43
44 float distance;
45 // 定义一个float类型的成员变量distance,用于表示距离相关的信息
46
47 MSGPACK_DEFINE_ARRAY(self_actor, other_actor, distance)
48// 这应该是一个宏用于定义如何将包含self_actor、other_actor、distance这几个成员的结构体进行序列化,告诉序列化库要处理的成员变量列表
49 };
50
51 constexpr static auto header_offset = 0u;
52// 定义一个常量表达式(constexpr)类型的静态变量header_offset,并初始化为0(无符号整数类型)
53
54 static Data DeserializeRawData(const RawData &message) {
55// 定义一个静态成员函数DeserializeRawData,用于从给定的RawData类型的对象(通常是传感器原始数据)中反序列化出Data结构体类型的数据。
56// 参数message是一个const引用,避免不必要的数据拷贝,传入要进行反序列化的原始数据
57
58 return MsgPack::UnPack<Data>(message.begin(), message.size());
59 // 调用MsgPack序列化库的UnPack函数,将从message对象表示的数据起始位置(message.begin())到数据末尾(message.size()指定的数据长度范围)的数据进行反序列化,转换为Data结构体类型并返回
60 }
61
62 template <typename SensorT>
64 const SensorT &,
65 rpc::Actor self_actor,
66 rpc::Actor other_actor,
67 float distance) {
68// 定义一个函数模板Serialize,用于将相关数据进行序列化并返回一个Buffer类型的结果
69 // 它是一个静态函数,并且是模板函数,可以适用于不同类型的SensorT
70 // 第一个参数是一个const引用类型的SensorT对象(具体类型由调用时传入的实际类型决定),后面三个参数分别是自身Actor、其他Actor以及距离信息,这些都是要参与序列化的数据
71
72 return MsgPack::Pack(Data{self_actor, other_actor, distance});
73// 创建一个Data结构体对象,使用传入的self_actor、other_actor、distance进行初始化,然后调用MsgPack序列化库的Pack函数(推测用于序列化)将这个Data结构体对象进行序列化,并返回序列化后的结果(存储在Buffer类型中)
74 }
75
77// 定义一个静态成员函数Deserialize,用于从右值引用类型的RawData对象(传感器原始数据)中反序列化出一个指向SensorData类的智能指针(SharedPtr<SensorData>)。
78// 这里使用右值引用可以更高效地处理临时对象等情况
79 };
80
81} // namespace s11n
82} // namespace sensor
83} // namespace carla
一块原始数据。 请注意,如果需要更多容量,则会分配一个新的内存块,并 删除旧的内存块。这意味着默认情况下,缓冲区只能增长。要释放内存,使用 clear 或 pop。
static Buffer Pack(const T &obj)
Definition MsgPack.h:18
包装一个传感器生成的原始数据以及一些有用的元信息。
Definition RawData.h:20
auto begin() noexcept
指向传感器生成的数据的开始迭代器。
Definition RawData.h:52
size_t size() const
传感器生成的数据的字节大小。
Definition RawData.h:82
Serializes the current state of the whole episode.
static Buffer Serialize(const SensorT &, rpc::Actor self_actor, rpc::Actor other_actor, float distance)
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
boost::shared_ptr< T > SharedPtr
使用这个SharedPtr(boost::shared_ptr)以保持与boost::python的兼容性, 但未来如果可能的话,我们希望能为std::shared_ptr制作一个Python适配器。
Definition Memory.h:19