Validate() public method

Verifies that if the buffer has enough bytes for read or enough room for write and grow the buffer if needed.
public Validate ( bool write, int dataSize ) : void
write bool Operation to verify. True for write and false for read.
dataSize int The size to read or write.
return void
Beispiel #1
0
        /// <summary>
        /// Writes a uuid (16-bytes) into the buffer and advance the buffer write cursor.
        /// </summary>
        /// <param name="buffer">The buffer to write.</param>
        /// <param name="data">The data to write.</param>
        public static void WriteUuid(ByteBuffer buffer, Guid data)
        {
            buffer.Validate(true, FixedWidth.Uuid);
            byte[] p   = data.ToByteArray();
            int    pos = buffer.WritePos;

            if (AmqpBitConverter.IsLittleEndian)
            {
                buffer.Buffer[pos++] = p[3];
                buffer.Buffer[pos++] = p[2];
                buffer.Buffer[pos++] = p[1];
                buffer.Buffer[pos++] = p[0];

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

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

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

            buffer.Append(FixedWidth.Uuid);
        }
 /// <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.Validate(false, FixedWidth.UByte);
     sbyte data = (sbyte)buffer.Buffer[buffer.Offset];
     buffer.Complete(FixedWidth.UByte);
     return data;
 }
Beispiel #3
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.Validate(false, 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));
        }
Beispiel #4
0
 /// <summary>
 /// Writes a 16-bit signed integer into the buffer and advance the buffer write cursor.
 /// </summary>
 /// <param name="buffer">The buffer to write.</param>
 /// <param name="data">The data to write.</param>
 public static void WriteShort(ByteBuffer buffer, short data)
 {
     buffer.Validate(true, FixedWidth.Short);
     buffer.Buffer[buffer.WritePos]     = (byte)(data >> 8);
     buffer.Buffer[buffer.WritePos + 1] = (byte)data;
     buffer.Append(FixedWidth.Short);
 }
        public static short ReadShort(ByteBuffer buffer)
        {
            buffer.Validate(false, FixedWidth.Short);
            short data = (short)((buffer.Buffer[buffer.Offset] << 8) | buffer.Buffer[buffer.Offset + 1]);

            buffer.Complete(FixedWidth.Short);
            return(data);
        }
        public static sbyte ReadByte(ByteBuffer buffer)
        {
            buffer.Validate(false, FixedWidth.UByte);
            sbyte data = (sbyte)buffer.Buffer[buffer.Offset];

            buffer.Complete(FixedWidth.UByte);
            return(data);
        }
        public static int ReadInt(ByteBuffer buffer)
        {
            buffer.Validate(false, FixedWidth.Int);
            int data = ReadInt(buffer.Buffer, buffer.Offset);

            buffer.Complete(FixedWidth.Int);
            return(data);
        }
        public static long ReadLong(ByteBuffer buffer)
        {
            buffer.Validate(false, 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);
        }
 public static void WriteBytes(ByteBuffer buffer, byte[] data, int offset, int count)
 {
     buffer.Validate(true, count);
     Array.Copy(data, offset, buffer.Buffer, buffer.WritePos, count);
     buffer.Append(count);
 }
 public static void WriteInt(ByteBuffer buffer, int data)
 {
     buffer.Validate(true, FixedWidth.Int);
     WriteInt(buffer.Buffer, buffer.WritePos, data);
     buffer.Append(FixedWidth.Int);
 }
 public static void WriteByte(ByteBuffer buffer, sbyte data)
 {
     buffer.Validate(true, FixedWidth.Byte);
     buffer.Buffer[buffer.WritePos] = (byte)data;
     buffer.Append(FixedWidth.Byte);
 }
 public static void ReadBytes(ByteBuffer buffer, byte[] data, int offset, int count)
 {
     buffer.Validate(false, count);
     Array.Copy(buffer.Buffer, buffer.Offset, data, offset, count);
     buffer.Complete(count);
 }
 /// <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.Validate(false, FixedWidth.Int);
     int data = ReadInt(buffer.Buffer, buffer.Offset);
     buffer.Complete(FixedWidth.Int);
     return data;
 }
 /// <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.Validate(false, FixedWidth.Short);
     short data = (short)((buffer.Buffer[buffer.Offset] << 8) | buffer.Buffer[buffer.Offset + 1]);
     buffer.Complete(FixedWidth.Short);
     return data;
 }
        /// <summary>
        /// Writes a uuid (16-bytes) into the buffer and advance the buffer write cursor.
        /// </summary>
        /// <param name="buffer">The buffer to write.</param>
        /// <param name="data">The data to write.</param>
        public static void WriteUuid(ByteBuffer buffer, Guid data)
        {
            buffer.Validate(true, FixedWidth.Uuid);
            byte[] p = data.ToByteArray();
            int pos = buffer.WritePos;

            if (AmqpBitConverter.IsLittleEndian)
            {
                buffer.Buffer[pos++] = p[3];
                buffer.Buffer[pos++] = p[2];
                buffer.Buffer[pos++] = p[1];
                buffer.Buffer[pos++] = p[0];

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

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

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

            buffer.Append(FixedWidth.Uuid);
        }
 /// <summary>
 /// Writes a 16-bit signed integer into the buffer and advance the buffer write cursor.
 /// </summary>
 /// <param name="buffer">The buffer to write.</param>
 /// <param name="data">The data to write.</param>
 public static void WriteShort(ByteBuffer buffer, short data)
 {
     buffer.Validate(true, FixedWidth.Short);
     buffer.Buffer[buffer.WritePos] = (byte)(data >> 8);
     buffer.Buffer[buffer.WritePos + 1] = (byte)data;
     buffer.Append(FixedWidth.Short);
 }
 /// <summary>
 /// Writes a 32-bit signed integer into the buffer and advance the buffer write cursor.
 /// </summary>
 /// <param name="buffer">The buffer to write.</param>
 /// <param name="data">The data to write.</param>
 public static void WriteInt(ByteBuffer buffer, int data)
 {
     buffer.Validate(true, FixedWidth.Int);
     WriteInt(buffer.Buffer, buffer.WritePos, data);
     buffer.Append(FixedWidth.Int);
 }
 /// <summary>
 /// Writes bytes from one buffer into another.
 /// </summary>
 /// <param name="buffer">The destination buffer.</param>
 /// <param name="data">The source buffer</param>
 /// <param name="offset">The position in source buffer to start.</param>
 /// <param name="count">The number of bytes to write.</param>
 public static void WriteBytes(ByteBuffer buffer, byte[] data, int offset, int count)
 {
     buffer.Validate(true, count);
     Array.Copy(data, offset, buffer.Buffer, buffer.WritePos, count);
     buffer.Append(count);
 }
 /// <summary>
 /// Writes a signed byte into the buffer and advance the buffer write cursor.
 /// </summary>
 /// <param name="buffer">The buffer to write.</param>
 /// <param name="data">The data to write.</param>
 public static void WriteByte(ByteBuffer buffer, sbyte data)
 {
     buffer.Validate(true, FixedWidth.Byte);
     buffer.Buffer[buffer.WritePos] = (byte)data;
     buffer.Append(FixedWidth.Byte);
 }
        /// <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.Validate(false, 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);
        }
 /// <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.Validate(false, count);
     Array.Copy(buffer.Buffer, buffer.Offset, data, offset, count);
     buffer.Complete(count);
 }
 /// <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.Validate(false, 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;
 }