Apollo 10.0
自动驾驶开放平台
apollo::bridge::BridgeProtoSerializedBuf< T > 模板类 参考

#include <bridge_proto_serialized_buf.h>

apollo::bridge::BridgeProtoSerializedBuf< T > 的协作图:

Public 成员函数

 BridgeProtoSerializedBuf ()
 
 ~BridgeProtoSerializedBuf ()
 
char * GetFrame (size_t index)
 
bool Serialize (const std::shared_ptr< T > &proto, const std::string &msg_name)
 
const char * GetSerializedBuf (size_t index) const
 
size_t GetSerializedBufCount () const
 
size_t GetSerializedBufSize (size_t index) const
 

详细描述

template<typename T>
class apollo::bridge::BridgeProtoSerializedBuf< T >

在文件 bridge_proto_serialized_buf.h30 行定义.

构造及析构函数说明

◆ BridgeProtoSerializedBuf()

template<typename T >
apollo::bridge::BridgeProtoSerializedBuf< T >::BridgeProtoSerializedBuf ( )
inline

在文件 bridge_proto_serialized_buf.h32 行定义.

32{}

◆ ~BridgeProtoSerializedBuf()

在文件 bridge_proto_serialized_buf.h57 行定义.

57 {
58 for (auto frame : frames_) {
59 FREE_ARRY(frame.buf_);
60 }
61}
#define FREE_ARRY(arry)
Definition macro.h:24

成员函数说明

◆ GetFrame()

template<typename T >
char * apollo::bridge::BridgeProtoSerializedBuf< T >::GetFrame ( size_t  index)

◆ GetSerializedBuf()

template<typename T >
const char * apollo::bridge::BridgeProtoSerializedBuf< T >::GetSerializedBuf ( size_t  index) const
inline

在文件 bridge_proto_serialized_buf.h38 行定义.

38 {
39 return frames_[index].buf_;
40 }

◆ GetSerializedBufCount()

template<typename T >
size_t apollo::bridge::BridgeProtoSerializedBuf< T >::GetSerializedBufCount ( ) const
inline

在文件 bridge_proto_serialized_buf.h41 行定义.

41{ return frames_.size(); }

◆ GetSerializedBufSize()

template<typename T >
size_t apollo::bridge::BridgeProtoSerializedBuf< T >::GetSerializedBufSize ( size_t  index) const
inline

在文件 bridge_proto_serialized_buf.h42 行定义.

42 {
43 return frames_[index].buf_len_;
44 }

◆ Serialize()

template<typename T >
bool apollo::bridge::BridgeProtoSerializedBuf< T >::Serialize ( const std::shared_ptr< T > &  proto,
const std::string &  msg_name 
)

在文件 bridge_proto_serialized_buf.h64 行定义.

65 {
66 bsize msg_len = static_cast<bsize>(proto->ByteSizeLong());
67 char *tmp = new char[msg_len]();
68 if (!proto->SerializeToArray(tmp, static_cast<int>(msg_len))) {
69 FREE_ARRY(tmp);
70 return false;
71 }
72 bsize offset = 0;
73 bsize frame_index = 0;
74 uint32_t total_frames = static_cast<uint32_t>(msg_len / FRAME_SIZE +
75 (msg_len % FRAME_SIZE ? 1 : 0));
76
77 while (offset < msg_len) {
78 bsize left = msg_len - frame_index * FRAME_SIZE;
79 bsize cpy_size = (left > FRAME_SIZE) ? FRAME_SIZE : left;
80
81 BridgeHeader header;
82 header.SetHeaderVer(0);
83 header.SetMsgName(msg_name);
84 header.SetMsgID(proto->header().sequence_num());
85 header.SetTimeStamp(proto->header().timestamp_sec());
86 header.SetMsgSize(msg_len);
87 header.SetTotalFrames(total_frames);
88 header.SetFrameSize(cpy_size);
89 header.SetIndex(frame_index);
90 header.SetFramePos(frame_index * FRAME_SIZE);
91 hsize header_size = header.GetHeaderSize();
92 Buf buf;
93 buf.buf_ = new char[cpy_size + header_size];
94 buf.buf_len_ = cpy_size + header_size;
95 header.Serialize(buf.buf_, buf.buf_len_);
96 memcpy(buf.buf_ + header_size, tmp + frame_index * FRAME_SIZE, cpy_size);
97 frames_.push_back(buf);
98 frame_index++;
99 offset += cpy_size;
100 }
101 FREE_ARRY(tmp);
102 return true;
103}
constexpr uint32_t FRAME_SIZE
Definition macro.h:36

该类的文档由以下文件生成: