Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,15 @@ private class FieldBuilder implements ElementBuilder<FieldType> {
private final String scenario;
private final BigInteger tag;
private final String type;
private final BigInteger lengthId;

public FieldBuilder(final BigInteger tag, final String name, final String scenario,
final String type) {
final String type, final BigInteger lengthId) {
this.tag = tag;
this.name = name;
this.scenario = scenario;
this.type = type;
this.lengthId = lengthId;
}

@Override
Expand Down Expand Up @@ -217,6 +219,7 @@ public FieldType build() {
fieldType.setId(baseFieldType.getId());
fieldType.setName(baseFieldType.getName());
fieldType.setType(baseFieldType.getType());
fieldType.setLengthId(baseFieldType.getLengthId());
fieldType.setScenario(scenario);
repositoryAdapter.addField(fieldType);
}
Expand Down Expand Up @@ -303,7 +306,7 @@ public GroupType build() {
if (groupType != null) {
FieldRefType numInGroupRef = groupType.getNumInGroup();
if (numInGroupRef != null) {
buildSteps.add(new FieldBuilder(numInGroupRef.getId(), null, DEFAULT_SCENARIO, "NumInGroup"));
buildSteps.add(new FieldBuilder(numInGroupRef.getId(), null, DEFAULT_SCENARIO, "NumInGroup", null));
}
repositoryAdapter.copyGroup(groupType);
} else {
Expand Down Expand Up @@ -489,7 +492,7 @@ private void copyReferencedMembers(final List<Object> members, int currentDepth,
FieldRefType numInGroupRef = group.getNumInGroup();
if (numInGroupRef != null) {
buildSteps.add(new FieldBuilder(numInGroupRef.getId(), null, numInGroupRef.getScenario(),
"NumInGroup"));
"NumInGroup", null));
if (currentDepth <= maxDepth) {
final List<Object> groupMembers = group.getComponentRefOrGroupRefOrFieldRef();
copyReferencedMembers(groupMembers, currentDepth + 1, maxDepth);
Expand Down Expand Up @@ -1437,6 +1440,9 @@ private void addField(final GraphContext graphContext, final Context keyContext)
case "type":
field.setType(p.getValue());
break;
case "lengthId":
field.setLengthId(new BigInteger(p.getValue()));
break;
case "values":
final String values = p.getValue();
if (values != null && !values.isEmpty()) {
Expand Down Expand Up @@ -1556,11 +1562,13 @@ private void addFieldAndType(final FieldType field) {
final String scenario = field.getScenario();
final UnionDataTypeT unionDatatype = field.getUnionDataType();
final String unionType = unionDatatype != null ? unionDatatype.value() : null;

final BigInteger lengthId = "data".equals(type) ? id.subtract(BigInteger.ONE) : null;
field.setLengthId(lengthId);

if (id == null) {
buildSteps.add(new FieldBuilder(BigInteger.ZERO, name, scenario, type));
buildSteps.add(new FieldBuilder(BigInteger.ZERO, name, scenario, type, null));
} else if (name == null || type == null) {
buildSteps.add(new FieldBuilder(id, name, scenario, type));
buildSteps.add(new FieldBuilder(id, name, scenario, type, lengthId));
} else {
buildSteps.add(new TypeBuilder(type, scenario));
repositoryAdapter.addField(field);
Expand Down Expand Up @@ -2233,15 +2241,15 @@ private FieldRefType populateFieldRef(final DetailTable.TableRow detail) {
if (fieldRefType.getId() != null) {
final FieldType fieldType = repositoryAdapter.findFieldByTag(fieldRefType.getId(), scenario);
if (fieldType == null) {
buildSteps.add(new FieldBuilder(fieldRefType.getId(), name, scenario, null));
buildSteps.add(new FieldBuilder(fieldRefType.getId(), name, scenario, null, null));
}
} else {
final FieldType fieldType = repositoryAdapter.findFieldByName(name, scenario);
if (fieldType != null) {
fieldRefType.setId(fieldType.getId());
} else {
fieldRefType.setId(BigInteger.ZERO);
buildSteps.add(new FieldBuilder(BigInteger.ZERO, name, scenario, null));
buildSteps.add(new FieldBuilder(BigInteger.ZERO, name, scenario, null, null));
buildSteps.add(new FieldRefBuilder(name, fieldRefType));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1271,4 +1271,23 @@ void userDefinedFields() throws Exception {
//System.out.println(errors);
assertTrue(errors.contains("Unknown type for field"));
}

@Test
void dataFieldLengthId() throws Exception {
String text =
"## Fields\n"
+ "\n"
+ "| Name | Tag | Type | Values |\n"
+ "|------------------|----:|--------------|--------------------------|\n"
+ "| CustomRawData | 10060 | data | |\n";

InputStream inputStream = new ByteArrayInputStream(text.getBytes());
RepositoryBuilder builder = RepositoryBuilder.instance(null , jsonOutputStream);
builder.appendInput(inputStream);
ByteArrayOutputStream xmlStream = new ByteArrayOutputStream(8096);
builder.write(xmlStream);
String xml = xmlStream.toString();
assertTrue(xml.contains("lengthId=\"10059\""));
builder.closeEventLogger();
}
}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<antlr.version>4.8-1</antlr.version>
<commons-cli.version>1.4</commons-cli.version>
<jackson.version>2.13.4.1</jackson.version>
<jackson.version>2.19.2</jackson.version>
<java.version>11</java.version>
<junit.version>5.9.1</junit.version>
<log4j.version>2.19.0</log4j.version>
Expand Down Expand Up @@ -198,4 +198,4 @@
</profile>
</profiles>

</project>
</project>