Apollo 11.0
自动驾驶开放平台
base_map_node_config.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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
18
19#include <memory>
20
21namespace apollo {
22namespace localization {
23namespace msf {
24namespace pyramid_map {
25
27
29
30std::shared_ptr<BaseMapNodeConfig> BaseMapNodeConfig::Clone() {
31 std::shared_ptr<BaseMapNodeConfig> map_node_config(new BaseMapNodeConfig());
32 map_node_config->node_index_ = node_index_;
33 map_node_config->map_version_ = map_version_;
34 memcpy(map_node_config->body_md5_, body_md5_, sizeof(body_md5_));
35 map_node_config->body_size_ = body_size_;
36 map_node_config->has_map_version_ = has_map_version_;
37 map_node_config->has_body_md5_ = has_body_md5_;
38
39 return map_node_config;
40}
41
42unsigned int BaseMapNodeConfig::LoadBinary(const unsigned char *buf) {
43 size_t binary_size = 0;
44
45 // map_version
46 const uint16_t *us_p = reinterpret_cast<const uint16_t *>(buf);
47 if (has_map_version_) {
48 binary_size += sizeof(uint16_t);
49 map_version_ = static_cast<MapVersion>(*us_p);
50 ++us_p;
51 }
52
53 // body_md5
54 const unsigned char *uc_p = reinterpret_cast<const unsigned char *>(us_p);
55 if (has_body_md5_) {
56 binary_size += sizeof(body_md5_);
57 memcpy(body_md5_, uc_p, sizeof(body_md5_));
58 uc_p += MD5LENTH;
59 }
60
61 binary_size += sizeof(unsigned int) + sizeof(int) + sizeof(unsigned int) +
62 sizeof(unsigned int) + sizeof(unsigned int);
63 // node_index._resolution_id
64 const unsigned int *ui_p = reinterpret_cast<const unsigned int *>(us_p);
66 ++ui_p;
67
68 // node_index._zone_id
69 const int *int_p = reinterpret_cast<const int *>(ui_p);
70 node_index_.zone_id_ = *int_p;
71 ++int_p;
72
73 // node_index._m
74 ui_p = reinterpret_cast<const unsigned int *>(int_p);
75 node_index_.m_ = *ui_p;
76 ++ui_p;
77
78 // node_index._n
79 node_index_.n_ = *ui_p;
80 ++ui_p;
81
82 // the body size
83 body_size_ = *ui_p;
84
85 return static_cast<unsigned int>(binary_size);
86}
87
88unsigned int BaseMapNodeConfig::CreateBinary(unsigned char *buf,
89 size_t buf_size) const {
90 unsigned int target_size = GetBinarySize();
91
92 if (buf_size < target_size) {
93 return 0;
94 }
95
96 // map_version
97 uint16_t *us_p = reinterpret_cast<uint16_t *>(buf);
98 if (has_map_version_) {
99 *us_p = static_cast<uint16_t>(map_version_);
100 ++us_p;
101 }
102
103 // body_md5
104 unsigned char *uc_p = reinterpret_cast<unsigned char *>(us_p);
105 if (has_body_md5_) {
106 memcpy(uc_p, body_md5_, sizeof(body_md5_));
107 uc_p += MD5LENTH;
108 }
109
110 // node_index._resolution_id
111 unsigned int *ui_p = reinterpret_cast<unsigned int *>(us_p);
113 ++ui_p;
114
115 // node_index._zone_id
116 int *int_p = reinterpret_cast<int *>(ui_p);
117 *int_p = node_index_.zone_id_;
118 ++int_p;
119
120 // node_index._m
121 ui_p = reinterpret_cast<unsigned int *>(int_p);
122 *ui_p = node_index_.m_;
123 ++ui_p;
124
125 // node_index._n
126 *ui_p = node_index_.n_;
127 ++ui_p;
128
129 // the body size
130 *ui_p = static_cast<unsigned int>(body_size_);
131
132 return target_size;
133}
134
136 size_t binary_size = 0;
137
138 // map_version
139 if (has_map_version_) {
140 binary_size += sizeof(uint16_t);
141 }
142
143 // body_md5
144 if (has_body_md5_) {
145 binary_size += sizeof(body_md5_);
146 }
147
148 // node_index._resolution_id
149 // node_index._zone_id
150 // node_index._m
151 // node_index._n
152 binary_size += sizeof(unsigned int) + sizeof(int) + sizeof(unsigned int) +
153 sizeof(unsigned int);
154
155 // the body size
156 binary_size += sizeof(unsigned int);
157 return static_cast<unsigned int>(binary_size);
158}
159
160} // namespace pyramid_map
161} // namespace msf
162} // namespace localization
163} // namespace apollo
#define MD5LENTH
virtual std::shared_ptr< BaseMapNodeConfig > Clone()
Alloc a new map node config.
virtual unsigned int GetBinarySize() const
Get the size of the config in bytes.
virtual unsigned int CreateBinary(unsigned char *buf, size_t buf_size) const
Create the binary map node config.
virtual unsigned int LoadBinary(const unsigned char *buf)
Load the map node config from a binary chunk.
unsigned int m_
The map node ID at the northing direction.
unsigned int resolution_id_
The ID of the resolution.
unsigned int n_
The map node ID at the easting direction.
class register implement
Definition arena_queue.h:37