Skip to content

Commit bca8849

Browse files
committed
[Java] Carry down field sinceVersion into composite types to allow for more convenient OTF parsing. Issue #908.
1 parent 4ac18d0 commit bca8849

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

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

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -208,22 +208,19 @@ private void add(final CompositeType type, final int currOffset, final Field fie
208208
.semanticType(semanticTypeOf(type, field))
209209
.build();
210210

211+
final int version = null != field ? Math.max(field.sinceVersion(), type.sinceVersion()) : type.sinceVersion();
212+
211213
final Token.Builder builder = new Token.Builder()
212214
.signal(Signal.BEGIN_COMPOSITE)
213215
.name(type.name())
214216
.referencedName(type.referencedName())
215217
.offset(currOffset)
216218
.size(type.encodedLength())
217-
.version(type.sinceVersion())
219+
.version(version)
218220
.deprecated(type.deprecated())
219221
.description(type.description())
220222
.encoding(encoding);
221223

222-
if (null != field)
223-
{
224-
builder.version(Math.max(field.sinceVersion(), type.sinceVersion()));
225-
}
226-
227224
tokenList.add(builder.build());
228225

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

237234
if (elementType instanceof EncodedDataType)
238235
{
239-
add((EncodedDataType)elementType, offset);
236+
add((EncodedDataType)elementType,
237+
offset,
238+
null != field ? Math.max(field.sinceVersion(), type.sinceVersion()) : elementType.sinceVersion());
240239
}
241240
else if (elementType instanceof EnumType)
242241
{
243-
add((EnumType)elementType, offset, null);
242+
add((EnumType)elementType, offset, field);
244243
}
245244
else if (elementType instanceof SetType)
246245
{
247-
add((SetType)elementType, offset, null);
246+
add((SetType)elementType, offset, field);
248247
}
249248
else if (elementType instanceof CompositeType)
250249
{
251-
add((CompositeType)elementType, offset, null);
250+
add((CompositeType)elementType, offset, field);
252251
}
253252

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

268+
final int version = null != field ? Math.max(field.sinceVersion(), type.sinceVersion()) : type.sinceVersion();
269+
269270
final Token.Builder builder = new Token.Builder()
270271
.signal(Signal.BEGIN_ENUM)
271272
.name(type.name())
272273
.referencedName(type.referencedName())
273274
.size(encodingType.size())
274275
.offset(offset)
275-
.version(type.sinceVersion())
276+
.version(version)
276277
.deprecated(type.deprecated())
277278
.description(type.description())
278279
.encoding(encodingBuilder.build());
279280

280-
if (null != field)
281-
{
282-
builder.version(Math.max(field.sinceVersion(), type.sinceVersion()));
283-
}
284-
285281
tokenList.add(builder.build());
286282

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

321+
final int version = null != field ? Math.max(field.sinceVersion(), type.sinceVersion()) : type.sinceVersion();
322+
325323
final Token.Builder builder = new Token.Builder()
326324
.signal(Signal.BEGIN_SET)
327325
.name(type.name())
328326
.referencedName(type.referencedName())
329327
.size(encodingType.size())
330328
.offset(offset)
331-
.version(type.sinceVersion())
329+
.version(version)
332330
.deprecated(type.deprecated())
333331
.description(type.description())
334332
.encoding(encoding);
335333

336-
if (null != field)
337-
{
338-
builder.version(Math.max(field.sinceVersion(), type.sinceVersion()));
339-
}
340-
341334
tokenList.add(builder.build());
342335

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

372-
private void add(final EncodedDataType type, final int offset)
365+
private void add(final EncodedDataType type, final int offset, final int sinceVersion)
373366
{
374367
final Encoding.Builder encodingBuilder = new Encoding.Builder()
375368
.primitiveType(type.primitiveType())
@@ -382,7 +375,7 @@ private void add(final EncodedDataType type, final int offset)
382375
.referencedName(type.referencedName())
383376
.size(type.encodedLength())
384377
.description(type.description())
385-
.version(type.sinceVersion())
378+
.version(sinceVersion)
386379
.deprecated(type.deprecated())
387380
.offset(offset);
388381

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

422+
final int version = Math.max(field.sinceVersion(), type.sinceVersion());
423+
429424
final Token.Builder tokenBuilder = new Token.Builder()
430425
.signal(Signal.ENCODING)
431426
.name(type.name())
432427
.referencedName(type.referencedName())
433428
.size(type.encodedLength())
434429
.description(type.description())
435-
.version(type.sinceVersion())
430+
.version(version)
436431
.deprecated(type.deprecated())
437432
.offset(offset);
438433

439-
if (field.type() instanceof CompositeType)
440-
{
441-
tokenBuilder.version(Math.max(field.sinceVersion(), type.sinceVersion()));
442-
}
443-
444434
switch (field.presence())
445435
{
446436
case REQUIRED:

0 commit comments

Comments
 (0)