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

WriteSymbol() public static method

Writes a symbol value to a buffer.
public static WriteSymbol ( System.ByteBuffer buffer, Amqp.Types.Symbol value, bool smallEncoding ) : void
buffer System.ByteBuffer The buffer to write.
value Amqp.Types.Symbol The symbol value.
smallEncoding bool if true, try using small encoding if possible.
return void
        public static void WriteSymbol(ByteBuffer buffer, Symbol value, bool smallEncoding)
        {
            if (value == null)
            {
                AmqpBitConverter.WriteUByte(buffer, FormatCode.Null);
            }
            else
            {
                byte[] data = Encoding.UTF8.GetBytes(value);
                if (smallEncoding && data.Length <= byte.MaxValue)
                {
                    AmqpBitConverter.WriteUByte(buffer, FormatCode.Symbol8);
                    AmqpBitConverter.WriteUByte(buffer, (byte)data.Length);
                    AmqpBitConverter.WriteBytes(buffer, data, 0, data.Length);
                }
                else
                {
                    AmqpBitConverter.WriteUByte(buffer, FormatCode.Symbol32);
                    AmqpBitConverter.WriteUInt(buffer, (uint)data.Length);
                    AmqpBitConverter.WriteBytes(buffer, data, 0, data.Length);
                }
            }
        }