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

ReadBinary() public static method

Reads a binary value from a buffer.
public static ReadBinary ( System.ByteBuffer buffer, byte formatCode ) : byte[]
buffer System.ByteBuffer The buffer to read.
formatCode byte The format code of the value.
return byte[]
        public static byte[] ReadBinary(ByteBuffer buffer, byte formatCode)
        {
            if (formatCode == FormatCode.Null)
            {
                return null;
            }

            int count;
            if (formatCode == FormatCode.Binary8)
            {
                count = AmqpBitConverter.ReadUByte(buffer);
            }
            else if (formatCode == FormatCode.Binary32)
            {
                count = (int)AmqpBitConverter.ReadUInt(buffer);
            }
            else
            {
                throw InvalidFormatCodeException(formatCode, buffer.Offset);
            }

            buffer.Validate(false, count);
            byte[] value = new byte[count];
            Array.Copy(buffer.Buffer, buffer.Offset, value, 0, count);
            buffer.Complete(count);

            return value;
        }