Java Code Examples for org.agrona.DirectBuffer#getShort()
The following examples show how to use
org.agrona.DirectBuffer#getShort() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleOpenFramingHeader.java From artio with Apache License 2.0 | 5 votes |
public static int readSofh(final DirectBuffer buffer, final int offset) { final int messageSize = readSofhMessageSize(buffer, offset); final short encodingType = buffer.getShort(offset + SOFH_ENCODING_OFFSET, ByteOrder.LITTLE_ENDIAN); if (encodingType != CME_ENCODING_TYPE) { throw new IllegalArgumentException( "Unsupported Encoding Type: " + encodingType + " should be " + CME_ENCODING_TYPE); } return messageSize; }
Example 2
Source File: BufferAlignmentAgentTest.java From agrona with Apache License 2.0 | 5 votes |
private void testAlignedReadMethods(final DirectBuffer buffer, final int offset) { buffer.getLong(offset + SIZE_OF_LONG); buffer.getLong(offset + SIZE_OF_LONG, BIG_ENDIAN); buffer.getDouble(offset + SIZE_OF_DOUBLE); buffer.getDouble(offset + SIZE_OF_DOUBLE, BIG_ENDIAN); buffer.getInt(offset + SIZE_OF_INT); buffer.getInt(offset + SIZE_OF_INT, BIG_ENDIAN); buffer.getFloat(offset + SIZE_OF_FLOAT); buffer.getFloat(offset + SIZE_OF_FLOAT, BIG_ENDIAN); buffer.getShort(offset + SIZE_OF_SHORT); buffer.getShort(offset + SIZE_OF_SHORT, BIG_ENDIAN); buffer.getChar(offset + SIZE_OF_CHAR); buffer.getChar(offset + SIZE_OF_CHAR, BIG_ENDIAN); buffer.getByte(offset + SIZE_OF_BYTE); buffer.getByte(offset + SIZE_OF_BYTE); buffer.getStringUtf8(offset + SIZE_OF_INT); buffer.getStringUtf8(offset + SIZE_OF_INT, BIG_ENDIAN); buffer.getStringAscii(offset + SIZE_OF_INT); buffer.getStringAscii(offset + SIZE_OF_INT, BIG_ENDIAN); // string size is not read for these method => no need for 4-bytes // alignment buffer.getStringUtf8(offset + SIZE_OF_BYTE, 7); buffer.getStringWithoutLengthUtf8(offset + SIZE_OF_BYTE, 7); buffer.getStringAscii(offset + SIZE_OF_BYTE, 7); buffer.getStringWithoutLengthAscii(offset + SIZE_OF_BYTE, 7); }
Example 3
Source File: Types.java From simple-binary-encoding with Apache License 2.0 | 5 votes |
/** * Get an integer value from a buffer at a given index for a {@link PrimitiveType}. * * @param buffer from which to read. * @param index at which he integer should be read. * @param type of the integer encoded in the buffer. * @param byteOrder of the integer in the buffer. * @return the value of the encoded integer. */ public static int getInt( final DirectBuffer buffer, final int index, final PrimitiveType type, final ByteOrder byteOrder) { switch (type) { case INT8: return buffer.getByte(index); case UINT8: return (short)(buffer.getByte(index) & 0xFF); case INT16: return buffer.getShort(index, byteOrder); case UINT16: return buffer.getShort(index, byteOrder) & 0xFFFF; case INT32: return buffer.getInt(index, byteOrder); case UINT32: final int value = buffer.getInt(index, byteOrder); if (value < 0) { throw new IllegalStateException( "UINT32 type should not be greater than Integer.MAX_VALUE: value=" + value); } return value; default: throw new IllegalArgumentException("Unsupported type: " + type); } }
Example 4
Source File: SimpleOpenFramingHeader.java From artio with Apache License 2.0 | 4 votes |
public static int readSofhMessageSize(final DirectBuffer buffer, final int offset) { return buffer.getShort(offset + SOFH_MSG_SIZE_OFFSET, ByteOrder.LITTLE_ENDIAN) & 0xFFFF; }