PrimitiveType( final String name, final int size, final double minValue, final double maxValue, final double nullValue) { this.name = name; this.size = size; this.minValue = new PrimitiveValue(minValue, size); this.maxValue = new PrimitiveValue(maxValue, size); this.nullValue = new PrimitiveValue(nullValue, size); }
public static void main(final String[] args) { for (int i = 0; i < 10; i++) { perfTestEncode(i); perfTestDecode(i); } }
public static void main(final String[] args) { for (int i = 0; i < 10; i++) { perfTestEncode(i); perfTestDecode(i); } }
private boolean isRepresentableByInt32(final Encoding encoding) { // These min and max values are the same in .NET return encoding.applicableMinValue().longValue() >= Integer.MIN_VALUE && encoding.applicableMaxValue().longValue() <= Integer.MAX_VALUE; }
private static int sizeOfPrimitive(final Encoding encoding) { return encoding.primitiveType().size(); }
@Test public void shouldHandleBasicFile() throws Exception { parse(TestUtil.getLocalResource("basic-schema.xml"), ParserOptions.DEFAULT); }
/** * The encodedLength (in octets) of the encodingType * * @return encodedLength of the encodingType */ public int encodedLength() { return encodingType.size(); }
/** * Return double value for this PrimitiveValue. * * @return value expressed as a double * @throws IllegalStateException if not a double value representation */ public double doubleValue() { if (representation != Representation.DOUBLE) { throw new IllegalStateException( "Not a double representation: representation=" + representation + " value=" + toString()); } return doubleValue; }
/** * The most applicable min value for the encoded type. * * @return most applicable min value for the encoded type. */ public PrimitiveValue applicableMinValue() { if (null != minValue) { return minValue; } return primitiveType.minValue(); }
/** * The most applicable max value for the encoded type. * * @return most applicable max value for the encoded type. */ public PrimitiveValue applicableMaxValue() { if (null != maxValue) { return maxValue; } return primitiveType.maxValue(); }
/** * The most applicable null value for the encoded type. * * @return most applicable null value for the encoded type. */ public PrimitiveValue applicableNullValue() { if (null != nullValue) { return nullValue; } return primitiveType.nullValue(); }
/** * The number of encoded primitives in this type. * * @return number of encoded primitives in this type. */ public int arrayLength() { if (null == encoding.primitiveType() || 0 == encodedLength) { return 0; } return encodedLength / encoding.primitiveType().size(); }
@Test public void shouldHandleEmbeddedLengthForData() throws Exception { parse(TestUtil.getLocalResource("embedded-length-and-count-schema.xml"), ParserOptions.DEFAULT); /* should parse correctly */ } }
/** * Return the Cpp98 formatted byte order encoding string to use for a given byte order and primitiveType * * @param byteOrder of the {@link uk.co.real_logic.sbe.ir.Token} * @param primitiveType of the {@link uk.co.real_logic.sbe.ir.Token} * @return the string formatted as the byte ordering encoding */ public static String formatByteOrderEncoding(final ByteOrder byteOrder, final PrimitiveType primitiveType) { switch (primitiveType.size()) { case 2: return "SBE_" + byteOrder + "_ENCODE_16"; case 4: return "SBE_" + byteOrder + "_ENCODE_32"; case 8: return "SBE_" + byteOrder + "_ENCODE_64"; default: return ""; } }
/** * Return byte array value for this PrimitiveValue. * * @return value expressed as a byte array * @throws IllegalStateException if not a byte array value representation */ public byte[] byteArrayValue() { if (representation != Representation.BYTE_ARRAY) { throw new IllegalStateException( "Not a byte[] representation: representation=" + representation + " value=" + toString()); } return byteArrayValue; }
PrimitiveType(final String name, final int size, final long minValue, final long maxValue, final long nullValue) { this.name = name; this.size = size; this.minValue = new PrimitiveValue(minValue, size); this.maxValue = new PrimitiveValue(maxValue, size); this.nullValue = new PrimitiveValue(nullValue, size); }
@Test public void shouldHandleBasicFileWithVariableLengthData() throws Exception { parse(TestUtil.getLocalResource("basic-variable-length-schema.xml"), ParserOptions.DEFAULT); }
/** * Return the Golang formatted byte order encoding string to use for a given byte order and primitiveType * * @param byteOrder of the {@link uk.co.real_logic.sbe.ir.Token} * @param primitiveType of the {@link uk.co.real_logic.sbe.ir.Token} * @return the string formatted as the byte ordering encoding */ public static String formatByteOrderEncoding(final ByteOrder byteOrder, final PrimitiveType primitiveType) { switch (primitiveType.size()) { case 2: return "binary.Write(buf, order, obj)"; case 4: return "binary.Write(buf, order, obj)"; case 8: return "binary.Write(buf, order, obj)"; default: return ""; } }
/** * Return long value for this PrimitiveValue * * @return value expressed as a long * @throws IllegalStateException if not a long value representation */ public long longValue() { if (representation != Representation.LONG) { throw new IllegalStateException( "Not a long representation: representation=" + representation + " value=" + toString()); } return longValue; }