Skip to content

Commit 09f6c70

Browse files
committed
Refs #20165: Fix for custom annotations name hash.
Signed-off-by: adriancampo <[email protected]>
1 parent bc1442c commit 09f6c70

15 files changed

+2476
-1794
lines changed

src/cpp/fastdds/xtypes/dynamic_types/DynamicTypeBuilderFactoryImpl.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,10 @@ traits<DynamicTypeBuilder>::ref_type DynamicTypeBuilderFactoryImpl::create_annot
464464
break;
465465
}
466466
member_descriptor->type(type);
467-
member_descriptor->name(parameter.name());
467+
// Name hashes are used because the full name is not present in AppliedAnnotationParameter
468+
// and can not be used in apply_custom_annotations when adding the members
469+
xtypes::NameHash parameter_name_hash = xtypes::TypeObjectUtils::name_hash(parameter.name().to_string());
470+
member_descriptor->name(get_string_from_name_hash(parameter_name_hash));
468471
member_descriptor->default_value(get_annotation_parameter_value(parameter.default_value()));
469472
if (RETCODE_OK != ret_val->add_member(member_descriptor))
470473
{
@@ -1413,7 +1416,15 @@ bool DynamicTypeBuilderFactoryImpl::apply_custom_annotations(
14131416
break;
14141417
}
14151418
traits<AnnotationDescriptor>::ref_type annotation_descriptor {traits<AnnotationDescriptor>::make_shared()};
1416-
annotation_descriptor->type(create_type_w_type_object(annotation_type_object)->build());
1419+
auto type = create_type_w_type_object(annotation_type_object);
1420+
if (!type)
1421+
{
1422+
EPROSIMA_LOG_ERROR(DYN_TYPES, "Type could not be created from TypeObject");
1423+
ret_val.reset();
1424+
break;
1425+
}
1426+
1427+
annotation_descriptor->type(type->build());
14171428
if (annotation.param_seq().has_value())
14181429
{
14191430
for (const xtypes::AppliedAnnotationParameter& parameter : annotation.param_seq().value())
@@ -1422,6 +1433,7 @@ bool DynamicTypeBuilderFactoryImpl::apply_custom_annotations(
14221433
get_annotation_parameter_value(parameter.value()));
14231434
}
14241435
}
1436+
14251437
if (member_id != MEMBER_ID_INVALID &&
14261438
ret_val && RETCODE_OK != ret_val->apply_annotation_to_member(member_id, annotation_descriptor))
14271439
{

test/dds-types-test/annotations.hpp

+124
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,130 @@ class EmptyAnnotatedStruct
260260
private:
261261

262262

263+
};
264+
265+
/*!
266+
* @brief This class represents the structure BasicAnnotationsStruct defined by the user in the IDL file.
267+
* @ingroup annotations
268+
*/
269+
class BasicAnnotationsStruct
270+
{
271+
public:
272+
273+
/*!
274+
* @brief Default constructor.
275+
*/
276+
eProsima_user_DllExport BasicAnnotationsStruct()
277+
{
278+
}
279+
280+
/*!
281+
* @brief Default destructor.
282+
*/
283+
eProsima_user_DllExport ~BasicAnnotationsStruct()
284+
{
285+
}
286+
287+
/*!
288+
* @brief Copy constructor.
289+
* @param x Reference to the object BasicAnnotationsStruct that will be copied.
290+
*/
291+
eProsima_user_DllExport BasicAnnotationsStruct(
292+
const BasicAnnotationsStruct& x)
293+
{
294+
m_basic_annotations_member = x.m_basic_annotations_member;
295+
296+
}
297+
298+
/*!
299+
* @brief Move constructor.
300+
* @param x Reference to the object BasicAnnotationsStruct that will be copied.
301+
*/
302+
eProsima_user_DllExport BasicAnnotationsStruct(
303+
BasicAnnotationsStruct&& x) noexcept
304+
{
305+
m_basic_annotations_member = x.m_basic_annotations_member;
306+
}
307+
308+
/*!
309+
* @brief Copy assignment.
310+
* @param x Reference to the object BasicAnnotationsStruct that will be copied.
311+
*/
312+
eProsima_user_DllExport BasicAnnotationsStruct& operator =(
313+
const BasicAnnotationsStruct& x)
314+
{
315+
316+
m_basic_annotations_member = x.m_basic_annotations_member;
317+
318+
return *this;
319+
}
320+
321+
/*!
322+
* @brief Move assignment.
323+
* @param x Reference to the object BasicAnnotationsStruct that will be copied.
324+
*/
325+
eProsima_user_DllExport BasicAnnotationsStruct& operator =(
326+
BasicAnnotationsStruct&& x) noexcept
327+
{
328+
329+
m_basic_annotations_member = x.m_basic_annotations_member;
330+
return *this;
331+
}
332+
333+
/*!
334+
* @brief Comparison operator.
335+
* @param x BasicAnnotationsStruct object to compare.
336+
*/
337+
eProsima_user_DllExport bool operator ==(
338+
const BasicAnnotationsStruct& x) const
339+
{
340+
return (m_basic_annotations_member == x.m_basic_annotations_member);
341+
}
342+
343+
/*!
344+
* @brief Comparison operator.
345+
* @param x BasicAnnotationsStruct object to compare.
346+
*/
347+
eProsima_user_DllExport bool operator !=(
348+
const BasicAnnotationsStruct& x) const
349+
{
350+
return !(*this == x);
351+
}
352+
353+
/*!
354+
* @brief This function sets a value in member basic_annotations_member
355+
* @param _basic_annotations_member New value for member basic_annotations_member
356+
*/
357+
eProsima_user_DllExport void basic_annotations_member(
358+
int16_t _basic_annotations_member)
359+
{
360+
m_basic_annotations_member = _basic_annotations_member;
361+
}
362+
363+
/*!
364+
* @brief This function returns the value of member basic_annotations_member
365+
* @return Value of member basic_annotations_member
366+
*/
367+
eProsima_user_DllExport int16_t basic_annotations_member() const
368+
{
369+
return m_basic_annotations_member;
370+
}
371+
372+
/*!
373+
* @brief This function returns a reference to member basic_annotations_member
374+
* @return Reference to member basic_annotations_member
375+
*/
376+
eProsima_user_DllExport int16_t& basic_annotations_member()
377+
{
378+
return m_basic_annotations_member;
379+
}
380+
381+
382+
383+
private:
384+
385+
int16_t m_basic_annotations_member{0};
386+
263387
};
264388

265389
#endif // _FAST_DDS_GENERATED_ANNOTATIONS_HPP_

test/dds-types-test/annotationsCdrAux.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ constexpr uint32_t EmptyAnnotatedStruct_max_cdr_typesize {4UL};
4040
constexpr uint32_t EmptyAnnotatedStruct_max_key_cdr_typesize {0UL};
4141

4242

43+
constexpr uint32_t BasicAnnotationsStruct_max_cdr_typesize {6UL};
44+
constexpr uint32_t BasicAnnotationsStruct_max_key_cdr_typesize {0UL};
45+
4346

4447

4548

@@ -61,6 +64,11 @@ eProsima_user_DllExport void serialize_key(
6164
const EmptyAnnotatedStruct& data);
6265

6366

67+
eProsima_user_DllExport void serialize_key(
68+
eprosima::fastcdr::Cdr& scdr,
69+
const BasicAnnotationsStruct& data);
70+
71+
6472
} // namespace fastcdr
6573
} // namespace eprosima
6674

test/dds-types-test/annotationsCdrAux.ipp

+77
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,83 @@ void serialize_key(
163163

164164

165165

166+
template<>
167+
eProsima_user_DllExport size_t calculate_serialized_size(
168+
eprosima::fastcdr::CdrSizeCalculator& calculator,
169+
const BasicAnnotationsStruct& data,
170+
size_t& current_alignment)
171+
{
172+
static_cast<void>(data);
173+
174+
eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding();
175+
size_t calculated_size {calculator.begin_calculate_type_serialized_size(
176+
eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ?
177+
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
178+
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
179+
current_alignment)};
180+
181+
182+
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0),
183+
data.basic_annotations_member(), current_alignment);
184+
185+
186+
calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment);
187+
188+
return calculated_size;
189+
}
190+
191+
template<>
192+
eProsima_user_DllExport void serialize(
193+
eprosima::fastcdr::Cdr& scdr,
194+
const BasicAnnotationsStruct& data)
195+
{
196+
eprosima::fastcdr::Cdr::state current_state(scdr);
197+
scdr.begin_serialize_type(current_state,
198+
eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ?
199+
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
200+
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR);
201+
202+
scdr
203+
<< eprosima::fastcdr::MemberId(0) << data.basic_annotations_member()
204+
;
205+
scdr.end_serialize_type(current_state);
206+
}
207+
208+
template<>
209+
eProsima_user_DllExport void deserialize(
210+
eprosima::fastcdr::Cdr& cdr,
211+
BasicAnnotationsStruct& data)
212+
{
213+
cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ?
214+
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
215+
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
216+
[&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool
217+
{
218+
bool ret_value = true;
219+
switch (mid.id)
220+
{
221+
case 0:
222+
dcdr >> data.basic_annotations_member();
223+
break;
224+
225+
default:
226+
ret_value = false;
227+
break;
228+
}
229+
return ret_value;
230+
});
231+
}
232+
233+
void serialize_key(
234+
eprosima::fastcdr::Cdr& scdr,
235+
const BasicAnnotationsStruct& data)
236+
{
237+
static_cast<void>(scdr);
238+
static_cast<void>(data);
239+
}
240+
241+
242+
166243
} // namespace fastcdr
167244
} // namespace eprosima
168245

0 commit comments

Comments
 (0)