Apollo
10.0
自动驾驶开放平台
readable_info.cc
浏览该文件的文档.
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
#include "
cyber/transport/shm/readable_info.h
"
18
19
#include <cstring>
20
21
#include "
cyber/common/log.h
"
22
23
namespace
apollo
{
24
namespace
cyber {
25
namespace
transport {
26
27
const
size_t
ReadableInfo::kSize
=
sizeof
(uint64_t) * 2 + \
28
sizeof
(int32_t) +
sizeof
(int32_t);
29
30
ReadableInfo::ReadableInfo
()
31
: host_id_(0),
32
block_index_(0),
33
arena_block_index_(-1),
34
channel_id_(0) {}
35
36
ReadableInfo::ReadableInfo
(uint64_t host_id, int32_t block_index,
37
uint64_t channel_id, int32_t arena_block_index)
38
: host_id_(host_id),
39
block_index_(block_index),
40
arena_block_index_(arena_block_index),
41
channel_id_(channel_id) {}
42
43
ReadableInfo::~ReadableInfo
() {}
44
45
ReadableInfo
&
ReadableInfo::operator=
(
const
ReadableInfo
& other) {
46
if
(
this
!= &other) {
47
this->host_id_ = other.host_id_;
48
this->block_index_ = other.block_index_;
49
this->channel_id_ = other.channel_id_;
50
this->arena_block_index_ = other.arena_block_index_;
51
}
52
return
*
this
;
53
}
54
55
bool
ReadableInfo::SerializeTo
(std::string* dst)
const
{
56
RETURN_VAL_IF_NULL
(dst,
false
);
57
58
dst->assign(
reinterpret_cast<
char
*
>
(
const_cast<
uint64_t*
>
(&host_id_)),
59
sizeof
(host_id_));
60
dst->append(
reinterpret_cast<
char
*
>
(
const_cast<
int32_t*
>
(&block_index_)),
61
sizeof
(block_index_));
62
dst->append(
reinterpret_cast<
char
*
>
(
const_cast<
uint64_t*
>
(&channel_id_)),
63
sizeof
(channel_id_));
64
dst->append(
reinterpret_cast<
char
*
>
(
const_cast<
int32_t*
>
(
65
&arena_block_index_)),
sizeof
(arena_block_index_));
66
return
true
;
67
}
68
69
bool
ReadableInfo::DeserializeFrom
(
const
std::string& src) {
70
return
DeserializeFrom
(src.data(), src.size());
71
}
72
73
bool
ReadableInfo::DeserializeFrom
(
const
char
* src, std::size_t len) {
74
RETURN_VAL_IF_NULL
(src,
false
);
75
if
(len !=
kSize
) {
76
AWARN
<<
"src size["
<< len <<
"] mismatch."
;
77
return
false
;
78
}
79
80
char
* ptr =
const_cast<
char
*
>
(src);
81
memcpy(
reinterpret_cast<
char
*
>
(&host_id_), ptr,
sizeof
(host_id_));
82
ptr +=
sizeof
(host_id_);
83
memcpy(
reinterpret_cast<
char
*
>
(&block_index_), ptr,
sizeof
(block_index_));
84
ptr +=
sizeof
(block_index_);
85
memcpy(
reinterpret_cast<
char
*
>
(&channel_id_), ptr,
sizeof
(channel_id_));
86
ptr +=
sizeof
(channel_id_);
87
memcpy(
reinterpret_cast<
char
*
>
(&arena_block_index_),
88
ptr,
sizeof
(arena_block_index_));
89
return
true
;
90
}
91
92
}
// namespace transport
93
}
// namespace cyber
94
}
// namespace apollo
apollo::cyber::transport::ReadableInfo
Definition
readable_info.h:32
apollo::cyber::transport::ReadableInfo::kSize
static const size_t kSize
Definition
readable_info.h:58
apollo::cyber::transport::ReadableInfo::~ReadableInfo
virtual ~ReadableInfo()
Definition
readable_info.cc:43
apollo::cyber::transport::ReadableInfo::SerializeTo
bool SerializeTo(std::string *dst) const
Definition
readable_info.cc:55
apollo::cyber::transport::ReadableInfo::operator=
ReadableInfo & operator=(const ReadableInfo &other)
Definition
readable_info.cc:45
apollo::cyber::transport::ReadableInfo::ReadableInfo
ReadableInfo()
Definition
readable_info.cc:30
apollo::cyber::transport::ReadableInfo::DeserializeFrom
bool DeserializeFrom(const std::string &src)
Definition
readable_info.cc:69
log.h
RETURN_VAL_IF_NULL
#define RETURN_VAL_IF_NULL(ptr, val)
Definition
log.h:98
AWARN
#define AWARN
Definition
log.h:43
apollo
class register implement
Definition
arena_queue.h:37
readable_info.h
cyber
transport
shm
readable_info.cc