/** * The encodedLength (in octets) of the list of EncodedDataTypes * * @return encodedLength of the compositeType */ public int encodedLength() { int offset = 0; for (final EncodedDataType t : containedTypeList) { if (t.isVariableLength()) { return Token.VARIABLE_LENGTH; } if (t.offsetAttribute() != -1) { offset = t.offsetAttribute(); } offset += t.encodedLength(); } return offset; }
/** * Check the composite for any specified offsets and validate they are correctly specified. * * @param node of the XML for this composite */ public void checkForValidOffsets(final Node node) { int offset = 0; for (final EncodedDataType edt : containedTypeList) { final int offsetAttribute = edt.offsetAttribute(); if (-1 != offsetAttribute) { if (offsetAttribute < offset) { XmlSchemaParser.handleError( node, String.format("composite element \"%s\" has incorrect offset specified", edt.name())); } offset = offsetAttribute; } offset += edt.encodedLength(); } } }
private void add(final CompositeType type, final int currOffset, final Field field) { final Token.Builder builder = new Token.Builder() .signal(Signal.BEGIN_COMPOSITE) .name(type.name()) .offset(currOffset) .size(type.encodedLength()) .encoding(new Encoding.Builder() .semanticType(semanticTypeOf(type, field)) .build()); if (field != null) { builder.version(field.sinceVersion()); } tokenList.add(builder.build()); int offset = 0; for (final EncodedDataType edt : type.getTypeList()) { if (edt.offsetAttribute() != -1) { offset = edt.offsetAttribute(); } add(edt, offset, field); offset += edt.encodedLength(); } tokenList.add(builder.signal(Signal.END_COMPOSITE).build()); }