Amqp.Types.Encoder.WriteBinary C# (CSharp) Method

WriteBinary() public static method

Writes a binary value to a buffer.
public static WriteBinary ( System.ByteBuffer buffer, byte value, bool smallEncoding ) : void
buffer System.ByteBuffer The buffer to write.
value byte The binary value.
smallEncoding bool if true, try using small encoding if possible.
return void
        public static void WriteBinary(ByteBuffer buffer, byte[] value, bool smallEncoding)
        {
            if (value == null)
            {
                AmqpBitConverter.WriteUByte(buffer, FormatCode.Null);
            }
            else if (smallEncoding && value.Length <= byte.MaxValue)
            {
                AmqpBitConverter.WriteUByte(buffer, FormatCode.Binary8);
                AmqpBitConverter.WriteUByte(buffer, (byte)value.Length);
                AmqpBitConverter.WriteBytes(buffer, value, 0, value.Length);
            }
            else
            {
                AmqpBitConverter.WriteUByte(buffer, FormatCode.Binary32);
                AmqpBitConverter.WriteUInt(buffer, (uint)value.Length);
                AmqpBitConverter.WriteBytes(buffer, value, 0, value.Length);
            }
        }