Exemplo n.º 1
0
 public static uint ReadUInt(ByteBuffer buffer)
 {
     buffer.Validate(false, FixedWidth.UInt);
     uint data = ReadUInt(buffer.Buffer, buffer.Offset, buffer.Length);
     buffer.Complete(FixedWidth.UInt);
     return data;
 }
Exemplo n.º 2
0
 public static sbyte ReadByte(ByteBuffer buffer)
 {
     buffer.Validate(false, FixedWidth.Byte);
     sbyte data = (sbyte)buffer.Buffer[buffer.Offset];
     buffer.Complete(FixedWidth.Byte);
     return data;
 }
Exemplo n.º 3
0
 public void Encode(ByteBuffer buffer)
 {
     byte[] bytes = this.uuid.ToByteArray();
     buffer.Validate(true, bytes.Length);
     Buffer.BlockCopy(bytes, 0, buffer.Buffer, buffer.WritePos, bytes.Length);
     buffer.Append(bytes.Length);
 }
Exemplo n.º 4
0
        public static ushort ReadUShort(ByteBuffer buffer)
        {
            buffer.Validate(false, FixedWidth.UShort);
            ushort data;
            fixed (byte* p = &buffer.Buffer[buffer.Offset])
            {
                byte* d = (byte*)&data;
                d[0] = p[1];
                d[1] = p[0];
            }

            buffer.Complete(FixedWidth.UShort);
            return data;
        }
Exemplo n.º 5
0
        public static int ReadInt(ByteBuffer buffer)
        {
            buffer.Validate(false, FixedWidth.Int);
            int data;
            fixed (byte* p = &buffer.Buffer[buffer.Offset])
            {
                byte* d = (byte*)&data;
                d[0] = p[3];
                d[1] = p[2];
                d[2] = p[1];
                d[3] = p[0];
            }

            buffer.Complete(FixedWidth.Int);
            return data;
        }
Exemplo n.º 6
0
 public static void WriteBytes(ByteBuffer buffer, byte[] data, int offset, int count)
 {
     buffer.Validate(true, count);
     Buffer.BlockCopy(data, offset, buffer.Buffer, buffer.WritePos, count);
     buffer.Append(count);
 }
Exemplo n.º 7
0
 public static ulong ReadULong(ByteBuffer buffer)
 {
     buffer.Validate(false, FixedWidth.ULong);
     ulong data = ReadULong(buffer.Buffer, buffer.Offset, buffer.Length);
     buffer.Complete(FixedWidth.ULong);
     return data;
 }
Exemplo n.º 8
0
        static string ReadString(ByteBuffer buffer, byte formatCode, byte code8, byte code32, string type)
        {
            if (formatCode == FormatCode.Null)
            {
                return null;
            }

            int count;
            if (formatCode == code8)
            {
                count = AmqpBitConverter.ReadUByte(buffer);
            }
            else if (formatCode == code32)
            {
                count = (int)AmqpBitConverter.ReadUInt(buffer);
            }
            else
            {
                throw DecodeException(formatCode, buffer.Offset);
            }

            buffer.Validate(false, count);
            string value = new string(Encoding.UTF8.GetChars(buffer.Buffer, buffer.Offset, count));
            buffer.Complete(count);

            return value;
        }
Exemplo n.º 9
0
        public static void WriteFloat(ByteBuffer buffer, float data)
        {
            buffer.Validate(true, FixedWidth.Float);
            fixed (byte* d = &buffer.Buffer[buffer.WritePos])
            {
                byte* p = (byte*)&data;
                d[0] = p[3];
                d[1] = p[2];
                d[2] = p[1];
                d[3] = p[0];
            }

            buffer.Append(FixedWidth.Float);
        }
Exemplo n.º 10
0
        public static void WriteUShort(ByteBuffer buffer, ushort data)
        {
            buffer.Validate(true, FixedWidth.UShort);
            fixed (byte* d = &buffer.Buffer[buffer.WritePos])
            {
                byte* p = (byte*)&data;
                d[0] = p[1];
                d[1] = p[0];
            }

            buffer.Append(FixedWidth.UShort);
        }
Exemplo n.º 11
0
 public static void WriteUByte(ByteBuffer buffer, byte data)
 {
     buffer.Validate(true, FixedWidth.UByte);
     buffer.Buffer[buffer.WritePos] = data;
     buffer.Append(FixedWidth.UByte);
 }
Exemplo n.º 12
0
 public static void ReadBytes(ByteBuffer buffer, byte[] data, int offset, int count)
 {
     buffer.Validate(false, count);
     Buffer.BlockCopy(buffer.Buffer, buffer.Offset, data, offset, count);
     buffer.Complete(count);
 }
Exemplo n.º 13
0
        public static Guid ReadUuid(ByteBuffer buffer)
        {
            buffer.Validate(false, FixedWidth.Uuid);
            Guid data;
            fixed (byte* p = &buffer.Buffer[buffer.Offset])
            {
                byte* d = (byte*)&data;
                d[0] = p[3];
                d[1] = p[2];
                d[2] = p[1];
                d[3] = p[0];

                d[4] = p[5];
                d[5] = p[4];

                d[6] = p[7];
                d[7] = p[6];

                *((ulong*)&d[8]) = *((ulong*)&p[8]);
            }

            buffer.Complete(FixedWidth.Uuid);
            return data;
        }
Exemplo n.º 14
0
        public static double ReadDouble(ByteBuffer buffer)
        {
            buffer.Validate(false, FixedWidth.Double);
            double data;
            fixed (byte* p = &buffer.Buffer[buffer.Offset])
            {
                byte* d = (byte*)&data;
                d[0] = p[7];
                d[1] = p[6];
                d[2] = p[5];
                d[3] = p[4];
                d[4] = p[3];
                d[5] = p[2];
                d[6] = p[1];
                d[7] = p[0];
            }

            buffer.Complete(FixedWidth.Double);
            return data;
        }
Exemplo n.º 15
0
        internal static ByteBuffer ReadBinaryBuffer(ByteBuffer buffer)
        {
            byte formatCode = Encoder.ReadFormatCode(buffer);
            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);
            ByteBuffer result = new ByteBuffer(buffer.Buffer, buffer.Offset, count, count);
            buffer.Complete(count);

            return result;
        }
Exemplo n.º 16
0
 protected bool TryDecodeNull(ByteBuffer buffer)
 {
     buffer.Validate(false, FixedWidth.FormatCode);
     byte formatCode = buffer.Buffer[buffer.Offset];
     if (formatCode == FormatCode.Null)
     {
         buffer.Complete(FixedWidth.FormatCode);
         return true;
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 17
0
        public static void WriteDouble(ByteBuffer buffer, double data)
        {
            buffer.Validate(true, FixedWidth.Double);
            fixed (byte* d = &buffer.Buffer[buffer.WritePos])
            {
                byte* p = (byte*)&data;
                d[0] = p[7];
                d[1] = p[6];
                d[2] = p[5];
                d[3] = p[4];
                d[4] = p[3];
                d[5] = p[2];
                d[6] = p[1];
                d[7] = p[0];
            }

            buffer.Append(FixedWidth.Double);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Reads a binary value from a buffer.
        /// </summary>
        /// <param name="buffer">The buffer to read.</param>
        /// <param name="formatCode">The format code of the value.</param>
        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 DecodeException(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;
        }
Exemplo n.º 19
0
        public static void WriteUuid(ByteBuffer buffer, Guid data)
        {
            buffer.Validate(true, FixedWidth.Uuid);
            fixed (byte* d = &buffer.Buffer[buffer.WritePos])
            {
                byte* p = (byte*)&data;
                d[0] = p[3];
                d[1] = p[2];
                d[2] = p[1];
                d[3] = p[0];

                d[4] = p[5];
                d[5] = p[4];

                d[6] = p[7];
                d[7] = p[6];

                *((ulong*)&d[8]) = *((ulong*)&p[8]);
            }

            buffer.Append(FixedWidth.Uuid);
        }
Exemplo n.º 20
0
 public override object ReadObject(ByteBuffer buffer)
 {
     buffer.Validate(false, FixedWidth.FormatCode);
     FormatCode formatCode = buffer.Buffer[buffer.Offset];
     if (formatCode == FormatCode.Null)
     {
         buffer.Complete(FixedWidth.FormatCode);
         return null;
     }
     else
     {
         object container = this.CreateInstance();
         ((IAmqpSerializable)container).Decode(buffer);
         return container;
     }
 }
Exemplo n.º 21
0
 public override object ReadObject(ByteBuffer buffer)
 {
     buffer.Validate(false, FixedWidth.FormatCode);
     byte formatCode = buffer.Buffer[buffer.Offset];
     if (formatCode == FormatCode.Null)
     {
         buffer.Complete(FixedWidth.FormatCode);
         return null;
     }
     else
     {
         object value = this.type.CreateInstance(this.hasDefaultCtor);
         ((IAmqpSerializable)value).Decode(buffer);
         return value;
     }
 }