static int put(final MutableDirectBuffer buffer, final PrimitiveValue value, final PrimitiveType type)
    {
        if (value == null)
        {
            return 0;
        }

        switch (type)
        {
            case CHAR:
                if (value.size() == 1)
                {
                    if (value.representation() == PrimitiveValue.Representation.LONG)
                    {
                        buffer.putByte(0, (byte)value.longValue());
                    }
                    else
                    {
                        buffer.putByte(0, value.byteArrayValue()[0]);
                    }
                    return 1;
                }
                else
                {
                    buffer.putBytes(0, value.byteArrayValue(), 0, value.byteArrayValue().length);
                    return value.byteArrayValue().length;
                }

            case INT8:
                buffer.putByte(0, (byte)value.longValue());
                return 1;

            case INT16:
                buffer.putShort(0, (short)value.longValue(), ByteOrder.LITTLE_ENDIAN);
                return 2;

            case INT32:
                buffer.putInt(0, (int)value.longValue(), ByteOrder.LITTLE_ENDIAN);
                return 4;

            case INT64:
                buffer.putLong(0, value.longValue(), ByteOrder.LITTLE_ENDIAN);
                return 8;

            case UINT8:
                buffer.putByte(0, (byte)value.longValue());
                return 1;

            case UINT16:
                buffer.putShort(0, (short)value.longValue(), ByteOrder.LITTLE_ENDIAN);
                return 2;

            case UINT32:
                buffer.putInt(0, (int)value.longValue(), ByteOrder.LITTLE_ENDIAN);
                return 4;

            case UINT64:
                buffer.putLong(0, value.longValue(), ByteOrder.LITTLE_ENDIAN);
                return 8;

            case FLOAT:
                buffer.putFloat(0, (float)value.doubleValue(), ByteOrder.LITTLE_ENDIAN);
                return 4;

            case DOUBLE:
                buffer.putDouble(0, value.doubleValue(), ByteOrder.LITTLE_ENDIAN);
                return 8;

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