Java Code Examples for org.agrona.DirectBuffer#getByte()

The following examples show how to use org.agrona.DirectBuffer#getByte() . 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: LogInspector.java    From aeron with Apache License 2.0 6 votes vote down vote up
private static char[] bytesToAscii(final DirectBuffer buffer, final int offset, final int length)
{
    final char[] chars = new char[length];

    for (int i = 0; i < length; i++)
    {
        byte b = buffer.getByte(offset + i);

        if (b < 0)
        {
            b = 0;
        }

        chars[i] = (char)b;
    }

    return chars;
}
 
Example 2
Source File: BasicAuctionClusterClient.java    From aeron with Apache License 2.0 6 votes vote down vote up
public void onMessage(
    final long clusterSessionId,
    final long timestamp,
    final DirectBuffer buffer,
    final int offset,
    final int length,
    final Header header)
{
    final long correlationId = buffer.getLong(offset + CORRELATION_ID_OFFSET);
    final long customerId = buffer.getLong(offset + CUSTOMER_ID_OFFSET);
    final long currentPrice = buffer.getLong(offset + PRICE_OFFSET);
    final boolean bidSucceed = 0 != buffer.getByte(offset + BID_SUCCEEDED_OFFSET);

    lastBidSeen = currentPrice;

    printOutput(
        "SessionMessage(" + clusterSessionId + ", " + correlationId + "," +
        customerId + ", " + currentPrice + ", " + bidSucceed + ")");
}
 
Example 3
Source File: ILink3Offsets.java    From artio with Apache License 2.0 5 votes vote down vote up
public int possRetrans(final int templateId, final DirectBuffer buffer, final int messageOffset)
{
    final int possRetransOffset = possRetransOffset(templateId);
    if (possRetransOffset == MISSING_OFFSET)
    {
        return MISSING_OFFSET;
    }

    return (short)buffer.getByte(messageOffset + possRetransOffset) & 0xFF;
}
 
Example 4
Source File: LogInspector.java    From aeron with Apache License 2.0 5 votes vote down vote up
public static char[] bytesToHex(final DirectBuffer buffer, final int offset, final int length)
{
    final char[] chars = new char[length * 2];

    for (int i = 0; i < length; i++)
    {
        final int b = buffer.getByte(offset + i) & 0xFF;

        chars[i * 2] = HEX_ARRAY[b >>> 4];
        chars[i * 2 + 1] = HEX_ARRAY[b & 0x0F];
    }

    return chars;
}
 
Example 5
Source File: BufferAlignmentAgentTest.java    From agrona with Apache License 2.0 5 votes vote down vote up
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 6
Source File: LogInspector.java    From nd4j with Apache License 2.0 5 votes vote down vote up
private static char[] bytesToAscii(final DirectBuffer buffer, final int offset, final int length) {
    final char[] chars = new char[length];

    for (int i = 0; i < length; i++) {
        byte b = buffer.getByte(offset + i);

        if (b < 0) {
            b = 0;
        }

        chars[i] = (char) b;
    }

    return chars;
}
 
Example 7
Source File: LogInspector.java    From nd4j with Apache License 2.0 5 votes vote down vote up
public static char[] bytesToHex(final DirectBuffer buffer, final int offset, final int length) {
    final char[] chars = new char[length * 2];

    for (int i = 0; i < length; i++) {
        final int b = buffer.getByte(offset + i) & 0xFF;

        chars[i * 2] = HEX_ARRAY[b >>> 4];
        chars[i * 2 + 1] = HEX_ARRAY[b & 0x0F];
    }

    return chars;
}
 
Example 8
Source File: Types.java    From simple-binary-encoding with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}