@@ -35,49 +35,42 @@ namespace shapes_demo_typesupport {
35
35
namespace idl {
36
36
KeylessShapeTypePubSubType::KeylessShapeTypePubSubType ()
37
37
{
38
- setName (" shapes_demo_typesupport::idl::KeylessShapeType" );
39
- uint32_t type_size =
40
- #if FASTCDR_VERSION_MAJOR == 1
41
- static_cast <uint32_t >(KeylessShapeType::getMaxCdrSerializedSize ());
42
- #else
43
- shapes_demo_typesupport_idl_KeylessShapeType_max_cdr_typesize;
44
- #endif
38
+ set_name (" shapes_demo_typesupport::idl::KeylessShapeType" );
39
+ uint32_t type_size = shapes_demo_typesupport_idl_KeylessShapeType_max_cdr_typesize;
45
40
type_size += static_cast <uint32_t >(eprosima::fastcdr::Cdr::alignment (type_size, 4 )); /* possible submessage alignment */
46
- m_typeSize = type_size + 4 ; /* encapsulation*/
47
- m_isGetKeyDefined = false ;
48
- uint32_t keyLength = shapes_demo_typesupport_idl_KeylessShapeType_max_key_cdr_typesize > 16 ? shapes_demo_typesupport_idl_KeylessShapeType_max_key_cdr_typesize : 16 ;
49
- m_keyBuffer = reinterpret_cast <unsigned char *>(malloc (keyLength ));
50
- memset (m_keyBuffer , 0 , keyLength );
41
+ max_serialized_type_size = type_size + 4 ; /* encapsulation*/
42
+ is_compute_key_provided = false ;
43
+ uint32_t key_length = shapes_demo_typesupport_idl_KeylessShapeType_max_key_cdr_typesize > 16 ? shapes_demo_typesupport_idl_KeylessShapeType_max_key_cdr_typesize : 16 ;
44
+ key_buffer_ = reinterpret_cast <unsigned char *>(malloc (key_length ));
45
+ memset (key_buffer_ , 0 , key_length );
51
46
}
52
47
53
48
KeylessShapeTypePubSubType::~KeylessShapeTypePubSubType ()
54
49
{
55
- if (m_keyBuffer != nullptr )
50
+ if (key_buffer_ != nullptr )
56
51
{
57
- free (m_keyBuffer );
52
+ free (key_buffer_ );
58
53
}
59
54
}
60
55
61
56
bool KeylessShapeTypePubSubType::serialize (
62
57
const void * const data,
63
- SerializedPayload_t* payload,
58
+ SerializedPayload_t& payload,
64
59
DataRepresentationId_t data_representation)
65
60
{
66
61
const KeylessShapeType* p_type = static_cast <const KeylessShapeType*>(data);
67
62
68
63
// Object that manages the raw buffer.
69
- eprosima::fastcdr::FastBuffer fastbuffer (reinterpret_cast <char *>(payload-> data ), payload-> max_size );
64
+ eprosima::fastcdr::FastBuffer fastbuffer (reinterpret_cast <char *>(payload. data ), payload. max_size );
70
65
// Object that serializes the data.
71
66
eprosima::fastcdr::Cdr ser (fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
72
67
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
73
68
eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2);
74
- payload->encapsulation = ser.endianness () == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
75
- #if FASTCDR_VERSION_MAJOR > 1
69
+ payload.encapsulation = ser.endianness () == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
76
70
ser.set_encoding_flag (
77
71
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
78
72
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR :
79
73
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2);
80
- #endif // FASTCDR_VERSION_MAJOR > 1
81
74
82
75
try
83
76
{
@@ -92,16 +85,12 @@ namespace shapes_demo_typesupport {
92
85
}
93
86
94
87
// Get the serialized length
95
- #if FASTCDR_VERSION_MAJOR == 1
96
- payload->length = static_cast <uint32_t >(ser.getSerializedDataLength ());
97
- #else
98
- payload->length = static_cast <uint32_t >(ser.get_serialized_data_length ());
99
- #endif // FASTCDR_VERSION_MAJOR == 1
88
+ payload.length = static_cast <uint32_t >(ser.get_serialized_data_length ());
100
89
return true ;
101
90
}
102
91
103
92
bool KeylessShapeTypePubSubType::deserialize (
104
- SerializedPayload_t* payload,
93
+ SerializedPayload_t& payload,
105
94
void * data)
106
95
{
107
96
try
@@ -110,18 +99,14 @@ namespace shapes_demo_typesupport {
110
99
KeylessShapeType* p_type = static_cast <KeylessShapeType*>(data);
111
100
112
101
// Object that manages the raw buffer.
113
- eprosima::fastcdr::FastBuffer fastbuffer (reinterpret_cast <char *>(payload-> data ), payload-> length );
102
+ eprosima::fastcdr::FastBuffer fastbuffer (reinterpret_cast <char *>(payload. data ), payload. length );
114
103
115
104
// Object that deserializes the data.
116
- eprosima::fastcdr::Cdr deser (fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN
117
- #if FASTCDR_VERSION_MAJOR == 1
118
- , eprosima::fastcdr::Cdr::CdrType::DDS_CDR
119
- #endif // FASTCDR_VERSION_MAJOR == 1
120
- );
105
+ eprosima::fastcdr::Cdr deser (fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN);
121
106
122
107
// Deserialize encapsulation.
123
108
deser.read_encapsulation ();
124
- payload-> encapsulation = deser.endianness () == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
109
+ payload. encapsulation = deser.endianness () == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
125
110
126
111
// Deserialize the object.
127
112
deser >> *p_type;
@@ -134,88 +119,90 @@ namespace shapes_demo_typesupport {
134
119
return true ;
135
120
}
136
121
137
- std::function< uint32_t ()> KeylessShapeTypePubSubType::getSerializedSizeProvider (
122
+ uint32_t KeylessShapeTypePubSubType::calculate_serialized_size (
138
123
const void * const data,
139
124
DataRepresentationId_t data_representation)
140
125
{
141
- return [data, data_representation]() -> uint32_t
142
- {
143
- #if FASTCDR_VERSION_MAJOR == 1
144
- static_cast <void >(data_representation);
145
- return static_cast <uint32_t >(type::getCdrSerializedSize (*static_cast <KeylessShapeType*>(data))) +
146
- 4u /* encapsulation*/ ;
147
- #else
148
- try
149
- {
150
- eprosima::fastcdr::CdrSizeCalculator calculator (
151
- data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
152
- eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2);
153
- size_t current_alignment {0 };
154
- return static_cast <uint32_t >(calculator.calculate_serialized_size (
155
- *static_cast <const KeylessShapeType*>(data), current_alignment)) +
156
- 4u /* encapsulation*/ ;
157
- }
158
- catch (eprosima::fastcdr::exception::Exception& /* exception*/ )
159
- {
160
- return 0 ;
161
- }
162
- #endif // FASTCDR_VERSION_MAJOR == 1
163
- };
126
+ try
127
+ {
128
+ eprosima::fastcdr::CdrSizeCalculator calculator (
129
+ data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
130
+ eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2);
131
+ size_t current_alignment {0 };
132
+ return static_cast <uint32_t >(calculator.calculate_serialized_size (
133
+ *static_cast <const KeylessShapeType*>(data), current_alignment)) +
134
+ 4u /* encapsulation*/ ;
135
+ }
136
+ catch (eprosima::fastcdr::exception::Exception& /* exception*/ )
137
+ {
138
+ return 0 ;
139
+ }
164
140
}
165
141
166
- void * KeylessShapeTypePubSubType::createData ()
142
+ void * KeylessShapeTypePubSubType::create_data ()
167
143
{
168
144
return reinterpret_cast <void *>(new KeylessShapeType ());
169
145
}
170
146
171
- void KeylessShapeTypePubSubType::deleteData (
147
+ void KeylessShapeTypePubSubType::delete_data (
172
148
void * data)
173
149
{
174
150
delete (reinterpret_cast <KeylessShapeType*>(data));
175
151
}
176
152
177
- bool KeylessShapeTypePubSubType::getKey (
153
+ bool KeylessShapeTypePubSubType::compute_key (
154
+ SerializedPayload_t& payload,
155
+ InstanceHandle_t& handle,
156
+ bool force_md5)
157
+ {
158
+ if (!is_compute_key_provided)
159
+ {
160
+ return false ;
161
+ }
162
+
163
+ KeylessShapeType data;
164
+ if (deserialize (payload, static_cast <void *>(&data)))
165
+ {
166
+ return compute_key (static_cast <void *>(&data), handle, force_md5);
167
+ }
168
+
169
+ return false ;
170
+ }
171
+
172
+ bool KeylessShapeTypePubSubType::compute_key (
178
173
const void * const data,
179
- InstanceHandle_t* handle,
174
+ InstanceHandle_t& handle,
180
175
bool force_md5)
181
176
{
182
- if (!m_isGetKeyDefined )
177
+ if (!is_compute_key_provided )
183
178
{
184
179
return false ;
185
180
}
186
181
187
182
const KeylessShapeType* p_type = static_cast <const KeylessShapeType*>(data);
188
183
189
184
// Object that manages the raw buffer.
190
- eprosima::fastcdr::FastBuffer fastbuffer (reinterpret_cast <char *>(m_keyBuffer ),
185
+ eprosima::fastcdr::FastBuffer fastbuffer (reinterpret_cast <char *>(key_buffer_ ),
191
186
shapes_demo_typesupport_idl_KeylessShapeType_max_key_cdr_typesize);
192
187
193
188
// Object that serializes the data.
194
189
eprosima::fastcdr::Cdr ser (fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1);
195
- #if FASTCDR_VERSION_MAJOR == 1
196
- p_type->serializeKey (ser);
197
- #else
198
190
eprosima::fastcdr::serialize_key (ser, *p_type);
199
- #endif // FASTCDR_VERSION_MAJOR == 1
200
191
if (force_md5 || shapes_demo_typesupport_idl_KeylessShapeType_max_key_cdr_typesize > 16 )
201
192
{
202
- m_md5.init ();
203
- #if FASTCDR_VERSION_MAJOR == 1
204
- m_md5.update (m_keyBuffer, static_cast <unsigned int >(ser.getSerializedDataLength ()));
205
- #else
206
- m_md5.update (m_keyBuffer, static_cast <unsigned int >(ser.get_serialized_data_length ()));
207
- #endif // FASTCDR_VERSION_MAJOR == 1
208
- m_md5.finalize ();
193
+ md5_.init ();
194
+ md5_.update (key_buffer_, static_cast <unsigned int >(ser.get_serialized_data_length ()));
195
+ md5_.finalize ();
209
196
for (uint8_t i = 0 ; i < 16 ; ++i)
210
197
{
211
- handle-> value [i] = m_md5 .digest [i];
198
+ handle. value [i] = md5_ .digest [i];
212
199
}
213
200
}
214
201
else
215
202
{
216
203
for (uint8_t i = 0 ; i < 16 ; ++i)
217
204
{
218
- handle-> value [i] = m_keyBuffer [i];
205
+ handle. value [i] = key_buffer_ [i];
219
206
}
220
207
}
221
208
return true ;
0 commit comments