Apollo 10.0
自动驾驶开放平台
protobuf_traits.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#ifndef CYBER_MESSAGE_PROTOBUF_TRAITS_H_
18#define CYBER_MESSAGE_PROTOBUF_TRAITS_H_
19
20#include <cassert>
21#include <memory>
22#include <string>
23
26
27namespace apollo {
28namespace cyber {
29namespace message {
30
31template <typename MessageT,
32 typename std::enable_if<
33 std::is_base_of<google::protobuf::Message, MessageT>::value,
34 int>::type = 0>
35inline std::string MessageType() {
36 return MessageT::descriptor()->full_name();
37}
38
39template <typename MessageT,
40 typename std::enable_if<
41 std::is_base_of<google::protobuf::Message, MessageT>::value,
42 int>::type = 0>
43std::string MessageType(const MessageT& message) {
44 return message.GetDescriptor()->full_name();
45}
46
47template <typename MessageT,
48 typename std::enable_if<
49 std::is_base_of<google::protobuf::Message, MessageT>::value,
50 int>::type = 0>
51inline void GetDescriptorString(const MessageT& message,
52 std::string* desc_str) {
53 ProtobufFactory::Instance()->GetDescriptorString(message, desc_str);
54}
55
56template <typename MessageT,
57 typename std::enable_if<
58 std::is_base_of<google::protobuf::Message, MessageT>::value,
59 int>::type = 0>
60inline void GetDescriptorString(const std::string& type,
61 std::string* desc_str) {
62 ProtobufFactory::Instance()->GetDescriptorString(type, desc_str);
63}
64
65template <typename MessageT,
66 typename std::enable_if<
67 std::is_base_of<google::protobuf::Message, MessageT>::value,
68 int>::type = 0>
69bool RegisterMessage(const MessageT& message) {
70 return ProtobufFactory::Instance()->RegisterMessage(message);
71}
72
73template <typename MessageT,
74 typename std::enable_if<
75 std::is_base_of<google::protobuf::Message, MessageT>::value,
76 bool>::type = true>
77bool SerializeToArenaMessageWrapper(const MessageT& message,
78 ArenaMessageWrapper* wrapper,
79 MessageT** message_ptr) {
80 *message_ptr = wrapper->SetMessage(message);
81 return true;
82}
83
84template <typename MessageT,
85 typename std::enable_if<
86 std::is_base_of<google::protobuf::Message, MessageT>::value,
87 bool>::type = true>
89 MessageT* message, MessageT** message_ptr) {
90 *message_ptr = wrapper->GetMessage<MessageT>();
91 // message->CopyFrom(*message_ptr);
92 return true;
93}
94
95} // namespace message
96} // namespace cyber
97} // namespace apollo
98
99#endif // CYBER_MESSAGE_PROTOBUF_TRAITS_H_
MessageT * SetMessage(const MessageT &message)
bool RegisterMessage(const MessageT &message)
std::enable_if< HasParseFromArenaMessageWrapper< T >::value, bool >::type ParseFromArenaMessageWrapper(ArenaMessageWrapper *wrapper, T *message, T **message_ptr)
std::enable_if< HasSerializeToArenaMessageWrapper< T >::value, bool >::type SerializeToArenaMessageWrapper(const T &message, ArenaMessageWrapper *wrapper, T **message_ptr)
std::string MessageType()
void GetDescriptorString(const std::string &type, std::string *desc_str)
class register implement
Definition arena_queue.h:37