Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for annotations to set MemberId [20114] #274

Merged
merged 5 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.eprosima.fastdds.idl.parser.typecode;

import com.eprosima.idl.parser.typecode.Member;

public interface MemberedTypeCode extends TypeCode
{
static long xcdr_extra_header_serialized_size(
Expand Down Expand Up @@ -50,14 +52,15 @@ static long xcdr_extra_member_serialized_size(
long current_alignment,
com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind memberedtypecode_ext_kind,
boolean member_optional,
int member_size)
Member member)
{
long returned_alignment = current_alignment;
int member_size = member.getTypecode() instanceof PrimitiveTypeCode ? Integer.parseInt(((PrimitiveTypeCode)member.getTypecode()).getSize()) : 8;

if (com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind.MUTABLE.get_value() == memberedtypecode_ext_kind.get_value() ||
member_optional)
{
if (5 > member_size)
if (5 > member_size && 16384 /*2^14*/ >= member.get_id())
{
returned_alignment += 4 + TypeCode.cdr_alignment(returned_alignment, 4);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,8 @@ private long maxSerializedSize(
detect_recursive_ = true;
current_alignment = MemberedTypeCode.xcdr_extra_header_serialized_size(current_alignment, struct_ext_kind);

if (getInheritance() != null)
{
current_alignment += ((StructTypeCode)getInheritance()).maxSerializedSize(current_alignment, only_keys,
com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind.FINAL); // FINAL to avoid calculation
// of any XCDR header.
}

// TODO if only_key, get members sorted.
for (Member member : getMembers())
for (Member member : getAllMembers())
{
if (member.isAnnotationNonSerialized())
{
Expand Down Expand Up @@ -110,7 +103,7 @@ else if (!only_keys)
current_alignment = MemberedTypeCode.xcdr_extra_member_serialized_size(
current_alignment,
struct_ext_kind, member.isAnnotationOptional(),
member.getTypecode() instanceof PrimitiveTypeCode ? Integer.parseInt(((PrimitiveTypeCode)member.getTypecode()).getSize()) : 8);
member);
current_alignment += ((TypeCode)member.getTypecode()).maxSerializedSize(current_alignment);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ eProsima_user_DllExport size_t calculate_serialized_size(
current_alignment)};


$struct.allIdentifiedMembers : { member | $if(!member.value.annotationNonSerialized)$
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId($member.key$),
data.$member.value.name$(), current_alignment);
$struct.allMembers : { member | $if(!member.annotationNonSerialized)$
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId($if(struct.annotationMutable)$$member.id$$else$$member.index$$endif$),
data.$member.name$(), current_alignment);
$endif$}; separator="\n"$

calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment);
Expand All @@ -147,9 +147,9 @@ eProsima_user_DllExport void serialize(
$if(struct.annotationFinal)$eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2$elseif(struct.annotationAppendable)$eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2$elseif(struct.annotationMutable)$eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR2$endif$ :
$if(struct.annotationFinal || struct.annotationAppendable)$eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR$elseif(struct.annotationMutable)$eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR$endif$);

$if(struct.allIdentifiedMembers)$
scdr$struct.allIdentifiedMembers : { member | $if(!member.value.annotationNonSerialized)$
<< eprosima::fastcdr::MemberId($member.key$) << data.$member.value.name$()
$if(struct.allMembers)$
scdr$struct.allMembers : { member | $if(!member.annotationNonSerialized)$
<< eprosima::fastcdr::MemberId($if(struct.annotationMutable)$$member.id$$else$$member.index$$endif$) << data.$member.name$()
$endif$
}; separator=""$;
$else$
Expand All @@ -176,13 +176,13 @@ eProsima_user_DllExport void deserialize(
bool ret_value = true;
switch (mid.id)
{
$if(!struct.allIdentifiedMembers)$
$if(!struct.allMembers)$
static_cast<void>(dcdr);
$endif$
$struct.allIdentifiedMembers : { member |
case $member.key$:
$if(!member.value.annotationNonSerialized)$
dcdr \>> data.$member.value.name$();
$struct.allMembers : { member |
case $if(struct.annotationMutable)$$member.id$$else$$member.index$$endif$:
$if(!member.annotationNonSerialized)$
dcdr \>> data.$member.name$();
$endif$
break;
}; separator="\n"$
Expand Down Expand Up @@ -306,10 +306,10 @@ eProsima_user_DllExport size_t calculate_serialized_size(

switch (data._d())
{
$union.identifiedMembers:{ member | $if(member.value.printable)$$member.value.labels:{ label |case $label$:}; separator="\n"$
$if(member.value.default)$default:$endif$
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId($member.key$),
data.$member.value.name$(), current_alignment);
$union.membersDefaultAtEnd:{ member | $if(member.printable)$$member.labels:{ label |case $label$:}; separator="\n"$
$if(member.default)$default:$endif$
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId($if(union.annotationMutable)$$member.id$$else$$member.index$$endif$),
data.$member.name$(), current_alignment);
break;
$endif$
}; separator="\n"$
Expand Down Expand Up @@ -346,10 +346,10 @@ eProsima_user_DllExport void serialize(

switch (data._d())
{
$union.identifiedMembers:{ member | $if(member.value.printable)$
$member.value.labels:{ label |case $label$:}; separator="\n"$
$if(member.value.default)$default:$endif$
scdr << eprosima::fastcdr::MemberId($member.key$) << data.$member.value.name$();
$union.membersDefaultAtEnd:{ member | $if(member.printable)$
$member.labels:{ label |case $label$:}; separator="\n"$
$if(member.default)$default:$endif$
scdr << eprosima::fastcdr::MemberId($if(union.annotationMutable)$$member.id$$else$$member.index$$endif$) << data.$member.name$();
break;
$endif$
}; separator="\n"$
Expand Down Expand Up @@ -385,10 +385,14 @@ eProsima_user_DllExport void deserialize(
default:
switch (data._d())
{
$union.identifiedMembers:{ member | $if(member.value.printable)$
$member.value.labels:{ label |case $label$:}; separator="\n"$
$if(member.value.default)$default:$endif$
dcdr \>> data.$member.value.name$();
$union.membersDefaultAtEnd:{ member | $if(member.printable)$
$member.labels:{ label |case $label$:}; separator="\n"$
$if(member.default)$default:$endif$
if (mid != $if(union.annotationMutable || member.annotationOptional)$$member.id$$else$$member.index$$endif$)
{
throw BadParamException("Deserializing union member $member.name$ the MemberId doesn't match");
\}
dcdr \>> data.$member.name$();
break;
$endif$
}; separator="\n"$
Expand Down