Skip to content

Commit

Permalink
Refactor key hash calculation according to DDS X-Types 1.3 (#381)
Browse files Browse the repository at this point in the history
* Refs #21385. New key hash calculation

Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>

* Refs #21385. Fix

Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>

* Refs #21385. Fix with inheritance

Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>

* Refs #21385. Apply suggestion

Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>

* Refs #21385. Update submodule

Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>

* Refs #21385. Update submodule

Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>

* Refs #21385. Fix tests

Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>

---------

Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>
  • Loading branch information
richiware authored Jul 29, 2024
1 parent a619e41 commit b3ae5dc
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ bool $struct.name$PubSubType::compute_key(
$struct.cScopedname$_max_key_cdr_typesize);

// Object that serializes the data.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1);
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv2);
ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2);
eprosima::fastcdr::serialize_key(ser, *p_type);
if (force_md5 || $struct.cScopedname$_max_key_cdr_typesize > 16)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,10 @@ TEST(TypeObjectTests, TestStructureTypeObject_$struct.cScopedname$)
$if (struct.inheritance)$
member_id = $struct.firstMember.id$;
$endif$
$struct.members: { member | $check_struct_member(member=member, parent=struct)$}; separator="\n"$
$struct.members: { member | $check_struct_member(member=member, parent=struct, pos=i0)$}; separator="\n"$
$endif$
ASSERT_EQ($struct.membersSize$, type_objects.minimal_type_object.minimal().struct_type().member_seq().size());
for (size_t i = 1; i < type_objects.minimal_type_object.minimal().struct_type().member_seq().size(); ++i)
{
EXPECT_LT(type_objects.minimal_type_object.minimal().struct_type().member_seq()[i-1].common().member_id(),
type_objects.minimal_type_object.minimal().struct_type().member_seq()[i].common().member_id());
}
ASSERT_EQ($struct.membersSize$, type_objects.complete_type_object.complete().struct_type().member_seq().size());
for (size_t i = 1; i < type_objects.complete_type_object.complete().struct_type().member_seq().size(); ++i)
{
EXPECT_LT(type_objects.complete_type_object.complete().struct_type().member_seq()[i-1].common().member_id(),
type_objects.complete_type_object.complete().struct_type().member_seq()[i].common().member_id());
}
}
>>

Expand Down Expand Up @@ -242,19 +232,9 @@ TEST(TypeObjectTests, TestUnionTypeObject_$union.name$)
}
$check_type_detail_annotations(object=union.discriminator, type="union_type().discriminator()")$
MemberId member_id = 1;
$union.members: { member | $check_union_member(member=member, parent=union)$}; separator="\n"$
$union.members: { member | $check_union_member(member=member, parent=union, pos=i0)$}; separator="\n"$
ASSERT_EQ($union.membersSize$, type_objects.minimal_type_object.minimal().union_type().member_seq().size());
for (size_t i = 1; i < type_objects.minimal_type_object.minimal().union_type().member_seq().size(); ++i)
{
EXPECT_LT(type_objects.minimal_type_object.minimal().union_type().member_seq()[i-1].common().member_id(),
type_objects.minimal_type_object.minimal().union_type().member_seq()[i].common().member_id());
}
ASSERT_EQ($union.membersSize$, type_objects.complete_type_object.complete().union_type().member_seq().size());
for (size_t i = 1; i < type_objects.complete_type_object.complete().union_type().member_seq().size(); ++i)
{
EXPECT_LT(type_objects.complete_type_object.complete().union_type().member_seq()[i-1].common().member_id(),
type_objects.complete_type_object.complete().union_type().member_seq()[i].common().member_id());
}
}
>>

Expand Down Expand Up @@ -803,19 +783,10 @@ $object.name$_expected_flags |= TypeFlagBits::IS_AUTOID_HASH;
$endif$
>>

check_struct_member(member, parent) ::= <<
check_struct_member(member, parent, pos) ::= <<
{
size_t pos = 0;
bool found = false;
for (; pos < type_objects.complete_type_object.complete().struct_type().member_seq().size(); ++pos)
{
if (strcmp("$member.name$", type_objects.complete_type_object.complete().struct_type().member_seq()[pos].detail().name()) == 0)
{
found = true;
break;
}
}
ASSERT_TRUE(found);
size_t pos = $pos$;
ASSERT_EQ(0, strcmp("$member.name$", type_objects.complete_type_object.complete().struct_type().member_seq()[pos].detail().name()));
NameHash member_name_hashed = TypeObjectUtils::name_hash("$member.name$");
$if(member.annotationId)$
member_id = $member.annotationIdValue$;
Expand Down Expand Up @@ -862,19 +833,10 @@ check_struct_member(member, parent) ::= <<
}
>>

check_union_member(member, parent) ::= <<
check_union_member(member, parent, pos) ::= <<
{
size_t pos = 0;
bool found = false;
for (; pos < type_objects.complete_type_object.complete().union_type().member_seq().size(); ++pos)
{
if (strcmp("$member.name$", type_objects.complete_type_object.complete().union_type().member_seq()[pos].detail().name()) == 0)
{
found = true;
break;
}
}
ASSERT_TRUE(found);
size_t pos = $pos$;
ASSERT_EQ(0, strcmp("$member.name$", type_objects.complete_type_object.complete().union_type().member_seq()[pos].detail().name()));
NameHash member_name_hashed = TypeObjectUtils::name_hash("$member.name$");
$if(member.annotationId)$
member_id = $member.annotationIdValue$;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,26 +151,55 @@ void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const $struct.scopedname$& data)
{
$if(!struct.inheritance)$
$if(!struct.scope.empty)$
using namespace $struct.scope$;
$endif$
$struct.membersById : { member |
$if(member.typecode.isStructType)$
extern void serialize_key(
Cdr& scdr,
const $member.typecode.scopedname$& data);
$endif$
}; separator="\n"$

static_cast<void>(scdr);
static_cast<void>(data);
$if(struct.hasKey)$
$struct.members : { member |
$struct.membersById : { member |
$if(member.annotationKey)$
$if(member.typecode.isStructType)$
$if(member.typecode.hasKey)$
serialize_key(scdr, data.$member.name$());
$else$
scdr << data.$member.name$();
$endif$
$else$
scdr << data.$member.name$();
$endif$
$if(member.typecode.isStructType)$
serialize_key(scdr, data.$member.name$());
$else$
scdr << data.$member.name$();
$endif$
$endif$
}; separator="\n"$
$else$
$struct.membersById : { member |
$if(member.annotationOptional)$
if (data.$member.name$().has_value())
{
$if(member.typecode.isStructType)$
serialize_key(scdr, $if(member.annotationExternal)$*$endif$data.$member.name$().value());
$else$
scdr << data.$member.name$().value();
$endif$
\}
$else$
$if(member.typecode.isStructType)$
serialize_key(scdr, $if(member.annotationExternal)$*$endif$data.$member.name$());
$else$
scdr << data.$member.name$();
$endif$
$endif$
}; separator="\n"$
$endif$
$else$
extern void serialize_key(
Cdr& scdr,
const $struct.inheritance.scopedname$& data);
serialize_key(scdr, static_cast<const $struct.inheritance.scopedname$&>(data));
$endif$
}

Expand Down
2 changes: 1 addition & 1 deletion thirdparty/dds-types-test
Submodule dds-types-test updated 1 files
+24 −0 IDL/key.idl
2 changes: 1 addition & 1 deletion thirdparty/idl-parser

0 comments on commit b3ae5dc

Please sign in to comment.