Skip to content

Commit

Permalink
Captured types in IR should be for the minimum version used in a sche…
Browse files Browse the repository at this point in the history
…ma. Issue #967.
  • Loading branch information
mjpt777 committed Jan 18, 2024
1 parent a43b4ae commit b8ac926
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/Ir.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,14 @@ private int captureType(
while (endSignal != token.signal() || !name.equals(token.name()));

updateComponentTokenCounts(typeTokens);
typesByNameMap.put(null == referencedName ? name : referencedName, typeTokens);

final String typeName = null == referencedName ? name : referencedName;
final List<Token> existingTypeTokens = typesByNameMap.get(typeName);

if (null == existingTypeTokens || existingTypeTokens.get(0).version() > typeTokens.get(0).version())
{
typesByNameMap.put(typeName, typeTokens);
}

return i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
package uk.co.real_logic.sbe.ir;

import org.junit.jupiter.api.Test;
import uk.co.real_logic.sbe.xml.IrGenerator;
import uk.co.real_logic.sbe.xml.MessageSchema;
import uk.co.real_logic.sbe.xml.ParserOptions;

import java.io.InputStream;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static uk.co.real_logic.sbe.Tests.getLocalResource;
Expand All @@ -43,4 +48,18 @@ void shouldErrorOnTypeWithGreaterSinceVersion() throws Exception

fail("expected IllegalStateException");
}

@Test
void shouldApplySinceVersionOnComposites() throws Exception
{
try (InputStream in = getLocalResource("issue967.xml"))
{
final MessageSchema schema = parse(in, ParserOptions.DEFAULT);
final IrGenerator irg = new IrGenerator();
final Ir ir = irg.generate(schema);

final List<Token> priceNull9Tokens = ir.getType("PRICENULL9");
assertThat(priceNull9Tokens.get(0).version(), lessThan(13));
}
}
}
25 changes: 25 additions & 0 deletions sbe-tool/src/test/resources/issue967.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe"
package="issue967"
id="1"
version="13"
semanticVersion="1.0"
description="Example null enum"
byteOrder="littleEndian">
<types>
<composite name="messageHeader" description="Message identifiers and length of message root">
<type name="blockLength" primitiveType="uint16"/>
<type name="templateId" primitiveType="uint16"/>
<type name="schemaId" primitiveType="uint16"/>
<type name="version" primitiveType="uint16"/>
</composite>
<composite name="PRICENULL9" description="Optional Price with constant exponent -9" sinceVersion="9">
<type name="mantissa" description="mantissa" presence="optional" nullValue="9223372036854775807" primitiveType="int64"/>
<type name="exponent" description="exponent" presence="constant" primitiveType="int8">-9</type>
</composite>
</types>
<sbe:message name="MDInstrumentDefinitionFX63" id="63" description="MDInstrumentDefinitionFX" blockLength="337" semanticType="d" sinceVersion="12">
<field name="AltMinPriceIncrement" id="37739" type="PRICENULL9" description="New sub-tick which is only available for order entry when certain conditions are met, tick value which corresponds to the Alt Min Quote Life" offset="309" sinceVersion="12" semanticType="Price"/>
<field name="AltPriceIncrementConstraint" id="37742" type="PRICENULL9" description="Minimum price offset better than the best Standard Tick order for an order to be allowed into the market" offset="321" sinceVersion="13" semanticType="Price"/>
</sbe:message>
</sbe:messageSchema>

0 comments on commit b8ac926

Please sign in to comment.