Skip to content

Commit df31e55

Browse files
committed
[Java] Added the ability to capture presence and valueRef on a message field.
1 parent 4da15fc commit df31e55

File tree

5 files changed

+65
-13
lines changed

5 files changed

+65
-13
lines changed

sbe-benchmarks/src/main/resources/fix-message-samples.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@
289289
<field name="MdUpdateAction" id="279" type="MDUpdateAction"/>
290290
<field name="RptSeq" id="83" type="uint8"/>
291291
<field name="AggressorSide" id="5797" type="Side"/>
292-
<field name="MdEntryType" id="269" type="MDEntryType" presence="constant" valueRef="MdEntryType.TRADE"/>
292+
<field name="MdEntryType" id="269" type="MDEntryType" presence="constant" valueRef="MDEntryType.TRADE"/>
293293
</group>
294294
</sbe:message>
295295

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class Field
3535
private final int offset; // optional for field/data (not present for group)
3636
private final String semanticType; // optional for field/data (not present for group?)
3737
private final Presence presence; // optional, defaults to required
38+
private final String valueRef; // optional, defaults to null
3839
private final int blockLength; // optional for group (not present for field/data)
3940
private final CompositeType dimensionType; // required for group (not present for field/data)
4041
private final boolean variableLength; // true for data (false for field/group)
@@ -53,6 +54,7 @@ public Field(
5354
final int offset,
5455
final String semanticType,
5556
final Presence presence,
57+
final String valueRef,
5658
final int blockLength,
5759
final CompositeType dimensionType,
5860
final boolean variableLength,
@@ -67,6 +69,7 @@ public Field(
6769
this.offset = offset;
6870
this.semanticType = semanticType;
6971
this.presence = presence;
72+
this.valueRef = valueRef;
7073
this.blockLength = blockLength;
7174
this.dimensionType = dimensionType;
7275
this.variableLength = variableLength;
@@ -89,6 +92,35 @@ public void validate(final Node node)
8992
}
9093

9194
checkForValidName(node, name);
95+
96+
if (type instanceof EnumType && presence == Presence.CONSTANT)
97+
{
98+
if (null == valueRef)
99+
{
100+
handleError(node, "valueRef not set for constant Enum");
101+
}
102+
else
103+
{
104+
final int periodIndex = valueRef.indexOf('.');
105+
if (-1 == periodIndex)
106+
{
107+
handleError(node, "valueRef format not valid for constant Enum: " + valueRef);
108+
}
109+
110+
final String valueRefType = valueRef.substring(0, periodIndex);
111+
if (!valueRefType.equals(type.name()))
112+
{
113+
handleError(node, "valueRef Enum type not found: " + valueRefType);
114+
}
115+
116+
final String validValueName = valueRef.substring(periodIndex + 1);
117+
final EnumType enumType = (EnumType)type;
118+
if (null == enumType.getValidValue(validValueName))
119+
{
120+
handleError(node, "valueRef Valid value name not found: " + validValueName);
121+
}
122+
}
123+
}
92124
}
93125

94126
public void groupFields(final List<Field> fields)
@@ -151,6 +183,16 @@ public int computedBlockLength()
151183
return computedBlockLength;
152184
}
153185

186+
public Presence presence()
187+
{
188+
return presence;
189+
}
190+
191+
public String valueRef()
192+
{
193+
return valueRef;
194+
}
195+
154196
public String semanticType()
155197
{
156198
return semanticType;
@@ -191,6 +233,7 @@ public String toString()
191233
", offset=" + offset +
192234
", semanticType='" + semanticType + '\'' +
193235
", presence=" + presence +
236+
", valueRef='" + valueRef + '\'' +
194237
", blockLength=" + blockLength +
195238
", dimensionType=" + dimensionType +
196239
", variableLength=" + variableLength +
@@ -212,6 +255,7 @@ public static class Builder
212255
private int offset;
213256
private String semanticType;
214257
private Presence presence;
258+
private String refValue;
215259
private int blockLength;
216260
private CompositeType dimensionType;
217261
private boolean variableLength;
@@ -261,6 +305,12 @@ public Builder presence(final Presence presence)
261305
return this;
262306
}
263307

308+
public Builder valueRef(final String refValue)
309+
{
310+
this.refValue = refValue;
311+
return this;
312+
}
313+
264314
public Builder blockLength(final int blockLength)
265315
{
266316
this.blockLength = blockLength;
@@ -307,6 +357,7 @@ public Field build()
307357
offset,
308358
semanticType,
309359
presence,
360+
refValue,
310361
blockLength,
311362
dimensionType,
312363
variableLength,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ private Field parseField(final NodeList nodeList, final int nodeIndex)
251251
.offset(Integer.parseInt(getAttributeValue(node, "offset", "0")))
252252
.semanticType(getAttributeValueOrNull(node, "semanticType"))
253253
.presence(Presence.get(getAttributeValue(node, "presence", "required")))
254+
.valueRef(getAttributeValueOrNull(node, "valueRef"))
254255
.sinceVersion(Integer.parseInt(getAttributeValue(node, "sinceVersion", "0")))
255256
.epoch(getAttributeValue(node, "epoch", "unix"))
256257
.timeUnit(getAttributeValue(node, "timeUnit", "nanosecond"))

sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaGeneratorTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ private Class<?> compileCarEncoder() throws Exception
411411
final String className = "CarEncoder";
412412
final String fqClassName = ir.applicableNamespace() + "." + className;
413413

414-
System.out.println(fqClassName);
415414
final Class<?> clazz = compile(fqClassName);
416415
assertNotNull(clazz);
417416

sbe-tool/src/test/resources/code-generation-schema.xml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,20 @@
5656
<field name="vehicleCode" id="6" type="VehicleCode"/>
5757
<field name="extras" id="5" type="OptionalExtras"/>
5858
<field name="engine" id="7" type="Engine"/>
59-
<group name="fuelFigures" id="8" dimensionType="groupSizeEncoding">
60-
<field name="speed" id="9" type="uint16"/>
61-
<field name="mpg" id="10" type="float"/>
59+
<field name="commonModel" id="8" type="Model" presence="constant" valueRef="Model.C"/>
60+
<group name="fuelFigures" id="9" dimensionType="groupSizeEncoding">
61+
<field name="speed" id="10" type="uint16"/>
62+
<field name="mpg" id="11" type="float"/>
6263
</group>
63-
<group name="performanceFigures" id="11" dimensionType="groupSizeEncoding">
64-
<field name="octaneRating" id="12" type="uint8"/>
65-
<field name="observations" id="13" type="string20"/>
66-
<group name="acceleration" id="14" dimensionType="groupSizeEncoding">
67-
<field name="mph" id="15" type="uint16"/>
68-
<field name="seconds" id="16" type="float"/>
64+
<group name="performanceFigures" id="12" dimensionType="groupSizeEncoding">
65+
<field name="octaneRating" id="13" type="uint8"/>
66+
<field name="observations" id="14" type="string20"/>
67+
<group name="acceleration" id="15" dimensionType="groupSizeEncoding">
68+
<field name="mph" id="16" type="uint16"/>
69+
<field name="seconds" id="17" type="float"/>
6970
</group>
7071
</group>
71-
<data name="make" id="17" type="varDataEncoding"/>
72-
<data name="model" id="18" type="varDataEncoding"/>
72+
<data name="make" id="18" type="varDataEncoding"/>
73+
<data name="model" id="19" type="varDataEncoding"/>
7374
</message>
7475
</messageSchema>

0 commit comments

Comments
 (0)