Fast DDS  Version 3.0.1
Fast DDS
Loading...
Searching...
No Matches
BinaryProperty.hpp
1// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
19#ifndef FASTDDS_RTPS_COMMON__BINARYPROPERTY_HPP
20#define FASTDDS_RTPS_COMMON__BINARYPROPERTY_HPP
21
22#include <string>
23#include <vector>
24#include <iostream>
25#include <cstdint>
26
27namespace eprosima {
28namespace fastdds {
29namespace rtps {
30
32{
33public:
34
36 : propagate_(false)
37 {
38 }
39
41 const BinaryProperty& property)
42 : name_(property.name_)
43 , value_(property.value_)
44 , propagate_(property.propagate_)
45 {
46 }
47
49 BinaryProperty&& property)
50 : name_(std::move(property.name_))
51 , value_(std::move(property.value_))
52 , propagate_(property.propagate_)
53 {
54 }
55
57 const std::string& name,
58 const std::vector<uint8_t>& value)
59 : name_(name)
60 , value_(value)
61 {
62 }
63
65 std::string&& name,
66 std::vector<uint8_t>&& value)
67 : name_(std::move(name))
68 , value_(std::move(value))
69 {
70 }
71
73 const BinaryProperty& property)
74 {
75 name_ = property.name_;
76 value_ = property.value_;
77 propagate_ = property.propagate_;
78 return *this;
79 }
80
82 BinaryProperty&& property)
83 {
84 name_ = std::move(property.name_);
85 value_ = std::move(property.value_);
86 propagate_ = property.propagate_;
87 return *this;
88 }
89
91 const BinaryProperty& b) const
92 {
93 return (this->name_ == b.name_) &&
94 (this->value_ == b.value_);
95 }
96
97 void name(
98 const std::string& name)
99 {
100 name_ = name;
101 }
102
103 void name(
104 std::string&& name)
105 {
106 name_ = std::move(name);
107 }
108
109 const std::string& name() const
110 {
111 return name_;
112 }
113
114 std::string& name()
115 {
116 return name_;
117 }
118
119 void value(
120 const std::vector<uint8_t>& value)
121 {
122 value_ = value;
123 }
124
125 void value(
126 std::vector<uint8_t>&& value)
127 {
128 value_ = std::move(value);
129 }
130
131 const std::vector<uint8_t>& value() const
132 {
133 return value_;
134 }
135
136 std::vector<uint8_t>& value()
137 {
138 return value_;
139 }
140
142 bool propagate)
143 {
144 propagate_ = propagate;
145 }
146
147 bool propagate() const
148 {
149 return propagate_;
150 }
151
152 bool& propagate()
153 {
154 return propagate_;
155 }
156
157private:
158
159 std::string name_;
160
161 std::vector<uint8_t> value_;
162
163 bool propagate_;
164};
165
166typedef std::vector<BinaryProperty> BinaryPropertySeq;
167
169{
170public:
171
172 static size_t serialized_size(
173 const BinaryProperty& binary_property,
174 size_t current_alignment = 0)
175 {
176 if (binary_property.propagate())
177 {
178 size_t initial_alignment = current_alignment;
179
180 current_alignment += 4 + alignment(current_alignment, 4) + binary_property.name().size() + 1;
181 current_alignment += 4 + alignment(current_alignment, 4) + binary_property.value().size();
182
183 return current_alignment - initial_alignment;
184 }
185 else
186 {
187 return 0;
188 }
189 }
190
191 static size_t serialized_size(
192 const BinaryPropertySeq& binary_properties,
193 size_t current_alignment = 0)
194 {
195 size_t initial_alignment = current_alignment;
196
197 current_alignment += 4 + alignment(current_alignment, 4);
198 for (auto binary_property = binary_properties.begin(); binary_property != binary_properties.end();
199 ++binary_property)
200 {
201 current_alignment += serialized_size(*binary_property, current_alignment);
202 }
203
204 return current_alignment - initial_alignment;
205 }
206
207private:
208
209 inline static size_t alignment(
210 size_t current_alignment,
211 size_t dataSize)
212 {
213 return (dataSize - (current_alignment % dataSize)) & (dataSize - 1);
214 }
215
216};
217
218} //namespace rtps
219} //namespace fastdds
220} //namespace eprosima
221
222#endif // FASTDDS_RTPS_COMMON__BINARYPROPERTY_HPP
Definition BinaryProperty.hpp:169
static size_t serialized_size(const BinaryProperty &binary_property, size_t current_alignment=0)
Definition BinaryProperty.hpp:172
static size_t serialized_size(const BinaryPropertySeq &binary_properties, size_t current_alignment=0)
Definition BinaryProperty.hpp:191
Definition BinaryProperty.hpp:32
const std::vector< uint8_t > & value() const
Definition BinaryProperty.hpp:131
std::vector< uint8_t > & value()
Definition BinaryProperty.hpp:136
void name(std::string &&name)
Definition BinaryProperty.hpp:103
BinaryProperty(BinaryProperty &&property)
Definition BinaryProperty.hpp:48
const std::string & name() const
Definition BinaryProperty.hpp:109
BinaryProperty(const BinaryProperty &property)
Definition BinaryProperty.hpp:40
BinaryProperty & operator=(const BinaryProperty &property)
Definition BinaryProperty.hpp:72
bool operator==(const BinaryProperty &b) const
Definition BinaryProperty.hpp:90
BinaryProperty(std::string &&name, std::vector< uint8_t > &&value)
Definition BinaryProperty.hpp:64
std::string & name()
Definition BinaryProperty.hpp:114
bool & propagate()
Definition BinaryProperty.hpp:152
BinaryProperty(const std::string &name, const std::vector< uint8_t > &value)
Definition BinaryProperty.hpp:56
void value(std::vector< uint8_t > &&value)
Definition BinaryProperty.hpp:125
void name(const std::string &name)
Definition BinaryProperty.hpp:97
BinaryProperty()
Definition BinaryProperty.hpp:35
bool propagate() const
Definition BinaryProperty.hpp:147
void propagate(bool propagate)
Definition BinaryProperty.hpp:141
void value(const std::vector< uint8_t > &value)
Definition BinaryProperty.hpp:119
std::vector< BinaryProperty > BinaryPropertySeq
Definition BinaryProperty.hpp:166
eProsima namespace.
Definition EntityId_t.hpp:388