/** * The constant value of the type if specified * * @return value of the constant for this type */ public PrimitiveValue constVal() throws IllegalArgumentException { if (presence() != CONSTANT) { throw new IllegalStateException("type is not of constant presence"); } return constValue; }
/** * The encodedLength (in octets) of the encoding as length of the primitiveType times its count. * * @return encodedLength of the encoding */ public int encodedLength() { if (presence() == CONSTANT) { return 0; } if (varLen) { return Token.VARIABLE_LENGTH; } return primitiveType.size() * length; }
@Test public void shouldHandleDecimal64CompositeType() throws Exception { final String testXmlString = "<types>" + "<composite name=\"decimal64\">" + " <type name=\"mantissa\" primitiveType=\"int64\"/>" + " <type name=\"exponent\" primitiveType=\"int8\" presence=\"constant\">-2</type>" + "</composite>" + "</types>"; final Map<String, Type> map = parseTestXmlWithMap("/types/composite", testXmlString); final CompositeType decimal64 = (CompositeType)map.get("decimal64"); assertThat(decimal64.name(), is("decimal64")); final EncodedDataType mantissa = (EncodedDataType)decimal64.getType("mantissa"); final EncodedDataType exponent = (EncodedDataType)decimal64.getType("exponent"); assertThat(mantissa.primitiveType(), is(PrimitiveType.INT64)); assertThat(exponent.primitiveType(), is(PrimitiveType.INT8)); assertThat(exponent.presence(), is(Presence.CONSTANT)); assertThat(exponent.constVal(), is(PrimitiveValue.parse("-2", PrimitiveType.INT8))); assertThat(decimal64.encodedLength(), is(8)); }
@Test public void shouldHandleDecimal32CompositeType() throws Exception { final String testXmlString = "<types>" + "<composite name=\"decimal32\">" + " <type name=\"mantissa\" primitiveType=\"int32\"/>" + " <type name=\"exponent\" primitiveType=\"int8\" presence=\"constant\">-2</type>" + "</composite>" + "</types>"; final Map<String, Type> map = parseTestXmlWithMap("/types/composite", testXmlString); final CompositeType decimal32 = (CompositeType)map.get("decimal32"); assertThat(decimal32.name(), is("decimal32")); final EncodedDataType mantissa = (EncodedDataType)decimal32.getType("mantissa"); final EncodedDataType exponent = (EncodedDataType)decimal32.getType("exponent"); assertThat(mantissa.primitiveType(), is(PrimitiveType.INT32)); assertThat(exponent.primitiveType(), is(PrimitiveType.INT8)); assertThat(exponent.presence(), is(Presence.CONSTANT)); assertThat(exponent.constVal(), is(PrimitiveValue.parse("-2", PrimitiveType.INT8))); assertThat(decimal32.encodedLength(), is(4)); }
.offset(offset); switch (type.presence())
/** * The constant value of the type if specified * * @return value of the constant for this type */ public PrimitiveValue constVal() throws IllegalArgumentException { if (presence() != CONSTANT) { throw new IllegalStateException("type is not of constant presence"); } return constValue; }
/** * The constant value of the type if specified * * @return value of the constant for this type */ public PrimitiveValue constVal() throws IllegalArgumentException { if (presence() != CONSTANT) { throw new IllegalStateException("type is not of constant presence"); } return constValue; }
/** * The constant value of the type if specified * * @return value of the constant for this type */ public PrimitiveValue constVal() throws IllegalArgumentException { if (presence() != Presence.CONSTANT) { throw new IllegalStateException("type is not of constant presence"); } return constValue; }
/** * The encodedLength (in octets) of the encoding as length of the primitiveType times its count. * * @return encodedLength of the encoding */ public int encodedLength() { if (presence() == CONSTANT) { return 0; } if (varLen) { return Token.VARIABLE_LENGTH; } return primitiveType.size() * length; }
/** * The encodedLength (in octets) of the encoding as length of the primitiveType times its count. * * @return encodedLength of the encoding */ public int encodedLength() { if (presence() == Presence.CONSTANT) { return 0; } if (varLen) { return Token.VARIABLE_LENGTH; } return primitiveType.size() * length; }
/** * The encodedLength (in octets) of the encoding as length of the primitiveType times its count. * * @return encodedLength of the encoding */ public int encodedLength() { if (presence() == CONSTANT) { return 0; } if (varLen) { return Token.VARIABLE_LENGTH; } return primitiveType.size() * length; }
.offset(offset); switch (type.presence())
.offset(offset); switch (type.presence())
switch (type.presence())