Apollo 10.0
自动驾驶开放平台
apollo::cyber::message::ProtobufFactory类 参考

#include <protobuf_factory.h>

apollo::cyber::message::ProtobufFactory 的协作图:

Public 成员函数

 ~ProtobufFactory ()
 
bool RegisterMessage (const std::string &proto_desc_str)
 
bool RegisterPythonMessage (const std::string &proto_str)
 
bool RegisterMessage (const google::protobuf::Message &message)
 
bool RegisterMessage (const Descriptor &desc)
 
bool RegisterMessage (const FileDescriptorProto &file_desc_proto)
 
void GetDescriptorString (const std::string &type, std::string *desc_str)
 
void GetProtoPath (const std::string &type, std::string &location)
 
google::protobuf::Message * GenerateMessageByType (const std::string &type) const
 
const Descriptor * FindMessageTypeByFile (const FileDescriptorProto &file_desc_proto)
 
const Descriptor * FindMessageTypeByName (const std::string &type) const
 
const google::protobuf::ServiceDescriptor * FindServiceByName (const std::string &name) const
 
void GetPythonDesc (const std::string &type, std::string *desc_str)
 

静态 Public 成员函数

static void GetDescriptorString (const google::protobuf::Message &message, std::string *desc_str)
 
static void GetDescriptorString (const Descriptor *desc, std::string *desc_str)
 

详细描述

在文件 protobuf_factory.h57 行定义.

构造及析构函数说明

◆ ~ProtobufFactory()

apollo::cyber::message::ProtobufFactory::~ProtobufFactory ( )

在文件 protobuf_factory.cc32 行定义.

32 {
33 factory_.reset();
34 pool_.reset();
35}

成员函数说明

◆ FindMessageTypeByFile()

const Descriptor * apollo::cyber::message::ProtobufFactory::FindMessageTypeByFile ( const FileDescriptorProto &  file_desc_proto)

在文件 protobuf_factory.cc239 行定义.

240 {
241 const std::string& scope = file_desc_proto.package();
242 std::string type;
243 if (file_desc_proto.message_type_size()) {
244 type = scope + "." + file_desc_proto.message_type(0).name();
245 }
246 const google::protobuf::Descriptor* descriptor =
247 pool_->FindMessageTypeByName(type);
248 return descriptor;
249}

◆ FindMessageTypeByName()

const Descriptor * apollo::cyber::message::ProtobufFactory::FindMessageTypeByName ( const std::string &  type) const

在文件 protobuf_factory.cc229 行定义.

230 {
231 return pool_->FindMessageTypeByName(name);
232}

◆ FindServiceByName()

const google::protobuf::ServiceDescriptor * apollo::cyber::message::ProtobufFactory::FindServiceByName ( const std::string &  name) const

在文件 protobuf_factory.cc234 行定义.

235 {
236 return pool_->FindServiceByName(name);
237}

◆ GenerateMessageByType()

google::protobuf::Message * apollo::cyber::message::ProtobufFactory::GenerateMessageByType ( const std::string &  type) const

在文件 protobuf_factory.cc186 行定义.

187 {
188 google::protobuf::Message* message = GetMessageByGeneratedType(type);
189 if (message != nullptr) {
190 return message;
191 }
192
193 const google::protobuf::Descriptor* descriptor =
194 pool_->FindMessageTypeByName(type);
195 if (descriptor == nullptr) {
196 AERROR << "cannot find [" << type << "] descriptor";
197 return nullptr;
198 }
199
200 const google::protobuf::Message* prototype =
201 factory_->GetPrototype(descriptor);
202 if (prototype == nullptr) {
203 AERROR << "cannot find [" << type << "] prototype";
204 return nullptr;
205 }
206
207 return prototype->New();
208}
#define AERROR
Definition log.h:44

◆ GetDescriptorString() [1/3]

void apollo::cyber::message::ProtobufFactory::GetDescriptorString ( const Descriptor *  desc,
std::string *  desc_str 
)
static

在文件 protobuf_factory.cc125 行定义.

126 {
127 ProtoDesc proto_desc;
128 if (!GetProtoDesc(desc->file(), &proto_desc)) {
129 AERROR << "Failed to get descriptor from message";
130 return;
131 }
132
133 if (!proto_desc.SerializeToString(desc_str)) {
134 AERROR << "Failed to get descriptor from message";
135 }
136}

◆ GetDescriptorString() [2/3]

void apollo::cyber::message::ProtobufFactory::GetDescriptorString ( const google::protobuf::Message &  message,
std::string *  desc_str 
)
static

在文件 protobuf_factory.cc138 行定义.

139 {
140 const Descriptor* desc = message.GetDescriptor();
141 return GetDescriptorString(desc, desc_str);
142}
static void GetDescriptorString(const google::protobuf::Message &message, std::string *desc_str)

◆ GetDescriptorString() [3/3]

void apollo::cyber::message::ProtobufFactory::GetDescriptorString ( const std::string &  type,
std::string *  desc_str 
)

在文件 protobuf_factory.cc155 行定义.

156 {
157 auto desc = DescriptorPool::generated_pool()->FindMessageTypeByName(type);
158 if (desc != nullptr) {
159 return GetDescriptorString(desc, desc_str);
160 }
161
162 desc = pool_->FindMessageTypeByName(type);
163 if (desc == nullptr) {
164 return;
165 }
166 return GetDescriptorString(desc, desc_str);
167}

◆ GetProtoPath()

void apollo::cyber::message::ProtobufFactory::GetProtoPath ( const std::string &  type,
std::string &  location 
)

在文件 protobuf_factory.cc169 行定义.

170 {
171 auto desc = DescriptorPool::generated_pool()->FindMessageTypeByName(type);
172 if (desc != nullptr) {
173 location = (desc->file())->name();
174 return;
175 }
176
177 desc = pool_->FindMessageTypeByName(type);
178 if (desc == nullptr) {
179 return;
180 }
181 location = (desc->file())->name();
182 return;
183}

◆ GetPythonDesc()

void apollo::cyber::message::ProtobufFactory::GetPythonDesc ( const std::string &  type,
std::string *  desc_str 
)

在文件 protobuf_factory.cc144 行定义.

145 {
146 auto desc = pool_->FindMessageTypeByName(type);
147 if (desc == nullptr) {
148 return;
149 }
150 google::protobuf::DescriptorProto dp;
151 desc->CopyTo(&dp);
152 dp.SerializeToString(desc_str);
153}

◆ RegisterMessage() [1/4]

bool apollo::cyber::message::ProtobufFactory::RegisterMessage ( const Descriptor &  desc)

在文件 protobuf_factory.cc43 行定义.

43 {
44 FileDescriptorProto file_desc_proto;
45 desc.file()->CopyTo(&file_desc_proto);
46 return RegisterMessage(file_desc_proto);
47}
bool RegisterMessage(const std::string &proto_desc_str)

◆ RegisterMessage() [2/4]

bool apollo::cyber::message::ProtobufFactory::RegisterMessage ( const FileDescriptorProto &  file_desc_proto)

在文件 protobuf_factory.cc88 行定义.

89 {
90 ErrorCollector ec;
91 std::lock_guard<std::mutex> lg(register_mutex_);
92 auto file_desc = pool_->BuildFileCollectingErrors(file_desc_proto, &ec);
93 if (!file_desc) {
94 /*
95 AERROR << "Failed to register protobuf messages ["
96 << file_desc_proto.name() << "]";
97 */
98 return false;
99 }
100 return true;
101}

◆ RegisterMessage() [3/4]

bool apollo::cyber::message::ProtobufFactory::RegisterMessage ( const google::protobuf::Message &  message)

在文件 protobuf_factory.cc37 行定义.

38 {
39 const Descriptor* descriptor = message.GetDescriptor();
40 return RegisterMessage(*descriptor);
41}

◆ RegisterMessage() [4/4]

bool apollo::cyber::message::ProtobufFactory::RegisterMessage ( const std::string &  proto_desc_str)

在文件 protobuf_factory.cc81 行定义.

81 {
82 ProtoDesc proto_desc;
83 proto_desc.ParseFromString(proto_desc_str);
84 return RegisterMessage(proto_desc);
85}

◆ RegisterPythonMessage()

bool apollo::cyber::message::ProtobufFactory::RegisterPythonMessage ( const std::string &  proto_str)

在文件 protobuf_factory.cc75 行定义.

75 {
76 FileDescriptorProto file_desc_proto;
77 file_desc_proto.ParseFromString(proto_str);
78 return RegisterMessage(file_desc_proto);
79}

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