Skip to content

Commit a699b4c

Browse files
committed
[Java] Factor in constant fields when computing block length. Issue #528.
1 parent e4641f1 commit a699b4c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/EnumType.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ public PrimitiveType encodingType()
168168
*/
169169
public int encodedLength()
170170
{
171+
if (presence() == Presence.CONSTANT)
172+
{
173+
return 0;
174+
}
175+
171176
return encodingType.size();
172177
}
173178

sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/Message.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,14 @@ else if (field.type() != null)
425425
return blockLength;
426426
}
427427

428-
blockLength = field.computedOffset() + fieldLength;
428+
if (field.presence() == Presence.CONSTANT)
429+
{
430+
blockLength = field.computedOffset();
431+
}
432+
else
433+
{
434+
blockLength = field.computedOffset() + fieldLength;
435+
}
429436
}
430437
}
431438

@@ -440,7 +447,7 @@ private static void validateBlockLength(
440447
handleError(
441448
node,
442449
"specified blockLength provides insufficient space " +
443-
computedBlockLength + " > " + specifiedBlockLength);
450+
computedBlockLength + " > " + specifiedBlockLength);
444451
}
445452
}
446453
}

0 commit comments

Comments
 (0)