Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "binary_serialization.h"
00012
00013 #include <opc/ua/protocol/view.h>
00014 #include <opc/ua/protocol/binary/stream.h>
00015 #include <opc/ua/protocol/types.h>
00016 #include <opc/ua/protocol/extension_identifiers.h>
00017
00018 #include <algorithm>
00019 #include <memory>
00020 #include <string>
00021
00022 namespace OpcUa
00023 {
00025
00027
00028 NodesQuery::NodesQuery()
00029 : MaxReferenciesPerNode(0)
00030 {
00031 }
00032
00034
00036
00037 ViewDescription::ViewDescription()
00038 : Timestamp(0)
00039 , Version(0)
00040 {
00041 }
00042
00043 BrowseDescription::BrowseDescription()
00044 : Direction(BrowseDirection::Both)
00045 , IncludeSubtypes(false)
00046 , NodeClasses(NodeClass::Unspecified)
00047 , ResultMask(BrowseResultMask::All)
00048 {
00049 }
00050
00051 BrowseRequest::BrowseRequest()
00052 : TypeId(BROWSE_REQUEST)
00053 {
00054 }
00055
00056 TranslateBrowsePathsToNodeIdsRequest::TranslateBrowsePathsToNodeIdsRequest()
00057 : TypeId(TRANSLATE_BROWSE_PATHS_TO_NODE_IdS_REQUEST)
00058 {
00059 }
00060
00061 RegisterNodesRequest::RegisterNodesRequest()
00062 : TypeId(REGISTER_NODES_REQUEST)
00063 {
00064 }
00065
00066 RegisterNodesResponse::RegisterNodesResponse()
00067 : TypeId(REGISTER_NODES_RESPONSE)
00068 {
00069 }
00070
00071 UnregisterNodesRequest::UnregisterNodesRequest()
00072 : TypeId(UNREGISTER_NODES_REQUEST)
00073 {
00074 }
00075
00076 UnregisterNodesResponse::UnregisterNodesResponse()
00077 : TypeId(UNREGISTER_NODES_RESPONSE)
00078 {
00079 }
00080
00081 ReferenceDescription::ReferenceDescription()
00082 : IsForward(false)
00083 , TargetNodeClass(NodeClass::Unspecified)
00084 {
00085 }
00086
00087 BrowseResult::BrowseResult()
00088 : Status(StatusCode::Good)
00089 {
00090 }
00091
00092 BrowseResponse::BrowseResponse()
00093 : TypeId(BROWSE_RESPONSE)
00094 {
00095 }
00096
00097 BrowseNextRequest::BrowseNextRequest()
00098 : TypeId(BROWSE_NEXT_REQUEST)
00099 , ReleaseContinuationPoints(false)
00100 {
00101 }
00102
00103 BrowseNextResponse::BrowseNextResponse()
00104 : TypeId(BROWSE_NEXT_RESPONSE)
00105 {
00106 }
00107
00108 BrowsePathTarget::BrowsePathTarget()
00109 : RemainingPathIndex(0)
00110 {
00111 }
00112
00113 BrowsePathResult::BrowsePathResult()
00114 : Status(StatusCode::Good)
00115 {
00116 }
00117
00118 TranslateBrowsePathsToNodeIdsResponse::TranslateBrowsePathsToNodeIdsResponse()
00119 : TypeId(TRANSLATE_BROWSE_PATHS_TO_NODE_IdS_RESPONSE)
00120 {
00121 }
00122
00123 namespace Binary
00124 {
00125
00126
00127
00128
00129
00130 template<>
00131 std::size_t RawSize<ViewDescription>(const ViewDescription& desc)
00132 {
00133 return RawSize(desc.Id) + RawSize(desc.Timestamp) + RawSize(desc.Version);
00134 }
00135
00136 template<>
00137 void DataSerializer::Serialize<ViewDescription>(const ViewDescription& desc)
00138 {
00139 *this << desc.Id;
00140 *this << desc.Timestamp;
00141 *this << desc.Version;
00142 }
00143
00144 template<>
00145 void DataDeserializer::Deserialize<ViewDescription>(ViewDescription& desc)
00146 {
00147 *this >> desc.Id;
00148 *this >> desc.Timestamp;
00149 *this >> desc.Version;
00150 }
00151
00152
00153
00154
00155
00156
00157 template<>
00158 std::size_t RawSize<BrowseDescription>(const BrowseDescription& desc)
00159 {
00160 return RawSize(desc.NodeToBrowse) +
00161 RawSize(desc.Direction) +
00162 RawSize(desc.ReferenceTypeId) +
00163 RawSize(desc.IncludeSubtypes) +
00164 RawSize(desc.NodeClasses) +
00165 RawSize(desc.ResultMask);
00166 }
00167
00168 template<>
00169 void DataSerializer::Serialize<BrowseDescription>(const BrowseDescription& desc)
00170 {
00171 *this << desc.NodeToBrowse;
00172 *this << desc.Direction;
00173 *this << desc.ReferenceTypeId;
00174 *this << desc.IncludeSubtypes;
00175 *this << desc.NodeClasses;
00176 *this << desc.ResultMask;
00177 }
00178
00179 template<>
00180 void DataDeserializer::Deserialize<BrowseDescription>(BrowseDescription& desc)
00181 {
00182 *this >> desc.NodeToBrowse;
00183 *this >> desc.Direction;
00184 *this >> desc.ReferenceTypeId;
00185 *this >> desc.IncludeSubtypes;
00186 *this >> desc.NodeClasses;
00187 *this >> desc.ResultMask;
00188 }
00189
00191
00193
00194 template<>
00195 std::size_t RawSize<NodesQuery>(const NodesQuery& desc)
00196 {
00197 return RawSize(desc.View) + RawSize(desc.MaxReferenciesPerNode) + RawSizeContainer(desc.NodesToBrowse);
00198 }
00199
00200 template<>
00201 void DataSerializer::Serialize<NodesQuery>(const NodesQuery& desc)
00202 {
00203 *this << desc.View;
00204 *this << desc.MaxReferenciesPerNode;
00205 SerializeContainer(*this, desc.NodesToBrowse);
00206 }
00207
00208 template<>
00209 void DataDeserializer::Deserialize<NodesQuery>(NodesQuery& desc)
00210 {
00211 *this >> desc.View;
00212 *this >> desc.MaxReferenciesPerNode;
00213 DeserializeContainer(*this, desc.NodesToBrowse);
00214 }
00215
00216
00217
00218
00219
00220 template<>
00221 std::size_t RawSize<BrowseRequest>(const BrowseRequest& request)
00222 {
00223 return RawSize(request.TypeId) + RawSize(request.Header) + RawSize(request.Query);
00224 }
00225
00226 template<>
00227 void DataSerializer::Serialize<BrowseRequest>(const BrowseRequest& request)
00228 {
00229 *this << request.TypeId;
00230 *this << request.Header;
00231 *this << request.Query;
00232 }
00233
00234 template<>
00235 void DataDeserializer::Deserialize<BrowseRequest>(BrowseRequest& request)
00236 {
00237 *this >> request.TypeId;
00238 *this >> request.Header;
00239 *this >> request.Query;
00240 }
00241
00242
00243
00244
00245
00246 template<>
00247 std::size_t RawSize<ReferenceDescription>(const ReferenceDescription& desc)
00248 {
00249 return RawSize(desc.ReferenceTypeId) +
00250 RawSize(desc.IsForward) +
00251 RawSize(desc.TargetNodeId) +
00252 RawSize(desc.BrowseName) +
00253 RawSize(desc.DisplayName) +
00254 RawSize(desc.TargetNodeClass) +
00255 RawSize(desc.TargetNodeTypeDefinition);
00256 }
00257
00258 template<>
00259 void DataSerializer::Serialize<ReferenceDescription>(const ReferenceDescription& desc)
00260 {
00261 *this << desc.ReferenceTypeId;
00262 *this << desc.IsForward;
00263 *this << desc.TargetNodeId;
00264 *this << desc.BrowseName;
00265 *this << desc.DisplayName;
00266 *this << desc.TargetNodeClass;
00267 *this << desc.TargetNodeTypeDefinition;
00268 }
00269
00270 template<>
00271 void DataDeserializer::Deserialize<ReferenceDescription>(ReferenceDescription& desc)
00272 {
00273 *this >> desc.ReferenceTypeId;
00274 *this >> desc.IsForward;
00275 *this >> desc.TargetNodeId;
00276 *this >> desc.BrowseName;
00277 *this >> desc.DisplayName;
00278 *this >> desc.TargetNodeClass;
00279 *this >> desc.TargetNodeTypeDefinition;
00280 }
00281
00282
00283
00284
00285
00286 template<>
00287 std::size_t RawSize<BrowseResult>(const BrowseResult& result)
00288 {
00289 return RawSize(result.Status) +
00290 RawSizeContainer(result.ContinuationPoint) +
00291 RawSizeContainer(result.Referencies);
00292 }
00293
00294 template<>
00295 void DataSerializer::Serialize<BrowseResult>(const BrowseResult& result)
00296 {
00297 *this << result.Status;
00298 SerializeContainer(*this, result.ContinuationPoint);
00299 SerializeContainer(*this, result.Referencies);
00300 }
00301
00302 template<>
00303 void DataDeserializer::Deserialize<BrowseResult>(BrowseResult& result)
00304 {
00305 *this >> result.Status;
00306 DeserializeContainer(*this, result.ContinuationPoint);
00307 DeserializeContainer(*this, result.Referencies);
00308 }
00309
00310
00311
00312
00313
00314 template<>
00315 std::size_t RawSize<BrowseResponse>(const BrowseResponse& response)
00316 {
00317 return RawSize(response.TypeId) + RawSize(response.Header) +
00318 RawSizeContainer(response.Results) +
00319 RawSizeContainer(response.Diagnostics);
00320 }
00321
00322 template<>
00323 void DataSerializer::Serialize<BrowseResponse>(const BrowseResponse& response)
00324 {
00325 *this << response.TypeId;
00326 *this << response.Header;
00327
00328 SerializeContainer(*this, response.Results, 0);
00329 SerializeContainer(*this, response.Diagnostics, 0);
00330 }
00331
00332 template<>
00333 void DataDeserializer::Deserialize<BrowseResponse>(BrowseResponse& response)
00334 {
00335 *this >> response.TypeId;
00336 *this >> response.Header;
00337
00338 DeserializeContainer(*this, response.Results);
00339 DeserializeContainer(*this, response.Diagnostics);
00340 }
00341
00342
00343
00344
00345
00346 template<>
00347 std::size_t RawSize<BrowseNextRequest>(const BrowseNextRequest& request)
00348 {
00349 return RawSize(request.TypeId) + RawSize(request.Header) +
00350 RawSize(request.ReleaseContinuationPoints) +
00351 RawSize(request.ContinuationPoints);
00352 }
00353
00354 template<>
00355 void DataSerializer::Serialize<BrowseNextRequest>(const BrowseNextRequest& request)
00356 {
00357 *this << request.TypeId;
00358 *this << request.Header;
00359
00360 *this << request.ReleaseContinuationPoints;
00361 SerializeContainer(*this, request.ContinuationPoints);
00362 }
00363
00364 template<>
00365 void DataDeserializer::Deserialize<BrowseNextRequest>(BrowseNextRequest& request)
00366 {
00367 *this >> request.TypeId;
00368 *this >> request.Header;
00369
00370 *this >> request.ReleaseContinuationPoints;
00371 DeserializeContainer(*this, request.ContinuationPoints);
00372 }
00373
00374
00375
00376
00377
00378 template<>
00379 std::size_t RawSize<BrowseNextResponse>(const BrowseNextResponse& response)
00380 {
00381 return RawSize(response.TypeId) + RawSize(response.Header) +
00382 RawSizeContainer(response.Results) +
00383 RawSizeContainer(response.Diagnostics);
00384 }
00385
00386 template<>
00387 void DataSerializer::Serialize<BrowseNextResponse>(const BrowseNextResponse& response)
00388 {
00389 *this << response.TypeId;
00390 *this << response.Header;
00391
00392 SerializeContainer(*this, response.Results, 0);
00393 SerializeContainer(*this, response.Diagnostics, 0);
00394 }
00395
00396 template<>
00397 void DataDeserializer::Deserialize<BrowseNextResponse>(BrowseNextResponse& response)
00398 {
00399 *this >> response.TypeId;
00400 *this >> response.Header;
00401
00402 DeserializeContainer(*this, response.Results);
00403 DeserializeContainer(*this, response.Diagnostics);
00404 }
00405
00407
00409
00410 template<>
00411 std::size_t RawSize<BrowsePathTarget>(const BrowsePathTarget& target)
00412 {
00413 return RawSize(target.Node) + RawSize(target.RemainingPathIndex);
00414 }
00415
00416 template<>
00417 void DataSerializer::Serialize<BrowsePathTarget>(const BrowsePathTarget& target)
00418 {
00419 *this << target.Node;
00420 *this << target.RemainingPathIndex;
00421 }
00422
00423 template<>
00424 void DataDeserializer::Deserialize<BrowsePathTarget>(BrowsePathTarget& target)
00425 {
00426 *this >> target.Node;
00427 *this >> target.RemainingPathIndex;
00428 }
00429
00430 template<>
00431 void DataSerializer::Serialize<std::vector<BrowsePathTarget>>(const std::vector<BrowsePathTarget>& targets)
00432 {
00433 SerializeContainer(*this, targets);
00434 }
00435
00436 template<>
00437 void DataDeserializer::Deserialize<std::vector<BrowsePathTarget>>(std::vector<BrowsePathTarget>& targets)
00438 {
00439 DeserializeContainer(*this, targets);
00440 }
00441
00443
00445
00446 template<>
00447 std::size_t RawSize<BrowsePathResult>(const BrowsePathResult& result)
00448 {
00449 return RawSize(result.Status) + RawSizeContainer(result.Targets);
00450 }
00451
00452 template<>
00453 void DataSerializer::Serialize<BrowsePathResult>(const BrowsePathResult& result)
00454 {
00455 *this << result.Status;
00456 *this << result.Targets;
00457 }
00458
00459 template<>
00460 void DataDeserializer::Deserialize<BrowsePathResult>(BrowsePathResult& result)
00461 {
00462 *this >> result.Status;
00463 *this >> result.Targets;
00464 }
00465
00466 template<>
00467 void DataSerializer::Serialize<std::vector<BrowsePathResult>>(const std::vector<BrowsePathResult>& results)
00468 {
00469 SerializeContainer(*this, results);
00470 }
00471
00472 template<>
00473 void DataDeserializer::Deserialize<std::vector<BrowsePathResult>>(std::vector<BrowsePathResult>& results)
00474 {
00475 DeserializeContainer(*this, results);
00476 }
00477
00479
00481
00482 template<>
00483 std::size_t RawSize<TranslateBrowsePathsResult>(const TranslateBrowsePathsResult& result)
00484 {
00485 return RawSizeContainer(result.Paths) + RawSizeContainer(result.Diagnostics);
00486 }
00487
00488 template<>
00489 void DataSerializer::Serialize<TranslateBrowsePathsResult>(const TranslateBrowsePathsResult& result)
00490 {
00491 *this << result.Paths;
00492 *this << result.Diagnostics;
00493 }
00494
00495 template<>
00496 void DataDeserializer::Deserialize<TranslateBrowsePathsResult>(TranslateBrowsePathsResult& result)
00497 {
00498 *this >> result.Paths;
00499 *this >> result.Diagnostics;
00500 }
00501
00503
00505
00506 template<>
00507 std::size_t RawSize<TranslateBrowsePathsToNodeIdsResponse>(const TranslateBrowsePathsToNodeIdsResponse& response)
00508 {
00509 return RawSize(response.TypeId) + RawSize(response.Header) + RawSize(response.Result);
00510 }
00511
00512 template<>
00513 void DataSerializer::Serialize<TranslateBrowsePathsToNodeIdsResponse>(const TranslateBrowsePathsToNodeIdsResponse& response)
00514 {
00515 *this << response.TypeId;
00516 *this << response.Header;
00517 *this << response.Result;
00518 }
00519
00520 template<>
00521 void DataDeserializer::Deserialize<TranslateBrowsePathsToNodeIdsResponse>(TranslateBrowsePathsToNodeIdsResponse& response)
00522 {
00523 *this >> response.TypeId;
00524 *this >> response.Header;
00525 *this >> response.Result;
00526 }
00527
00529
00531
00532 template<>
00533 std::size_t RawSize<RegisterNodesRequest>(const RegisterNodesRequest& request)
00534 {
00535 return RawSize(request.TypeId) + RawSize(request.Header) + RawSizeContainer(request.NodesToRegister);
00536 }
00537
00538 template<>
00539 void DataSerializer::Serialize<RegisterNodesRequest>(const RegisterNodesRequest& request)
00540 {
00541 *this << request.TypeId;
00542 *this << request.Header;
00543 SerializeContainer(*this, request.NodesToRegister);
00544 }
00545
00546 template<>
00547 void DataDeserializer::Deserialize<RegisterNodesRequest>(RegisterNodesRequest& request)
00548 {
00549 *this >> request.TypeId;
00550 *this >> request.Header;
00551 DeserializeContainer(*this, request.NodesToRegister);
00552 }
00553
00555
00557
00558 template<>
00559 std::size_t RawSize<RegisterNodesResponse>(const RegisterNodesResponse& response)
00560 {
00561 return RawSize(response.TypeId) + RawSize(response.Header) + RawSizeContainer(response.Result);
00562 }
00563
00564 template<>
00565 void DataSerializer::Serialize<RegisterNodesResponse>(const RegisterNodesResponse& response)
00566 {
00567 *this << response.TypeId;
00568 *this << response.Header;
00569 SerializeContainer(*this, response.Result);
00570 }
00571
00572 template<>
00573 void DataDeserializer::Deserialize<RegisterNodesResponse>(RegisterNodesResponse& response)
00574 {
00575 *this >> response.TypeId;
00576 *this >> response.Header;
00577 DeserializeContainer(*this, response.Result);
00578 }
00579
00581
00583
00584 template<>
00585 std::size_t RawSize<UnregisterNodesRequest>(const UnregisterNodesRequest& request)
00586 {
00587 return RawSize(request.TypeId) + RawSize(request.Header) + RawSizeContainer(request.NodesToUnregister);
00588 }
00589
00590 template<>
00591 void DataSerializer::Serialize<UnregisterNodesRequest>(const UnregisterNodesRequest& request)
00592 {
00593 *this << request.TypeId;
00594 *this << request.Header;
00595 SerializeContainer(*this, request.NodesToUnregister);
00596 }
00597
00598 template<>
00599 void DataDeserializer::Deserialize<UnregisterNodesRequest>(UnregisterNodesRequest& request)
00600 {
00601 *this >> request.TypeId;
00602 *this >> request.Header;
00603 DeserializeContainer(*this, request.NodesToUnregister);
00604 }
00605
00607
00609
00610 template<>
00611 std::size_t RawSize<UnregisterNodesResponse>(const UnregisterNodesResponse& response)
00612 {
00613 return RawSize(response.TypeId) + RawSize(response.Header);
00614 }
00615
00616 template<>
00617 void DataSerializer::Serialize<UnregisterNodesResponse>(const UnregisterNodesResponse& response)
00618 {
00619 *this << response.TypeId;
00620 *this << response.Header;
00621 }
00622
00623 template<>
00624 void DataDeserializer::Deserialize<UnregisterNodesResponse>(UnregisterNodesResponse& response)
00625 {
00626 *this >> response.TypeId;
00627 *this >> response.Header;
00628 }
00629
00631
00633
00634 template<>
00635 std::size_t RawSize<RelativePathElement>(const RelativePathElement& element)
00636 {
00637 return RawSize(element.IncludeSubtypes) + RawSize(element.IsInverse) + RawSize(element.ReferenceTypeId) + RawSize(element.TargetName);
00638 }
00639
00640 template<>
00641 void DataSerializer::Serialize<RelativePathElement>(const RelativePathElement& path)
00642 {
00643 *this << path.ReferenceTypeId;
00644 *this << path.IsInverse;
00645 *this << path.IncludeSubtypes;
00646 *this << path.TargetName;
00647 }
00648
00649 template<>
00650 void DataDeserializer::Deserialize<RelativePathElement>(RelativePathElement& path)
00651 {
00652 *this >> path.ReferenceTypeId;
00653 *this >> path.IsInverse;
00654 *this >> path.IncludeSubtypes;
00655 *this >> path.TargetName;
00656 }
00657
00658 template<>
00659 void DataDeserializer::Deserialize<std::vector<RelativePathElement>>(std::vector<RelativePathElement>& targets)
00660 {
00661 DeserializeContainer(*this, targets);
00662 }
00663
00664 template<>
00665 void DataSerializer::Serialize<std::vector<RelativePathElement>>( const std::vector<RelativePathElement>& targets)
00666 {
00667 SerializeContainer(*this, targets);
00668 }
00669
00671
00673
00674 template<>
00675 std::size_t RawSize<RelativePath>(const RelativePath& rpath)
00676 {
00677 return RawSizeContainer(rpath.Elements);
00678 }
00679
00680 template<>
00681 void DataSerializer::Serialize<RelativePath>(const RelativePath& path)
00682 {
00683 *this << path.Elements;
00684 }
00685
00686 template<>
00687 void DataDeserializer::Deserialize<RelativePath>(RelativePath& path)
00688 {
00689 *this >> path.Elements;
00690 }
00691
00693
00695
00696 template<>
00697 std::size_t RawSize<BrowsePath>(const BrowsePath& path)
00698 {
00699 return RawSize(path.StartingNode) + RawSize(path.Path);
00700 }
00701
00702 template<>
00703 void DataDeserializer::Deserialize<BrowsePath>(BrowsePath& path)
00704 {
00705 *this >> path.StartingNode;
00706 *this >> path.Path;
00707 }
00708
00709 template<>
00710 void DataSerializer::Serialize<BrowsePath>(const BrowsePath& path)
00711 {
00712 *this << path.StartingNode;
00713 *this << path.Path;
00714 }
00715
00716 template<>
00717 void DataDeserializer::Deserialize<std::vector<BrowsePath>>(std::vector<BrowsePath>& paths)
00718 {
00719 DeserializeContainer(*this, paths);
00720 }
00721
00722 template<>
00723 void DataSerializer::Serialize<std::vector<BrowsePath>>(const std::vector<BrowsePath>& paths)
00724 {
00725 SerializeContainer(*this, paths);
00726 }
00727
00729
00731
00732 template<>
00733 std::size_t RawSize<TranslateBrowsePathsParameters>(const TranslateBrowsePathsParameters& params)
00734 {
00735 return RawSizeContainer(params.BrowsePaths);
00736 }
00737
00738 template<>
00739 void DataSerializer::Serialize<TranslateBrowsePathsParameters>(const TranslateBrowsePathsParameters& params)
00740 {
00741 *this << params.BrowsePaths;
00742 }
00743
00744 template<>
00745 void DataDeserializer::Deserialize<TranslateBrowsePathsParameters>(TranslateBrowsePathsParameters& path)
00746 {
00747 *this >> path.BrowsePaths;
00748 }
00749
00751
00753
00754 template<>
00755 std::size_t RawSize<TranslateBrowsePathsToNodeIdsRequest>(const TranslateBrowsePathsToNodeIdsRequest& request)
00756 {
00757 return RawSize(request.TypeId) + RawSize(request.Header) + RawSize(request.Parameters) ;
00758 }
00759
00760 template<>
00761 void DataSerializer::Serialize<TranslateBrowsePathsToNodeIdsRequest>(const TranslateBrowsePathsToNodeIdsRequest& request)
00762 {
00763 *this << request.TypeId;
00764 *this << request.Header;
00765 *this << request.Parameters;
00766 }
00767
00768 template<>
00769 void DataDeserializer::Deserialize<TranslateBrowsePathsToNodeIdsRequest>(TranslateBrowsePathsToNodeIdsRequest& request)
00770 {
00771 *this >> request.TypeId;
00772 *this >> request.Header;
00773 *this >> request.Parameters;
00774 }
00775
00776 }
00777 }