Skip to content

Commit

Permalink
[Java] Carry down field sinceVersion into composite types to allow fo…
Browse files Browse the repository at this point in the history
…r more convenient OTF parsing. Issue #908.
  • Loading branch information
mjpt777 committed Jul 26, 2022
1 parent 4ac18d0 commit bca8849
Showing 1 changed file with 20 additions and 30 deletions.
50 changes: 20 additions & 30 deletions sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/IrGenerator.java
Expand Up @@ -208,22 +208,19 @@ private void add(final CompositeType type, final int currOffset, final Field fie
.semanticType(semanticTypeOf(type, field))
.build();

final int version = null != field ? Math.max(field.sinceVersion(), type.sinceVersion()) : type.sinceVersion();

final Token.Builder builder = new Token.Builder()
.signal(Signal.BEGIN_COMPOSITE)
.name(type.name())
.referencedName(type.referencedName())
.offset(currOffset)
.size(type.encodedLength())
.version(type.sinceVersion())
.version(version)
.deprecated(type.deprecated())
.description(type.description())
.encoding(encoding);

if (null != field)
{
builder.version(Math.max(field.sinceVersion(), type.sinceVersion()));
}

tokenList.add(builder.build());

int offset = 0;
Expand All @@ -236,19 +233,21 @@ private void add(final CompositeType type, final int currOffset, final Field fie

if (elementType instanceof EncodedDataType)
{
add((EncodedDataType)elementType, offset);
add((EncodedDataType)elementType,
offset,
null != field ? Math.max(field.sinceVersion(), type.sinceVersion()) : elementType.sinceVersion());
}
else if (elementType instanceof EnumType)
{
add((EnumType)elementType, offset, null);
add((EnumType)elementType, offset, field);
}
else if (elementType instanceof SetType)
{
add((SetType)elementType, offset, null);
add((SetType)elementType, offset, field);
}
else if (elementType instanceof CompositeType)
{
add((CompositeType)elementType, offset, null);
add((CompositeType)elementType, offset, field);
}

offset += elementType.encodedLength();
Expand All @@ -266,22 +265,19 @@ private void add(final EnumType type, final int offset, final Field field)
.nullValue(type.nullValue())
.byteOrder(schema.byteOrder());

final int version = null != field ? Math.max(field.sinceVersion(), type.sinceVersion()) : type.sinceVersion();

final Token.Builder builder = new Token.Builder()
.signal(Signal.BEGIN_ENUM)
.name(type.name())
.referencedName(type.referencedName())
.size(encodingType.size())
.offset(offset)
.version(type.sinceVersion())
.version(version)
.deprecated(type.deprecated())
.description(type.description())
.encoding(encodingBuilder.build());

if (null != field)
{
builder.version(Math.max(field.sinceVersion(), type.sinceVersion()));
}

tokenList.add(builder.build());

for (final EnumType.ValidValue validValue : type.validValues())
Expand Down Expand Up @@ -322,22 +318,19 @@ private void add(final SetType type, final int offset, final Field field)
.primitiveType(encodingType)
.build();

final int version = null != field ? Math.max(field.sinceVersion(), type.sinceVersion()) : type.sinceVersion();

final Token.Builder builder = new Token.Builder()
.signal(Signal.BEGIN_SET)
.name(type.name())
.referencedName(type.referencedName())
.size(encodingType.size())
.offset(offset)
.version(type.sinceVersion())
.version(version)
.deprecated(type.deprecated())
.description(type.description())
.encoding(encoding);

if (null != field)
{
builder.version(Math.max(field.sinceVersion(), type.sinceVersion()));
}

tokenList.add(builder.build());

for (final SetType.Choice choice : type.choices())
Expand Down Expand Up @@ -369,7 +362,7 @@ private void add(final SetType.Choice value, final PrimitiveType encodingType)
tokenList.add(builder.build());
}

private void add(final EncodedDataType type, final int offset)
private void add(final EncodedDataType type, final int offset, final int sinceVersion)
{
final Encoding.Builder encodingBuilder = new Encoding.Builder()
.primitiveType(type.primitiveType())
Expand All @@ -382,7 +375,7 @@ private void add(final EncodedDataType type, final int offset)
.referencedName(type.referencedName())
.size(type.encodedLength())
.description(type.description())
.version(type.sinceVersion())
.version(sinceVersion)
.deprecated(type.deprecated())
.offset(offset);

Expand Down Expand Up @@ -426,21 +419,18 @@ private void add(final EncodedDataType type, final int offset, final Field field
.timeUnit(field.timeUnit())
.epoch(field.epoch());

final int version = Math.max(field.sinceVersion(), type.sinceVersion());

final Token.Builder tokenBuilder = new Token.Builder()
.signal(Signal.ENCODING)
.name(type.name())
.referencedName(type.referencedName())
.size(type.encodedLength())
.description(type.description())
.version(type.sinceVersion())
.version(version)
.deprecated(type.deprecated())
.offset(offset);

if (field.type() instanceof CompositeType)
{
tokenBuilder.version(Math.max(field.sinceVersion(), type.sinceVersion()));
}

switch (field.presence())
{
case REQUIRED:
Expand Down

0 comments on commit bca8849

Please sign in to comment.