@Test public void shouldCalculateGroupOffsetWithPaddingFromBlockLengthAndGroupBlockLength() throws Exception { final MessageSchema schema = parse(TestUtil.getLocalResource( "block-length-schema.xml"), ParserOptions.DEFAULT); final List<Field> fields = schema.getMessage(3).fields(); assertThat(valueOf(fields.get(0).computedOffset()), is(valueOf(0))); assertThat(valueOf(fields.get(0).type().encodedLength()), is(valueOf(8))); assertThat(valueOf(fields.get(1).computedOffset()), is(valueOf(64))); Assert.assertNull(fields.get(1).type()); assertThat(valueOf(fields.get(1).computedBlockLength()), is(valueOf(16))); final List<Field> groupFields = fields.get(1).groupFields(); assertThat(valueOf(groupFields.size()), is(valueOf(2))); assertThat(valueOf(groupFields.get(0).computedOffset()), is(valueOf(0))); assertThat(valueOf(groupFields.get(0).type().encodedLength()), is(valueOf(4))); assertThat(valueOf(groupFields.get(1).computedOffset()), is(valueOf(4))); assertThat(valueOf(groupFields.get(1).type().encodedLength()), is(valueOf(8))); }
@Test public void shouldCalculateGroupOffsetWithPaddingFromBlockLength() throws Exception { final MessageSchema schema = parse(TestUtil.getLocalResource( "block-length-schema.xml"), ParserOptions.DEFAULT); final List<Field> fields = schema.getMessage(2).fields(); assertThat(valueOf(fields.get(0).computedOffset()), is(valueOf(0))); assertThat(valueOf(fields.get(0).type().encodedLength()), is(valueOf(8))); assertThat(valueOf(fields.get(1).computedOffset()), is(valueOf(64))); Assert.assertNull(fields.get(1).type()); assertThat(valueOf(fields.get(1).computedBlockLength()), is(valueOf(12))); final List<Field> groupFields = fields.get(1).groupFields(); assertThat(valueOf(groupFields.size()), is(valueOf(2))); assertThat(valueOf(groupFields.get(0).computedOffset()), is(valueOf(0))); assertThat(valueOf(groupFields.get(0).type().encodedLength()), is(valueOf(4))); assertThat(valueOf(groupFields.get(1).computedOffset()), is(valueOf(4))); assertThat(valueOf(groupFields.get(1).type().encodedLength()), is(valueOf(8))); }
@Test public void shouldCalculateGroupOffsetWithNoPaddingFromBlockLength() throws Exception { final MessageSchema schema = parse(TestUtil.getLocalResource( "block-length-schema.xml"), ParserOptions.DEFAULT); final Message msg = schema.getMessage(1); assertThat(valueOf(msg.blockLength()), is(valueOf(8))); final List<Field> fields = msg.fields(); assertThat(valueOf(fields.get(0).computedOffset()), is(valueOf(0))); assertThat(valueOf(fields.get(0).type().encodedLength()), is(valueOf(8))); assertThat(valueOf(fields.get(1).computedOffset()), is(valueOf(8))); Assert.assertNull(fields.get(1).type()); final List<Field> groupFields = fields.get(1).groupFields(); assertThat(valueOf(groupFields.size()), is(valueOf(2))); assertThat(valueOf(groupFields.get(0).computedOffset()), is(valueOf(0))); assertThat(valueOf(groupFields.get(0).type().encodedLength()), is(valueOf(4))); assertThat(valueOf(groupFields.get(1).computedOffset()), is(valueOf(4))); assertThat(valueOf(groupFields.get(1).type().encodedLength()), is(valueOf(8))); }
@Test public void shouldHandleEmbeddedCountForGroup() throws Exception { final MessageSchema schema = parse( TestUtil.getLocalResource("embedded-length-and-count-schema.xml"), ParserOptions.DEFAULT); final List<Field> fields = schema.getMessage(1).fields(); assertThat(fields.get(1).name(), is("ListOrdGrp")); assertThat(valueOf(fields.get(1).id()), is(valueOf(73))); Assert.assertNotNull(fields.get(1).dimensionType()); final List<Field> groupFields = fields.get(1).groupFields(); Assert.assertNotNull(groupFields); }
private static int computeMessageRootBlockLength(final List<Field> fields) { int blockLength = 0; for (final Field field : fields) { if (field.groupFields() != null) { return blockLength; } else if (field.type() != null) { final int fieldLength = field.type().encodedLength(); if (Token.VARIABLE_LENGTH == fieldLength) { return blockLength; } if (field.presence() == Presence.CONSTANT) { blockLength = field.computedOffset(); } else { blockLength = field.computedOffset() + fieldLength; } } } return blockLength; }
field.groupFields(parseMembers(node)); // recursive call
@Test public void shouldParseSchemaSuccessfully() throws Exception { final MessageSchema schema = parse(TestUtil.getLocalResource( "group-with-data-schema.xml"), ParserOptions.DEFAULT); final List<Field> fields = schema.getMessage(1).fields(); final Field entriesGroup = fields.get(1); final CompositeType dimensionType = entriesGroup.dimensionType(); final List<Field> entriesFields = entriesGroup.groupFields(); assertThat(entriesGroup.name(), is("Entries")); assertThat(dimensionType.name(), is("groupSizeEncoding")); final Field varDataField = entriesFields.get(2); assertThat(varDataField.name(), is("varDataField")); assertTrue(varDataField.isVariableLength()); } }
if (null != field.groupFields()) final int groupBlockLength = computeAndValidateOffsets(node, field.groupFields(), 0);
addAllFields(field.groupFields()); addFieldSignal(field, Signal.END_GROUP);
private Field parseGroupField(final NodeList nodeList, final int nodeIndex) throws XPathExpressionException { final String dimensionTypeName = getAttributeValue(nodeList.item(nodeIndex), "dimensionType", "groupSizeEncoding"); Type dimensionType = typeByNameMap.get(dimensionTypeName); if (dimensionType == null) { handleError(nodeList.item(nodeIndex), "could not find dimensionType: " + dimensionTypeName); } else if (!(dimensionType instanceof CompositeType)) { handleError(nodeList.item(nodeIndex), "dimensionType should be a composite type: " + dimensionTypeName); dimensionType = null; } else { ((CompositeType)dimensionType).checkForWellFormedGroupSizeEncoding(nodeList.item(nodeIndex)); } final Field field = new Field.Builder() .name(getAttributeValue(nodeList.item(nodeIndex), "name")) .description(getAttributeValueOrNull(nodeList.item(nodeIndex), "description")) .id(Integer.parseInt(getAttributeValue(nodeList.item(nodeIndex), "id"))) .blockLength(Integer.parseInt(getAttributeValue(nodeList.item(nodeIndex), "blockLength", "0"))) .sinceVersion(Integer.parseInt(getAttributeValue(nodeList.item(nodeIndex), "sinceVersion", "0"))) .dimensionType((CompositeType)dimensionType) .build(); XmlSchemaParser.checkForValidName(nodeList.item(nodeIndex), field.name()); field.groupFields(parseFieldsAndGroups(nodeList.item(nodeIndex))); // recursive call return field; }
private int computeMessageRootBlockLength() { int blockLength = 0; for (final Field field : fieldList) { if (field.groupFields() != null) { return blockLength; } else if (field.type() != null) { final int fieldLength = field.type().encodedLength(); if (Token.VARIABLE_LENGTH == fieldLength) { return blockLength; } blockLength = field.computedOffset() + fieldLength; } } return blockLength; }
private static int computeMessageRootBlockLength(final List<Field> fields) { int blockLength = 0; for (final Field field : fields) { if (field.groupFields() != null) { return blockLength; } else if (field.type() != null) { final int fieldLength = field.type().encodedLength(); if (Token.VARIABLE_LENGTH == fieldLength) { return blockLength; } if (field.presence() == Presence.CONSTANT) { blockLength = field.computedOffset(); } else { blockLength = field.computedOffset() + fieldLength; } } } return blockLength; }
private static int computeMessageRootBlockLength(final List<Field> fields) { int blockLength = 0; for (final Field field : fields) { if (field.groupFields() != null) { return blockLength; } else if (field.type() != null) { final int fieldLength = field.type().encodedLength(); if (Token.VARIABLE_LENGTH == fieldLength) { return blockLength; } if (field.presence() == Presence.CONSTANT) { blockLength = field.computedOffset(); } else { blockLength = field.computedOffset() + fieldLength; } } } return blockLength; }
field.groupFields(parseMembers(node)); // recursive call
field.groupFields(parseMembers(node)); // recursive call
if (null != field.groupFields()) final int groupBlockLength = computeAndValidateOffsets(node, field.groupFields(), 0);
if (null != field.groupFields()) final int groupBlockLength = computeAndValidateOffsets(node, field.groupFields(), 0);
addAllFields(field.groupFields()); addFieldSignal(field, Signal.END_GROUP);
addAllFields(field.groupFields()); addFieldSignal(field, Signal.END_GROUP);
addAllFields(field.groupFields()); addFieldSignal(field, Signal.END_GROUP);