Skip to content

Commit

Permalink
Refs #18687. Fixes after rebase
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo González Moreno <[email protected]>
  • Loading branch information
richiware committed Jul 25, 2023
1 parent db43973 commit ff94ce9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public long maxSerializedSize(
long initial_alignment = current_alignment;
long reset_alignment = 0;
long union_max_size_serialized = 0;
com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind union_ext_kind = get_extensibility();

current_alignment = MemberedTypeCode.xcdr_extra_header_serialized_size(current_alignment, union_ext_kind);

current_alignment += ((TypeCode)getDiscriminator()).maxSerializedSize(current_alignment);

Expand All @@ -54,6 +57,8 @@ public long maxSerializedSize(
}
}

return union_max_size_serialized - initial_alignment;
current_alignment = MemberedTypeCode.xcdr_extra_endheader_serialized_size(union_max_size_serialized, union_ext_kind);

return current_alignment - initial_alignment;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ int $if(bitset.hasScope)$$bitset.scope$::$endif$compare$bitset.name$(
// ASSIGNMENT
// ========================================================================================
simply_member_assignment(ctx, typecode, name, optional) ::= <<
// $typecode.cppTypename$ - $typecode.kind$
$if(typecode.isType_7)$
$if(typecode.isType_10)$
$simply_member_assignment(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name)$
$elseif(typecode.isType_7)$
topic->$name$(static_cast<$typecode.cppTypename$>(idx%2==1));
$elseif(typecode.primitive)$
topic->$name$(static_cast<$typecode.cppTypename$>(idx));
Expand All @@ -195,8 +196,6 @@ topic->$name$() = std::to_string(idx).c_str();
$else$
topic->$name$() = std::to_string(idx);
$endif$
$elseif(typecode.isType_10)$
$simply_member_assignment(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name)$
$elseif(typecode.isSequenceType)$
printf("For testing map's key structs sequences aren't allowed.\n");
assert(false);
Expand All @@ -213,8 +212,9 @@ $endif$
>>

member_assignment(ctx, typecode, name, originName, optional) ::= <<
// $typecode.cppTypename$ - $typecode.kind$
$if(typecode.isType_7)$
$if(typecode.isType_10)$
$member_assignment(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName)$
$elseif(typecode.isType_7)$
topic->$name$(static_cast<$typecode.cppTypename$>(rand()%2==1));
$elseif(typecode.isWCharType)$
topic->$name$(L'W');
Expand All @@ -226,8 +226,6 @@ topic->$name$(std::wstring($typecode.maxsize$,'W'));
$else$
topic->$name$() = u8"AAAu8u8ñññöAA\u2602";
$endif$
$elseif(typecode.isType_10)$
$member_assignment(ctx=ctx, typecode=typecode.typedefContentTypeCode, name=name, originName=originName)$
$elseif(typecode.isSequenceType)$
$if(optional)$topic->$name$().reset(true);$endif$
$sequence_assigment(ctx=ctx, typecode=typecode, name=name, p=optional_suffix(p="()", optional=optional), loopvar=ctx.newLoopVarName)$
Expand All @@ -246,6 +244,8 @@ $endif$
array_member_assignment(ctx, typecode, name, originName, loopvar) ::= <<
$if(typecode.isType_7)$
topic->$name$ = static_cast<$typecode.cppTypename$>(rand()%2==1);
$elseif(typecode.isWCharType)$
topic->$name$ = static_cast<$typecode.cppTypename$>(L'W');
$elseif(typecode.primitive)$
topic->$name$ = static_cast<$typecode.cppTypename$>(rand());
$elseif(typecode.isType_d)$
Expand Down Expand Up @@ -278,6 +278,8 @@ topic->$name$$p$.value()[$currentvar$] = static_cast<$typecode.cppTypename$>(ran
$else$
topic->$name$$p$.push_back(static_cast<$typecode.cppTypename$>(rand()%2==1));
$endif$
$elseif(typecode.isWCharType)$
topic->$name$$p$.push_back(static_cast<$typecode.cppTypename$>(L'W'));
$elseif(typecode.primitive)$
$if(ctx.generateTypesC)$
topic->$name$$p$.value()[$currentvar$] = static_cast<$typecode.cppTypename$>(rand());
Expand Down Expand Up @@ -325,6 +327,9 @@ $map_member_assignment(ctx=ctx, keytypecode=keytypecode.typedefContentTypeCode,
$elseif(keytypecode.isType_7)$
$keytypecode.cppTypename$ var_map_Key$loopvar$ = static_cast<$keytypecode.cppTypename$>(rand()%2==1);
$map_member_value_assignment(ctx=ctx, valueTypeCode=valueTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$
$elseif(keytypecode.isWCharType)$
$keytypecode.cppTypename$ var_map_Key$loopvar$ = static_cast<$keytypecode.cppTypename$>(L'W');
$map_member_value_assignment(ctx=ctx, valueTypeCode=valueTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$
$elseif(keytypecode.primitive)$
$keytypecode.cppTypename$ var_map_Key$loopvar$ = static_cast<$keytypecode.cppTypename$>(rand());
$map_member_value_assignment(ctx=ctx, valueTypeCode=valueTypeCode, name=name, originName=originName, p=p, loopvar=loopvar)$
Expand Down Expand Up @@ -373,6 +378,8 @@ map_member_value_assignment(ctx, valueTypeCode, name, originName, p, loopvar) ::
// Value assignment
$if(valueTypeCode.isType_7)$
topic->$name$$p$[var_map_Key$loopvar$] = static_cast<$valueTypeCode.cppTypename$>(rand()%2==1);
$elseif(valueTypeCode.isWCharType)$
topic->$name$$p$[var_map_Key$loopvar$] = static_cast<$valueTypeCode.cppTypename$>(L'W');
$elseif(valueTypeCode.primitive)$
topic->$name$$p$[var_map_Key$loopvar$] = static_cast<$valueTypeCode.cppTypename$>(rand());
$elseif(valueTypeCode.isType_d)$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ $exports; separator="\n"$

>>

fwd_decl(ctx, parent, type) ::= <<>>

exception(ctx, parent, exception) ::= <<

$if(ctx.anyCdr)$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ $exports; separator="\n"$

>>

fwd_decl(ctx, parent, type) ::= <<>>

exception(ctx, parent, exception) ::= <<

$if(ctx.anyCdr)$
Expand Down Expand Up @@ -365,7 +367,7 @@ size_t calculate_serialized_size(
{
$union.identifiedMembers:{ member |
$if(member.value.printable)$
$member.value.labels:{ label |case $if(union.hasScope)$$union.scope$::$endif$$label$:}; separator="\n"$
$member.value.labels:{ label |case $label$:}; separator="\n"$
$if(member.value.default)$default:$endif$
current_alignment += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId($member.key$),
data.$member.value.name$(), current_alignment);
Expand Down Expand Up @@ -404,7 +406,7 @@ void serialize(
{
$union.identifiedMembers:{ member |
$if(member.value.printable)$
$member.value.labels:{ label |case $if(union.hasScope)$$union.scope$::$endif$$label$:}; separator="\n"$
$member.value.labels:{ label |case $label$:}; separator="\n"$
$if(member.value.default)$default:$endif$
scdr << eprosima::fastcdr::MemberId($member.key$) << data.$member.value.name$();
break;
Expand Down Expand Up @@ -441,7 +443,7 @@ void deserialize(
{
$union.identifiedMembers:{ member |
$if(member.value.printable)$
$member.value.labels:{ label |case $if(union.hasScope)$$union.scope$::$endif$$label$:}; separator="\n"$
$member.value.labels:{ label |case $label$:}; separator="\n"$
$if(member.value.default)$default:$endif$
// TODO Test on mutable the MemberId
dcdr \>> data.$member.value.name$();
Expand Down

0 comments on commit ff94ce9

Please sign in to comment.