-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFieldRequirementsData.cpp
More file actions
126 lines (104 loc) · 4.96 KB
/
Copy pathFieldRequirementsData.cpp
File metadata and controls
126 lines (104 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
The MIT License
Copyright (c) 2019 Lehrstuhl Informatik 11 - RWTH Aachen University
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE
This file is part of embeddedRTPS.
Author: i11 - Embedded Software, RWTH Aachen University
*/
#include "rtps/discovery/FieldRequirementsData.h"
#include "rtps/messages/MessageTypes.h"
using rtps::FieldRequirementsData;
// Custom Parameter IDs for FRDP (vendor-specific range 0x8000-0x8FFF)
constexpr uint16_t PID_FIELD_MASK = 0x8001;
constexpr uint16_t PID_UPDATE_SEQUENCE = 0x8002;
bool FieldRequirementsData::readFromUcdrBuffer(ucdrBuffer &buffer) {
while (ucdr_buffer_remaining(&buffer) >= 4) {
rtps::SMElement::ParameterId pid;
uint16_t length;
ucdr_deserialize_uint16_t(&buffer, reinterpret_cast<uint16_t *>(&pid));
ucdr_deserialize_uint16_t(&buffer, &length);
if (ucdr_buffer_remaining(&buffer) < length) {
return false;
}
switch (pid) {
case rtps::SMElement::ParameterId::PID_ENDPOINT_GUID:
ucdr_deserialize_array_uint8_t(&buffer, readerGuid.prefix.id.data(),
readerGuid.prefix.id.size());
ucdr_deserialize_array_uint8_t(&buffer, readerGuid.entityId.entityKey.data(),
readerGuid.entityId.entityKey.size());
ucdr_deserialize_uint8_t(&buffer,
reinterpret_cast<uint8_t *>(&readerGuid.entityId.entityKind));
break;
case PID_FIELD_MASK:
ucdr_deserialize_uint32_t(&buffer, &fieldMask);
break;
case PID_UPDATE_SEQUENCE:
ucdr_deserialize_uint32_t(&buffer, &updateSequence);
break;
case rtps::SMElement::ParameterId::PID_SENTINEL:
return true;
default: {
// Skip unknown parameters safely via deserialization
uint8_t skip_byte;
for (uint16_t i = 0; i < length; ++i) {
ucdr_deserialize_uint8_t(&buffer, &skip_byte);
}
break;
}
}
// Maintain 4-byte alignment
while (ucdr_buffer_remaining(&buffer) > 0 &&
((buffer.iterator - buffer.init) % 4) != 0) {
uint8_t pad;
ucdr_deserialize_uint8_t(&buffer, &pad);
}
}
return ucdr_buffer_remaining(&buffer) == 0;
}
bool FieldRequirementsData::serializeIntoUcdrBuffer(ucdrBuffer &buffer) const {
const uint16_t guidSize = sizeof(GuidPrefix_t::id) + 4;
// PID_ENDPOINT_GUID (reader GUID)
ucdr_serialize_uint16_t(&buffer, rtps::SMElement::ParameterId::PID_ENDPOINT_GUID);
ucdr_serialize_uint16_t(&buffer, guidSize);
ucdr_serialize_array_uint8_t(&buffer, readerGuid.prefix.id.data(),
readerGuid.prefix.id.size());
ucdr_serialize_array_uint8_t(&buffer, readerGuid.entityId.entityKey.data(),
readerGuid.entityId.entityKey.size());
ucdr_serialize_uint8_t(&buffer,
static_cast<uint8_t>(readerGuid.entityId.entityKind));
// PID_KEY_HASH (for keyed topic compatibility)
ucdr_serialize_uint16_t(&buffer, rtps::SMElement::ParameterId::PID_KEY_HASH);
ucdr_serialize_uint16_t(&buffer, guidSize);
ucdr_serialize_array_uint8_t(&buffer, readerGuid.prefix.id.data(),
readerGuid.prefix.id.size());
ucdr_serialize_array_uint8_t(&buffer, readerGuid.entityId.entityKey.data(),
readerGuid.entityId.entityKey.size());
ucdr_serialize_uint8_t(&buffer,
static_cast<uint8_t>(readerGuid.entityId.entityKind));
// PID_FIELD_MASK (custom parameter)
ucdr_serialize_uint16_t(&buffer, PID_FIELD_MASK);
ucdr_serialize_uint16_t(&buffer, sizeof(uint32_t));
ucdr_serialize_uint32_t(&buffer, fieldMask);
// PID_UPDATE_SEQUENCE (custom parameter)
ucdr_serialize_uint16_t(&buffer, PID_UPDATE_SEQUENCE);
ucdr_serialize_uint16_t(&buffer, sizeof(uint32_t));
ucdr_serialize_uint32_t(&buffer, updateSequence);
// PID_SENTINEL (marks end of parameter list)
ucdr_serialize_uint16_t(&buffer, rtps::SMElement::ParameterId::PID_SENTINEL);
ucdr_serialize_uint16_t(&buffer, 0);
return true;
}