Skip to content

Commit

Permalink
refactor(code-gen/go): fix length underflow issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Sep 26, 2024
1 parent cc14b9c commit 7f211a8
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,11 @@ func (m *_${type.name}) GetLengthInBits(ctx context.Context) uint16 {
if m.${optionalField.name?cap_first} != nil {
<#if optionalField.type.isSimpleTypeReference()>
<#assign simpleTypeReference = optionalField.type.asSimpleTypeReference().orElseThrow()>
lengthInBits += ${simpleTypeReference.sizeInBits}
<#assign bs=simpleTypeReference.sizeInBits>
lengthInBits += ${(bs<0)?then(0,bs)}
<#elseif helper.isEnumField(optionalField)>
lengthInBits += ${helper.getEnumBaseTypeReference(optionalField.type).sizeInBits}
<#assign bs=helper.getEnumBaseTypeReference(optionalField.type).sizeInBits>
lengthInBits += ${(bs<0)?then(0,bs)}
<#elseif optionalField.type.isComplexTypeReference()>
lengthInBits += m.${optionalField.name?cap_first}.GetLengthInBits(ctx)
<#else>
Expand Down

0 comments on commit 7f211a8

Please sign in to comment.