static PrimitiveValue get(final DirectBuffer buffer, final PrimitiveType type, final int length)
    {
        if (length == 0)
        {
            return null;
        }

        switch (type)
        {
            case CHAR:
                if (length == 1)
                {
                    return new PrimitiveValue(buffer.getByte(0), "US-ASCII");
                }
                else
                {
                    final byte[] array = new byte[length];
                    buffer.getBytes(0, array, 0, array.length);
                    return new PrimitiveValue(array, "US-ASCII", array.length);
                }

            case INT8:
                return new PrimitiveValue(buffer.getByte(0), 1);

            case INT16:
                return new PrimitiveValue(buffer.getShort(0, ByteOrder.LITTLE_ENDIAN), 2);

            case INT32:
                return new PrimitiveValue(buffer.getInt(0, ByteOrder.LITTLE_ENDIAN), 4);

            case INT64:
                return new PrimitiveValue(buffer.getLong(0, ByteOrder.LITTLE_ENDIAN), 8);

            case UINT8:
                return new PrimitiveValue((short)(buffer.getByte(0) & 0xFF), 1);

            case UINT16:
                return new PrimitiveValue(buffer.getShort(0, ByteOrder.LITTLE_ENDIAN) & 0xFFFF, 2);

            case UINT32:
                return new PrimitiveValue(buffer.getInt(0, ByteOrder.LITTLE_ENDIAN) & 0xFFFF_FFFFL, 4);

            case UINT64:
                return new PrimitiveValue(buffer.getLong(0, ByteOrder.LITTLE_ENDIAN), 8);

            case FLOAT:
                return new PrimitiveValue(buffer.getFloat(0, ByteOrder.LITTLE_ENDIAN), 4);

            case DOUBLE:
                return new PrimitiveValue(buffer.getDouble(0, ByteOrder.LITTLE_ENDIAN), 8);

            default:
                return null;
        }
    }
Utility functions for working with {@link Ir}.
sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/IrUtil.java