binary_view.cpp
Go to the documentation of this file.
1 
11 #include "binary_serialization.h"
12 
13 #include <opc/ua/protocol/view.h>
15 #include <opc/ua/protocol/types.h>
17 
18 #include <algorithm>
19 #include <memory>
20 #include <string>
21 
22 namespace OpcUa
23 {
25 // NodesDescription
27 
29  : MaxReferenciesPerNode(0)
30 {
31 }
32 
34 // ViewDescription
36 
38  : Timestamp(0)
39  , Version(0)
40 {
41 }
42 
44  : Direction(BrowseDirection::Both)
45  , IncludeSubtypes(false)
46  , NodeClasses(NodeClass::Unspecified)
47  , ResultMask(BrowseResultMask::All)
48 {
49 }
50 
53 {
54 }
55 
58 {
59 }
60 
63 {
64 }
65 
68 {
69 }
70 
73 {
74 }
75 
78 {
79 }
80 
82  : IsForward(false)
83  , TargetNodeClass(NodeClass::Unspecified)
84 {
85 }
86 
89 {
90 }
91 
94 {
95 }
96 
99  , ReleaseContinuationPoints(false)
100 {
101 }
102 
105 {
106 }
107 
109  : RemainingPathIndex(0)
110 {
111 }
112 
115 {
116 }
117 
120 {
121 }
122 
123 namespace Binary
124 {
125 
126 //---------------------------------------------------
127 // ViewDescription
128 //---------------------------------------------------
129 
130 template<>
131 std::size_t RawSize<ViewDescription>(const ViewDescription & desc)
132 {
133  return RawSize(desc.Id) + RawSize(desc.Timestamp) + RawSize(desc.Version);
134 }
135 
136 template<>
137 void DataSerializer::Serialize<ViewDescription>(const ViewDescription & desc)
138 {
139  *this << desc.Id;
140  *this << desc.Timestamp;
141  *this << desc.Version;
142 }
143 
144 template<>
145 void DataDeserializer::Deserialize<ViewDescription>(ViewDescription & desc)
146 {
147  *this >> desc.Id;
148  *this >> desc.Timestamp;
149  *this >> desc.Version;
150 }
151 
152 
153 //---------------------------------------------------
154 // BrowseDescription
155 //---------------------------------------------------
156 
157 template<>
159 {
160  return RawSize(desc.NodeToBrowse) +
161  RawSize(desc.Direction) +
162  RawSize(desc.ReferenceTypeId) +
163  RawSize(desc.IncludeSubtypes) +
164  RawSize(desc.NodeClasses) +
165  RawSize(desc.ResultMask);
166 }
167 
168 template<>
169 void DataSerializer::Serialize<BrowseDescription>(const BrowseDescription & desc)
170 {
171  *this << desc.NodeToBrowse;
172  *this << desc.Direction;
173  *this << desc.ReferenceTypeId;
174  *this << desc.IncludeSubtypes;
175  *this << desc.NodeClasses;
176  *this << desc.ResultMask;
177 }
178 
179 template<>
180 void DataDeserializer::Deserialize<BrowseDescription>(BrowseDescription & desc)
181 {
182  *this >> desc.NodeToBrowse;
183  *this >> desc.Direction;
184  *this >> desc.ReferenceTypeId;
185  *this >> desc.IncludeSubtypes;
186  *this >> desc.NodeClasses;
187  *this >> desc.ResultMask;
188 }
189 
191 // NodesDescription
193 
194 template<>
195 std::size_t RawSize<NodesQuery>(const NodesQuery & desc)
196 {
197  return RawSize(desc.View) + RawSize(desc.MaxReferenciesPerNode) + RawSizeContainer(desc.NodesToBrowse);
198 }
199 
200 template<>
201 void DataSerializer::Serialize<NodesQuery>(const NodesQuery & desc)
202 {
203  *this << desc.View;
204  *this << desc.MaxReferenciesPerNode;
205  SerializeContainer(*this, desc.NodesToBrowse);
206 }
207 
208 template<>
209 void DataDeserializer::Deserialize<NodesQuery>(NodesQuery & desc)
210 {
211  *this >> desc.View;
212  *this >> desc.MaxReferenciesPerNode;
213  DeserializeContainer(*this, desc.NodesToBrowse);
214 }
215 
216 //---------------------------------------------------
217 // BrowseRequest
218 //---------------------------------------------------
219 
220 template<>
221 std::size_t RawSize<BrowseRequest>(const BrowseRequest & request)
222 {
223  return RawSize(request.TypeId) + RawSize(request.Header) + RawSize(request.Query);
224 }
225 
226 template<>
227 void DataSerializer::Serialize<BrowseRequest>(const BrowseRequest & request)
228 {
229  *this << request.TypeId;
230  *this << request.Header;
231  *this << request.Query;
232 }
233 
234 template<>
235 void DataDeserializer::Deserialize<BrowseRequest>(BrowseRequest & request)
236 {
237  *this >> request.TypeId;
238  *this >> request.Header;
239  *this >> request.Query;
240 }
241 
242 //---------------------------------------------------
243 // ReferenceDescription
244 //---------------------------------------------------
245 
246 template<>
248 {
249  return RawSize(desc.ReferenceTypeId) +
250  RawSize(desc.IsForward) +
251  RawSize(desc.TargetNodeId) +
252  RawSize(desc.BrowseName) +
253  RawSize(desc.DisplayName) +
254  RawSize(desc.TargetNodeClass) +
255  RawSize(desc.TargetNodeTypeDefinition);
256 }
257 
258 template<>
259 void DataSerializer::Serialize<ReferenceDescription>(const ReferenceDescription & desc)
260 {
261  *this << desc.ReferenceTypeId;
262  *this << desc.IsForward;
263  *this << desc.TargetNodeId;
264  *this << desc.BrowseName;
265  *this << desc.DisplayName;
266  *this << desc.TargetNodeClass;
267  *this << desc.TargetNodeTypeDefinition;
268 }
269 
270 template<>
271 void DataDeserializer::Deserialize<ReferenceDescription>(ReferenceDescription & desc)
272 {
273  *this >> desc.ReferenceTypeId;
274  *this >> desc.IsForward;
275  *this >> desc.TargetNodeId;
276  *this >> desc.BrowseName;
277  *this >> desc.DisplayName;
278  *this >> desc.TargetNodeClass;
279  *this >> desc.TargetNodeTypeDefinition;
280 }
281 
282 //---------------------------------------------------
283 // BrowseResult
284 //---------------------------------------------------
285 
286 template<>
287 std::size_t RawSize<BrowseResult>(const BrowseResult & result)
288 {
289  return RawSize(result.Status) +
290  RawSizeContainer(result.ContinuationPoint) +
291  RawSizeContainer(result.Referencies);
292 }
293 
294 template<>
295 void DataSerializer::Serialize<BrowseResult>(const BrowseResult & result)
296 {
297  *this << result.Status;
298  SerializeContainer(*this, result.ContinuationPoint);
299  SerializeContainer(*this, result.Referencies);
300 }
301 
302 template<>
303 void DataDeserializer::Deserialize<BrowseResult>(BrowseResult & result)
304 {
305  *this >> result.Status;
306  DeserializeContainer(*this, result.ContinuationPoint);
307  DeserializeContainer(*this, result.Referencies);
308 }
309 
310 //---------------------------------------------------
311 // BrowseResponse
312 //---------------------------------------------------
313 
314 template<>
315 std::size_t RawSize<BrowseResponse>(const BrowseResponse & response)
316 {
317  return RawSize(response.TypeId) + RawSize(response.Header) +
318  RawSizeContainer(response.Results) +
319  RawSizeContainer(response.Diagnostics);
320 }
321 
322 template<>
323 void DataSerializer::Serialize<BrowseResponse>(const BrowseResponse & response)
324 {
325  *this << response.TypeId;
326  *this << response.Header;
327 
328  SerializeContainer(*this, response.Results, 0);
329  SerializeContainer(*this, response.Diagnostics, 0);
330 }
331 
332 template<>
333 void DataDeserializer::Deserialize<BrowseResponse>(BrowseResponse & response)
334 {
335  *this >> response.TypeId;
336  *this >> response.Header;
337 
338  DeserializeContainer(*this, response.Results);
339  DeserializeContainer(*this, response.Diagnostics);
340 }
341 
342 //---------------------------------------------------
343 // BrowseNextRequest
344 //---------------------------------------------------
345 
346 template<>
347 std::size_t RawSize<BrowseNextRequest>(const BrowseNextRequest & request)
348 {
349  return RawSize(request.TypeId) + RawSize(request.Header) +
350  RawSize(request.ReleaseContinuationPoints) +
351  RawSize(request.ContinuationPoints);
352 }
353 
354 template<>
355 void DataSerializer::Serialize<BrowseNextRequest>(const BrowseNextRequest & request)
356 {
357  *this << request.TypeId;
358  *this << request.Header;
359 
360  *this << request.ReleaseContinuationPoints;
361  SerializeContainer(*this, request.ContinuationPoints);
362 }
363 
364 template<>
365 void DataDeserializer::Deserialize<BrowseNextRequest>(BrowseNextRequest & request)
366 {
367  *this >> request.TypeId;
368  *this >> request.Header;
369 
370  *this >> request.ReleaseContinuationPoints;
371  DeserializeContainer(*this, request.ContinuationPoints);
372 }
373 
374 //---------------------------------------------------
375 // BrowseNextResponse
376 //---------------------------------------------------
377 
378 template<>
379 std::size_t RawSize<BrowseNextResponse>(const BrowseNextResponse & response)
380 {
381  return RawSize(response.TypeId) + RawSize(response.Header) +
382  RawSizeContainer(response.Results) +
383  RawSizeContainer(response.Diagnostics);
384 }
385 
386 template<>
387 void DataSerializer::Serialize<BrowseNextResponse>(const BrowseNextResponse & response)
388 {
389  *this << response.TypeId;
390  *this << response.Header;
391 
392  SerializeContainer(*this, response.Results, 0);
393  SerializeContainer(*this, response.Diagnostics, 0);
394 }
395 
396 template<>
397 void DataDeserializer::Deserialize<BrowseNextResponse>(BrowseNextResponse & response)
398 {
399  *this >> response.TypeId;
400  *this >> response.Header;
401 
402  DeserializeContainer(*this, response.Results);
403  DeserializeContainer(*this, response.Diagnostics);
404 }
405 
407 // BrowsePathTarget
409 
410 template<>
412 {
413  return RawSize(target.Node) + RawSize(target.RemainingPathIndex);
414 }
415 
416 template<>
417 void DataSerializer::Serialize<BrowsePathTarget>(const BrowsePathTarget & target)
418 {
419  *this << target.Node;
420  *this << target.RemainingPathIndex;
421 }
422 
423 template<>
424 void DataDeserializer::Deserialize<BrowsePathTarget>(BrowsePathTarget & target)
425 {
426  *this >> target.Node;
427  *this >> target.RemainingPathIndex;
428 }
429 
430 template<>
431 void DataSerializer::Serialize<std::vector<BrowsePathTarget>>(const std::vector<BrowsePathTarget> & targets)
432 {
433  SerializeContainer(*this, targets);
434 }
435 
436 template<>
437 void DataDeserializer::Deserialize<std::vector<BrowsePathTarget>>(std::vector<BrowsePathTarget> & targets)
438 {
439  DeserializeContainer(*this, targets);
440 }
441 
443 // BrowsePathResult
445 
446 template<>
447 std::size_t RawSize<BrowsePathResult>(const BrowsePathResult & result)
448 {
449  return RawSize(result.Status) + RawSizeContainer(result.Targets);
450 }
451 
452 template<>
453 void DataSerializer::Serialize<BrowsePathResult>(const BrowsePathResult & result)
454 {
455  *this << result.Status;
456  *this << result.Targets;
457 }
458 
459 template<>
460 void DataDeserializer::Deserialize<BrowsePathResult>(BrowsePathResult & result)
461 {
462  *this >> result.Status;
463  *this >> result.Targets;
464 }
465 
466 template<>
467 void DataSerializer::Serialize<std::vector<BrowsePathResult>>(const std::vector<BrowsePathResult> & results)
468 {
469  SerializeContainer(*this, results);
470 }
471 
472 template<>
473 void DataDeserializer::Deserialize<std::vector<BrowsePathResult>>(std::vector<BrowsePathResult> & results)
474 {
475  DeserializeContainer(*this, results);
476 }
477 
479 // TranslateBrowsePathsResult
481 
482 template<>
484 {
485  return RawSizeContainer(result.Paths) + RawSizeContainer(result.Diagnostics);
486 }
487 
488 template<>
489 void DataSerializer::Serialize<TranslateBrowsePathsResult>(const TranslateBrowsePathsResult & result)
490 {
491  *this << result.Paths;
492  *this << result.Diagnostics;
493 }
494 
495 template<>
496 void DataDeserializer::Deserialize<TranslateBrowsePathsResult>(TranslateBrowsePathsResult & result)
497 {
498  *this >> result.Paths;
499  *this >> result.Diagnostics;
500 }
501 
503 // TranslateBrowsePathsToNodeIdsResponse
505 
506 template<>
508 {
509  return RawSize(response.TypeId) + RawSize(response.Header) + RawSize(response.Result);
510 }
511 
512 template<>
513 void DataSerializer::Serialize<TranslateBrowsePathsToNodeIdsResponse>(const TranslateBrowsePathsToNodeIdsResponse & response)
514 {
515  *this << response.TypeId;
516  *this << response.Header;
517  *this << response.Result;
518 }
519 
520 template<>
521 void DataDeserializer::Deserialize<TranslateBrowsePathsToNodeIdsResponse>(TranslateBrowsePathsToNodeIdsResponse & response)
522 {
523  *this >> response.TypeId;
524  *this >> response.Header;
525  *this >> response.Result;
526 }
527 
529 // RegisterNodesRequest
531 
532 template<>
534 {
535  return RawSize(request.TypeId) + RawSize(request.Header) + RawSizeContainer(request.NodesToRegister);
536 }
537 
538 template<>
539 void DataSerializer::Serialize<RegisterNodesRequest>(const RegisterNodesRequest & request)
540 {
541  *this << request.TypeId;
542  *this << request.Header;
543  SerializeContainer(*this, request.NodesToRegister);
544 }
545 
546 template<>
547 void DataDeserializer::Deserialize<RegisterNodesRequest>(RegisterNodesRequest & request)
548 {
549  *this >> request.TypeId;
550  *this >> request.Header;
551  DeserializeContainer(*this, request.NodesToRegister);
552 }
553 
555 // RegisterNodesResponse
557 
558 template<>
560 {
561  return RawSize(response.TypeId) + RawSize(response.Header) + RawSizeContainer(response.Result);
562 }
563 
564 template<>
565 void DataSerializer::Serialize<RegisterNodesResponse>(const RegisterNodesResponse & response)
566 {
567  *this << response.TypeId;
568  *this << response.Header;
569  SerializeContainer(*this, response.Result);
570 }
571 
572 template<>
573 void DataDeserializer::Deserialize<RegisterNodesResponse>(RegisterNodesResponse & response)
574 {
575  *this >> response.TypeId;
576  *this >> response.Header;
577  DeserializeContainer(*this, response.Result);
578 }
579 
581 // UnregisterNodesRequest
583 
584 template<>
586 {
587  return RawSize(request.TypeId) + RawSize(request.Header) + RawSizeContainer(request.NodesToUnregister);
588 }
589 
590 template<>
591 void DataSerializer::Serialize<UnregisterNodesRequest>(const UnregisterNodesRequest & request)
592 {
593  *this << request.TypeId;
594  *this << request.Header;
595  SerializeContainer(*this, request.NodesToUnregister);
596 }
597 
598 template<>
599 void DataDeserializer::Deserialize<UnregisterNodesRequest>(UnregisterNodesRequest & request)
600 {
601  *this >> request.TypeId;
602  *this >> request.Header;
603  DeserializeContainer(*this, request.NodesToUnregister);
604 }
605 
607 // UnregisterNodesResponse
609 
610 template<>
612 {
613  return RawSize(response.TypeId) + RawSize(response.Header);
614 }
615 
616 template<>
617 void DataSerializer::Serialize<UnregisterNodesResponse>(const UnregisterNodesResponse & response)
618 {
619  *this << response.TypeId;
620  *this << response.Header;
621 }
622 
623 template<>
624 void DataDeserializer::Deserialize<UnregisterNodesResponse>(UnregisterNodesResponse & response)
625 {
626  *this >> response.TypeId;
627  *this >> response.Header;
628 }
629 
631 // RelativePathElement
633 
634 template<>
636 {
637  return RawSize(element.IncludeSubtypes) + RawSize(element.IsInverse) + RawSize(element.ReferenceTypeId) + RawSize(element.TargetName);
638 }
639 
640 template<>
641 void DataSerializer::Serialize<RelativePathElement>(const RelativePathElement & path)
642 {
643  *this << path.ReferenceTypeId;
644  *this << path.IsInverse;
645  *this << path.IncludeSubtypes;
646  *this << path.TargetName;
647 }
648 
649 template<>
650 void DataDeserializer::Deserialize<RelativePathElement>(RelativePathElement & path)
651 {
652  *this >> path.ReferenceTypeId;
653  *this >> path.IsInverse;
654  *this >> path.IncludeSubtypes;
655  *this >> path.TargetName;
656 }
657 
658 template<>
659 void DataDeserializer::Deserialize<std::vector<RelativePathElement>>(std::vector<RelativePathElement> & targets)
660 {
661  DeserializeContainer(*this, targets);
662 }
663 
664 template<>
665 void DataSerializer::Serialize<std::vector<RelativePathElement>>(const std::vector<RelativePathElement> & targets)
666 {
667  SerializeContainer(*this, targets);
668 }
669 
671 // RelativePath
673 
674 template<>
675 std::size_t RawSize<RelativePath>(const RelativePath & rpath)
676 {
677  return RawSizeContainer(rpath.Elements);
678 }
679 
680 template<>
681 void DataSerializer::Serialize<RelativePath>(const RelativePath & path)
682 {
683  *this << path.Elements;
684 }
685 
686 template<>
687 void DataDeserializer::Deserialize<RelativePath>(RelativePath & path)
688 {
689  *this >> path.Elements;
690 }
691 
693 // BrowsePath
695 
696 template<>
697 std::size_t RawSize<BrowsePath>(const BrowsePath & path)
698 {
699  return RawSize(path.StartingNode) + RawSize(path.Path);
700 }
701 
702 template<>
703 void DataDeserializer::Deserialize<BrowsePath>(BrowsePath & path)
704 {
705  *this >> path.StartingNode;
706  *this >> path.Path;
707 }
708 
709 template<>
710 void DataSerializer::Serialize<BrowsePath>(const BrowsePath & path)
711 {
712  *this << path.StartingNode;
713  *this << path.Path;
714 }
715 
716 template<>
717 void DataDeserializer::Deserialize<std::vector<BrowsePath>>(std::vector<BrowsePath> & paths)
718 {
719  DeserializeContainer(*this, paths);
720 }
721 
722 template<>
723 void DataSerializer::Serialize<std::vector<BrowsePath>>(const std::vector<BrowsePath> & paths)
724 {
725  SerializeContainer(*this, paths);
726 }
727 
729 // TranslateBrowsePathsParameters
731 
732 template<>
734 {
735  return RawSizeContainer(params.BrowsePaths);
736 }
737 
738 template<>
739 void DataSerializer::Serialize<TranslateBrowsePathsParameters>(const TranslateBrowsePathsParameters & params)
740 {
741  *this << params.BrowsePaths;
742 }
743 
744 template<>
745 void DataDeserializer::Deserialize<TranslateBrowsePathsParameters>(TranslateBrowsePathsParameters & path)
746 {
747  *this >> path.BrowsePaths;
748 }
749 
751 // TranslateBrowsePathsToNodeIdsRequest
753 
754 template<>
756 {
757  return RawSize(request.TypeId) + RawSize(request.Header) + RawSize(request.Parameters) ;
758 }
759 
760 template<>
761 void DataSerializer::Serialize<TranslateBrowsePathsToNodeIdsRequest>(const TranslateBrowsePathsToNodeIdsRequest & request)
762 {
763  *this << request.TypeId;
764  *this << request.Header;
765  *this << request.Parameters;
766 }
767 
768 template<>
769 void DataDeserializer::Deserialize<TranslateBrowsePathsToNodeIdsRequest>(TranslateBrowsePathsToNodeIdsRequest & request)
770 {
771  *this >> request.TypeId;
772  *this >> request.Header;
773  *this >> request.Parameters;
774 }
775 
776 } // namespace Binary
777 } // namespace OpcUa
std::size_t RawSize< BrowseDescription >(const BrowseDescription &desc)
std::size_t RawSize< BrowseNextRequest >(const BrowseNextRequest &request)
void SerializeContainer(Stream &out, const Container &c, uint32_t emptySizeValue=~uint32_t())
std::size_t RawSize< BrowseRequest >(const BrowseRequest &request)
std::size_t RawSize< ViewDescription >(const ViewDescription &desc)
std::size_t RawSize< BrowsePathTarget >(const BrowsePathTarget &target)
std::size_t RawSize< TranslateBrowsePathsToNodeIdsResponse >(const TranslateBrowsePathsToNodeIdsResponse &response)
std::size_t RawSize< BrowseResult >(const BrowseResult &result)
void DeserializeContainer(Stream &in, Container &c)
std::size_t RawSize< RegisterNodesResponse >(const RegisterNodesResponse &response)
std::size_t RawSize< BrowseNextResponse >(const BrowseNextResponse &response)
BrowseDirection
Definition: enums.h:173
std::size_t RawSize< RegisterNodesRequest >(const RegisterNodesRequest &request)
std::size_t RawSize< RelativePathElement >(const RelativePathElement &element)
std::size_t RawSize< BrowsePath >(const BrowsePath &path)
OPC UA Address space part. GNU LGPL.
const char * Binary(const char *input, short n)
std::size_t RawSize< TranslateBrowsePathsToNodeIdsRequest >(const TranslateBrowsePathsToNodeIdsRequest &request)
std::size_t RawSize< RelativePath >(const RelativePath &rpath)
std::size_t RawSize< BrowsePathResult >(const BrowsePathResult &result)
BrowseResultMask
Definition: enums.h:184
NodeClass
Definition: enums.h:39
std::size_t RawSize< TranslateBrowsePathsResult >(const TranslateBrowsePathsResult &result)
std::size_t RawSize< UnregisterNodesResponse >(const UnregisterNodesResponse &response)
std::size_t RawSize< UnregisterNodesRequest >(const UnregisterNodesRequest &request)
std::size_t RawSizeContainer(const T &container)
std::size_t RawSize< NodesQuery >(const NodesQuery &desc)
std::size_t RawSize< BrowseResponse >(const BrowseResponse &response)
std::size_t RawSize< TranslateBrowsePathsParameters >(const TranslateBrowsePathsParameters &params)
std::size_t RawSize(const T &obj)
std::size_t RawSize< ReferenceDescription >(const ReferenceDescription &desc)


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