예제 #1
0
        /// <summary>
        /// Reads a uuid (16-bytes) from the buffer and advance the buffer read cursor.
        /// </summary>
        /// <param name="buffer">The buffer to read from.</param>
        /// <returns></returns>
        public static Guid ReadUuid(ByteBuffer buffer)
        {
            buffer.ValidateRead(FixedWidth.Uuid);
            byte[] d = new byte[FixedWidth.Uuid];
            if (AmqpBitConverter.IsLittleEndian)
            {
                int pos = buffer.Offset;
                d[3] = buffer.Buffer[pos++];
                d[2] = buffer.Buffer[pos++];
                d[1] = buffer.Buffer[pos++];
                d[0] = buffer.Buffer[pos++];

                d[5] = buffer.Buffer[pos++];
                d[4] = buffer.Buffer[pos++];

                d[7] = buffer.Buffer[pos++];
                d[6] = buffer.Buffer[pos++];

                Array.Copy(buffer.Buffer, pos, d, 8, 8);
            }
            else
            {
                Array.Copy(buffer.Buffer, buffer.Offset, d, 0, FixedWidth.Uuid);
            }

            buffer.Complete(FixedWidth.Uuid);
            return(new Guid(d));
        }
예제 #2
0
        /// <summary>
        /// Reads a 32-bit signed integer and advance the buffer read cursor.
        /// </summary>
        /// <param name="buffer">The buffer to read from.</param>
        /// <returns></returns>
        public static int ReadInt(ByteBuffer buffer)
        {
            buffer.ValidateRead(FixedWidth.Int);
            int data = ReadInt(buffer.Buffer, buffer.Offset);

            buffer.Complete(FixedWidth.Int);
            return(data);
        }
예제 #3
0
        /// <summary>
        /// Reads a 16-bit signed integer and advance the buffer read cursor.
        /// </summary>
        /// <param name="buffer">The buffer to read from.</param>
        /// <returns></returns>
        public static short ReadShort(ByteBuffer buffer)
        {
            buffer.ValidateRead(FixedWidth.Short);
            short data = (short)((buffer.Buffer[buffer.Offset] << 8) | buffer.Buffer[buffer.Offset + 1]);

            buffer.Complete(FixedWidth.Short);
            return(data);
        }
예제 #4
0
        /// <summary>
        /// Reads a signed byte and advance the buffer read cursor.
        /// </summary>
        /// <param name="buffer">The buffer to read from.</param>
        /// <returns></returns>
        public static sbyte ReadByte(ByteBuffer buffer)
        {
            buffer.ValidateRead(FixedWidth.UByte);
            sbyte data = (sbyte)buffer.Buffer[buffer.Offset];

            buffer.Complete(FixedWidth.UByte);
            return(data);
        }
예제 #5
0
        /// <summary>
        /// Reads a 64-bit signed integer from the buffer and advance the buffer read cursor.
        /// </summary>
        /// <param name="buffer">The buffer to read from.</param>
        /// <returns></returns>
        public static long ReadLong(ByteBuffer buffer)
        {
            buffer.ValidateRead(FixedWidth.Long);
            long high = ReadInt(buffer.Buffer, buffer.Offset);
            long low  = (uint)ReadInt(buffer.Buffer, buffer.Offset + 4);
            long data = (high << 32) | low;

            buffer.Complete(FixedWidth.Long);
            return(data);
        }
예제 #6
0
 /// <summary>
 /// Reads bytes from one buffer into another.
 /// </summary>
 /// <param name="buffer">Source buffer.</param>
 /// <param name="data">Destination buffer</param>
 /// <param name="offset">The start position to write.</param>
 /// <param name="count">The number of bytes to read.</param>
 public static void ReadBytes(ByteBuffer buffer, byte[] data, int offset, int count)
 {
     buffer.ValidateRead(count);
     Array.Copy(buffer.Buffer, buffer.Offset, data, offset, count);
     buffer.Complete(count);
 }