CARLA
 
载入中...
搜索中...
未找到
CollisionEventSerializer.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#include "carla/Buffer.h"
10#include "carla/Debug.h"
11#include "carla/Memory.h"
12#include "carla/rpc/Actor.h"
13#include "carla/geom/Vector3D.h"
15
16// 命名空间 carla
17namespace carla {
18 // 命名空间 sensor
19 namespace sensor {
20
21 // 前置声明 SensorData 类
22 class SensorData;
23
24 // 命名空间 s11n
25 namespace s11n {
26
27 /// 序列化整个事件的当前状态的类
29 public:
30 // 结构体 Data,可能用于存储序列化所需的数据
31 struct Data {
32 // 表示自身的 Actor 对象
34 // 表示另一个 Actor 对象
36 // 表示法向冲量的 Vector3D 对象
38
39 // 使用 MSGPACK_DEFINE_ARRAY 宏来定义 msgpack 序列化和反序列化的数组元素,方便序列化和反序列化操作
40 MSGPACK_DEFINE_ARRAY(self_actor, other_actor, normal_impulse)
41 };
42
43 // 定义一个常量,表示头部偏移量为 0
44 constexpr static auto header_offset = 0u;
45
46 // 从原始数据反序列化数据的静态函数
47 static Data DeserializeRawData(const RawData &message) {
48 // 使用 MsgPack 库的 UnPack 函数将 message 中的数据解包为 Data 类型
49 return MsgPack::UnPack<Data>(message.begin(), message.size());
50 }
51
52 // 模板函数 Serialize,用于序列化数据,SensorT 是一个模板参数
53 template <typename SensorT>
55 const SensorT &,
56 rpc::Actor self_actor,
57 rpc::Actor other_actor,
58 geom::Vector3D normal_impulse) {
59 // 使用 MsgPack 库的 Pack 函数将输入的数据打包为 Buffer 类型
60 return MsgPack::Pack(Data{self_actor, other_actor, normal_impulse});
61 }
62
63 // 静态函数 Deserialize,声明但未实现,接收一个右值引用的 RawData 作为输入
65 };
66
67 } // namespace s11n
68 } // namespace sensor
69} // 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
序列化整个事件的当前状态的类
static Buffer Serialize(const SensorT &, rpc::Actor self_actor, rpc::Actor other_actor, geom::Vector3D normal_impulse)
static Data DeserializeRawData(const RawData &message)
static SharedPtr< SensorData > Deserialize(RawData &&data)
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
boost::shared_ptr< T > SharedPtr
使用这个SharedPtr(boost::shared_ptr)以保持与boost::python的兼容性, 但未来如果可能的话,我们希望能为std::shared_ptr制作一个Python适配器。
Definition Memory.h:19