binary_raw_size.cpp
Go to the documentation of this file.
1 
13 #include <opc/ua/protocol/types.h>
14 
15 #include <algorithm>
16 #include <stdexcept>
17 
18 namespace OpcUa
19 {
20 namespace Binary
21 {
22 template<>
23 std::size_t RawSize<bool>(const bool &)
24 {
25  return 1;
26 }
27 
28 template<>
29 std::size_t RawSize<uint8_t>(const uint8_t &)
30 {
31  return 1;
32 }
33 
34 template<>
35 std::size_t RawSize<int8_t>(const int8_t &)
36 {
37  return 1;
38 }
39 
40 template<>
41 std::size_t RawSize<uint16_t>(const uint16_t &)
42 {
43  return 2;
44 }
45 
46 template<>
47 std::size_t RawSize<int16_t>(const int16_t &)
48 {
49  return 2;
50 }
51 
52 template<>
53 std::size_t RawSize<uint32_t>(const uint32_t &)
54 {
55  return 4;
56 }
57 
58 template<>
59 std::size_t RawSize<int32_t>(const int32_t &)
60 {
61  return 4;
62 }
63 
64 
65 template<>
66 std::size_t RawSize<uint64_t>(const uint64_t &)
67 {
68  return 8;
69 }
70 
71 template<>
72 std::size_t RawSize<int64_t>(const int64_t &)
73 {
74  return 8;
75 }
76 
77 template<>
78 std::size_t RawSize<float>(const float &)
79 {
80  return 4;
81 }
82 
83 template<>
84 std::size_t RawSize<double>(const double &)
85 {
86  return 8;
87 }
88 
89 template<>
90 std::size_t RawSize<Guid>(const Guid &)
91 {
92  return 16;
93 }
94 
95 template<>
96 std::size_t RawSize<StatusCode>(const StatusCode &)
97 {
98  return 4;
99 }
100 
101 template<>
102 std::size_t RawSize<std::string>(const std::string & str)
103 {
104  const std::size_t headerSize = 4;
105  return headerSize + str.size();
106 }
107 
108 template<>
109 std::size_t RawSize<ByteString>(const ByteString & str)
110 {
111  const std::size_t headerSize = 4;
112  return headerSize + str.Data.size();
113 }
114 
115 template<>
116 std::size_t RawSize<DateTime>(const DateTime & date)
117 {
118  return RawSize(date.Value);
119 }
120 
121 template<>
122 std::size_t RawSize<std::vector<uint8_t>>(const std::vector<uint8_t> & vec)
123 {
124  const std::size_t headerSize = 4;
125  return headerSize + vec.size();
126 }
127 
128 template<>
129 std::size_t RawSize<std::vector<std::vector<uint8_t>>>(const std::vector<std::vector<uint8_t>> & vec)
130 {
131  const std::size_t headerSize = 4;
132  std::size_t totalSize = headerSize;
133  std::for_each(vec.begin(), vec.end(), [&](const std::vector<uint8_t> & v) {totalSize += RawSize(v);});
134  return totalSize;
135 }
136 
137 
138 template<>
139 std::size_t RawSize<std::vector<std::string>>(const std::vector<std::string> & vec)
140 {
141  const std::size_t headerSize = 4;
142  std::size_t totalSize = headerSize;
143  std::for_each(vec.begin(), vec.end(), [&](const std::string & str) {totalSize += RawSize(str);});
144  return totalSize;
145 }
146 
147 
148 template<>
149 std::size_t RawSize<Header>(const Header &)
150 {
151  const std::size_t sizeofType = 3; // 'H', 'E', 'L'
152  const std::size_t sizeofChunk = 1; // 'F'
153  const std::size_t sizeofSize = 4;
154  return sizeofType + sizeofChunk + sizeofSize;
155 }
156 
157 template<>
159 {
160  const std::size_t sizeofType = 3; // 'H', 'E', 'L'
161  const std::size_t sizeofChunk = 1; // 'F'
162  const std::size_t sizeofSize = 4;
163  const std::size_t sizeofChannelId = 4;
164  return sizeofType + sizeofChunk + sizeofSize + sizeofChannelId;
165 }
166 
167 template<>
168 std::size_t RawSize<Hello>(const Hello & hello)
169 {
170  const std::size_t sizeOfProtocolVersion = 4;
171  const std::size_t sizeOfReceiveBufferSize = 4;
172  const std::size_t sizeOfSendBufferSize = 4;
173  const std::size_t sizeOfMaxMessageSize = 4;
174  const std::size_t sizeOfMaxChunkCount = 4;
175 
176  return sizeOfProtocolVersion +
177  sizeOfReceiveBufferSize +
178  sizeOfSendBufferSize +
179  sizeOfMaxMessageSize +
180  sizeOfMaxChunkCount +
181  RawSize(hello.EndpointUrl);
182 }
183 
184 template<>
185 std::size_t RawSize<Acknowledge>(const Acknowledge &)
186 {
187  const std::size_t sizeofProtocolVersion = 4;
188  const std::size_t sizeofReceiveBufferSize = 4;
189  const std::size_t sizeofSendBufferSize = 4;
190  const std::size_t sizeofMaxMessageSize = 4;
191  const std::size_t sizeofMaxChunkCount = 4;
192 
193  return sizeofProtocolVersion + sizeofReceiveBufferSize + sizeofSendBufferSize + sizeofMaxMessageSize + sizeofMaxChunkCount;
194 }
195 
196 template<>
197 std::size_t RawSize<Error>(const Error & err)
198 {
199  const std::size_t sizeofCode = 4;
200  return sizeofCode + RawSize(err.Reason);
201 }
202 
203 template<>
205 {
206  const std::size_t sizeofUri = RawSize(ack.SecurityPolicyUri);
207  const std::size_t sizeofCertificate = RawSize(ack.SenderCertificate);
208  const std::size_t sizeofThumbprint = RawSize(ack.ReceiverCertificateThumbPrint);
209  return sizeofUri + sizeofCertificate + sizeofThumbprint;
210 }
211 
212 template<>
214 {
215  const std::size_t sizeofSequenceNumber = 4;
216  const std::size_t sizeofRequestId = 4;
217 
218  return sizeofSequenceNumber + sizeofRequestId;
219 }
220 
221 template<>
223 {
224  const std::size_t sizeofTypeId = RawSize(header.TypeId);
225  const std::size_t sizeofEncoding = 1;
226  return sizeofTypeId + sizeofEncoding;
227 }
228 
229 template<>
231 {
232  const std::size_t sizeofSessionAuthenticationToken = RawSize(header.SessionAuthenticationToken);
233  const std::size_t sizeofUtcTime = 8;
234  const std::size_t sizeofRequestHandle = 4;
235  const std::size_t sizeofReturnDiagnostics = 4;
236  const std::size_t sizeofAuditEntryId = 4 + header.AuditEntryId.size();
237  const std::size_t sizeofTimeout = 4;
238  const std::size_t sizeofAdditional = RawSize(header.Additional);
239 
240  return sizeofSessionAuthenticationToken + sizeofUtcTime + sizeofRequestHandle + sizeofReturnDiagnostics + sizeofAuditEntryId + sizeofTimeout + sizeofAdditional;
241 }
242 
243 template<>
245 {
246  const std::size_t sizeofTypeId = RawSize(request.TypeId);
247  const std::size_t sizeofHeader = RawSize(request.Header);
248  const std::size_t sizeofClientProtocolVersion = 4;
249  const std::size_t sizeofRequestType = 4;
250  const std::size_t sizeofSecurityMode = 4;
251  const std::size_t sizeofClientNonce = 4 + request.Parameters.ClientNonce.size();
252  const std::size_t sizeofRequestLifeTime = 4;
253 
254  return sizeofTypeId + sizeofHeader + sizeofClientProtocolVersion + sizeofRequestType + sizeofSecurityMode + sizeofClientNonce + sizeofRequestLifeTime;
255 }
256 
257 template<>
259 {
260  const std::size_t sizeofTokenId = 4;
261  return sizeofTokenId;
262 }
263 
264 template<>
266 {
267  const std::size_t sizeofEncodingMask = 1;
268  size_t size = sizeofEncodingMask;
269 
270  if (info.EncodingMask & DIM_SYMBOLIC_Id)
271  {
272  const std::size_t sizeofSymbolicId = 4;
273  size += sizeofSymbolicId;
274  }
275 
276  if (info.EncodingMask & DIM_NAMESPACE)
277  {
278  const std::size_t sizeofNamespace = 4;
279  size += sizeofNamespace;
280  }
281 
282  if (info.EncodingMask & DIM_LOCALIZED_TEXT)
283  {
284  const std::size_t sizeofLocalizedText = 4;
285  size += sizeofLocalizedText;
286  }
287 
288  if (info.EncodingMask & DIM_LOCALE)
289  {
290  const std::size_t sizeofLocale = 4;
291  size += sizeofLocale;
292  }
293 
294  if (info.EncodingMask & DIM_ADDITIONAL_INFO)
295  {
296  const std::size_t sizeofAdditionalInfo = 4 + info.AdditionalInfo.size();
297  size += sizeofAdditionalInfo;
298  }
299 
300  if (info.EncodingMask & DIM_INNER_STATUS_CODE)
301  {
302  const std::size_t sizeofInnerStatusCode = 4;
303  size += sizeofInnerStatusCode;
304  }
305 
306  if ((info.EncodingMask & DIM_INNER_DIAGNOSTIC_INFO) && info.InnerDiagnostics)
307  {
308  size += RawSize(*info.InnerDiagnostics);
309  }
310 
311  return size;
312 }
313 
314 template<>
316 {
317  return RawSizeContainer(infos);
318 }
319 
320 template<>
322 {
323  const std::size_t sizeofTimestamp = 8;
324  const std::size_t sizeofRequestHandle = 4;
325  const std::size_t sizeofServiceResult = 4;
326 
327  std::size_t sizeofDiagnostics = RawSize(header.InnerDiagnostics);
328  std::size_t sizeofStringTable = 4;
329  std::for_each(header.StringTable.begin(), header.StringTable.end(), [&](const std::string & str) {sizeofStringTable += RawSize(str);});
330 
331  const std::size_t sizeofAdditional = RawSize(header.Additional);
332  return sizeofTimestamp + sizeofRequestHandle + sizeofServiceResult + sizeofDiagnostics + sizeofStringTable + sizeofAdditional;
333 }
334 
335 template<>
337 {
338  const std::size_t sizeofSecureChannelId = 4;
339  const std::size_t sizeofTokenId = 4;
340  const std::size_t sizeofCreatedAt = 8;
341  const std::size_t sizeofRevisedLifetime = 4;
342 
343  return sizeofSecureChannelId + sizeofTokenId + sizeofCreatedAt + sizeofRevisedLifetime;
344 }
345 
346 template<>
348 {
349  const std::size_t sizeofTypeId = RawSize(response.TypeId);
350  const std::size_t sizeofHeader = RawSize(response.Header);
351  const std::size_t sizeofServerProtocolVersion = 4;
352  const std::size_t sizeofChannelSecurityToken = RawSize(response.ChannelSecurityToken);
353  const std::size_t sizeofServerNonce = 4 + response.ServerNonce.size();
354 
355  return sizeofTypeId + sizeofHeader + sizeofServerProtocolVersion + sizeofChannelSecurityToken + sizeofServerNonce;
356 }
357 
358 template<>
360 {
361  const std::size_t sizeofTypeId = RawSize(request.TypeId);
362  const std::size_t sizeofHeader = RawSize(request.Header);
363  return sizeofTypeId + sizeofHeader;
364 }
365 
366 
367 template<>
368 std::size_t RawSize<LocalizedText>(const LocalizedText & text)
369 {
370  std::size_t size = RawSize(text.Encoding);
371 
372  if (text.Encoding & HAS_LOCALE)
373  {
374  size += RawSize(text.Locale);
375  }
376 
377  if (text.Encoding & HAS_TEXT)
378  {
379  size += RawSize(text.Text);
380  }
381 
382  return size;
383 }
384 
385 // template<>
386 // std::size_t RawSize<SignatureData>(const SignatureData& s)
387 // {
388 // return RawSize(s.Signature) + RawSize(s.Algorithm);
389 // }
390 
391 template<>
393 {
394  const std::size_t sizeofEncoding = 1;
395  return RawSize(header.TypeId) + sizeofEncoding;
396 }
397 
398 template<>
400 {
401  return RawSize(name.NamespaceIndex) + RawSize(name.Name);
402 }
403 
404 template<>
405 std::size_t RawSize<IntegerId>(const IntegerId &)
406 {
407  return 4;
408 }
409 
410 }
411 }
412 
std::size_t RawSize< SequenceHeader >(const SequenceHeader &)
std::size_t RawSize< Error >(const Error &err)
const uint8_t HAS_LOCALE
Definition: types.h:129
std::size_t RawSize< int64_t >(const int64_t &)
std::size_t RawSize< double >(const double &)
std::size_t RawSize< ByteString >(const ByteString &str)
std::size_t RawSize< QualifiedName >(const QualifiedName &name)
std::size_t RawSize< Hello >(const Hello &hello)
std::size_t RawSize< IntegerId >(const IntegerId &)
std::size_t RawSize< float >(const float &)
std::size_t RawSize< DiagnosticInfo >(const DiagnosticInfo &info)
std::size_t RawSize< int32_t >(const int32_t &)
std::size_t RawSize< CloseSecureChannelRequest >(const CloseSecureChannelRequest &request)
const uint8_t HAS_TEXT
Definition: types.h:130
std::size_t RawSize< SymmetricAlgorithmHeader >(const SymmetricAlgorithmHeader &header)
std::size_t RawSize< StatusCode >(const StatusCode &)
std::size_t RawSize< LocalizedText >(const LocalizedText &text)
std_msgs::Header * header(M &m)
std::size_t RawSize< int8_t >(const int8_t &)
name
Definition: setup.py:38
std::size_t RawSize< DateTime >(const DateTime &date)
std::size_t RawSize< int16_t >(const int16_t &)
std::size_t RawSize< SecureHeader >(const SecureHeader &)
std::size_t RawSize< uint32_t >(const uint32_t &)
std::size_t RawSize< uint16_t >(const uint16_t &)
std::size_t RawSize< SecurityToken >(const SecurityToken &)
std::size_t RawSize< DiagnosticInfoList >(const DiagnosticInfoList &infos)
std::size_t RawSize< AsymmetricAlgorithmHeader >(const AsymmetricAlgorithmHeader &ack)
OPC UA Address space part. GNU LGPL.
std::size_t RawSize< uint64_t >(const uint64_t &)
const char * Binary(const char *input, short n)
std::vector< DiagnosticInfo > DiagnosticInfoList
Definition: types.h:253
std::size_t RawSize< RequestHeader >(const RequestHeader &header)
std::size_t RawSize< ResponseHeader >(const ResponseHeader &header)
std::size_t RawSize< Acknowledge >(const Acknowledge &)
std::size_t RawSize< bool >(const bool &)
std::size_t RawSize< ExtensionObjectHeader >(const ExtensionObjectHeader &header)
std::size_t RawSize< Guid >(const Guid &)
std::size_t RawSize< Header >(const Header &)
std::size_t RawSize< OpenSecureChannelResponse >(const OpenSecureChannelResponse &response)
std::size_t RawSize< OpenSecureChannelRequest >(const OpenSecureChannelRequest &request)
std::size_t RawSizeContainer(const T &container)
std::size_t RawSize< AdditionalHeader >(const AdditionalHeader &header)
std::size_t RawSize< uint8_t >(const uint8_t &)
std::size_t RawSize(const T &obj)


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:06:03