public static void Write(NetworkBinaryWriter writer, byte[] source, int offset, int count)
 {
     writer.Write(source, offset, count);
 }
 public static void WriteShort(NetworkBinaryWriter writer, ushort val)
 {
     writer.Write((ushort)val);
 }
        ///<summary>Writes an AMQP "table" to the writer.</summary>
        ///<remarks>
        ///<para>
        /// In this method, we assume that the stream that backs our
        /// NetworkBinaryWriter is a positionable stream - which it is
        /// currently (see Frame.m_accumulator, Frame.GetWriter and
        /// Command.Transmit).
        ///</para>
        ///<para>
        /// Supports the AMQP 0-8/0-9 standard entry types S, I, D, T
        /// and F, as well as the QPid-0-8 specific b, d, f, l, s, t
        /// x and V types and the AMQP 0-9-1 A type.
        ///</para>
        ///</remarks>
        public static void WriteTable(NetworkBinaryWriter writer, IDictionary val)
        {
            if (val == null)
            {
                writer.Write((uint)0);
            }
            else
            {
                Stream backingStream = writer.BaseStream;
                long patchPosition = backingStream.Position;
                writer.Write((uint)0); // length of table - will be backpatched

                foreach (DictionaryEntry entry in val)
                {
                    WriteShortstr(writer, (string)entry.Key);
                    object value = entry.Value;
                    WriteFieldValue(writer, value);
                }

                // Now, backpatch the table length.
                long savedPosition = backingStream.Position;
                long tableLength = savedPosition - patchPosition - 4; // offset for length word
                backingStream.Seek(patchPosition, SeekOrigin.Begin);
                writer.Write((uint)tableLength);
                backingStream.Seek(savedPosition, SeekOrigin.Begin);
            }
        }
 public static void WriteLong(NetworkBinaryWriter writer, uint val)
 {
     writer.Write((uint)val);
 }
 public static void WriteLongstr(NetworkBinaryWriter writer, byte[] val)
 {
     WriteLong(writer, (uint)val.Length);
     writer.Write(val);
 }
 public static void WriteString(NetworkBinaryWriter writer, string value) {
     writer.Write((byte) StreamWireFormattingTag.String);
     WriteUntypedString(writer, value);
 }
 public static void WriteArray(NetworkBinaryWriter writer, IList val)
 {
     if (val == null)
     {
         writer.Write((uint)0);
     }
     else
     {
         Stream backingStream = writer.BaseStream;
         long patchPosition = backingStream.Position;
         writer.Write((uint)0); // length of table - will be backpatched
         foreach (object entry in val)
         {
             WriteFieldValue(writer, entry);
         }
         long savedPosition = backingStream.Position;
         long tableLength = savedPosition - patchPosition - 4; // offset for length word
         backingStream.Seek(patchPosition, SeekOrigin.Begin);
         writer.Write((uint)tableLength);
         backingStream.Seek(savedPosition, SeekOrigin.Begin);
     }
 }
 public static void WriteInt64(NetworkBinaryWriter writer, long value)
 {
     writer.Write(value);
 }
 public static void WriteSingle(NetworkBinaryWriter writer, float value)
 {
     writer.Write(value);
 }
 public static void WriteInt16(NetworkBinaryWriter writer, short value)
 {
     writer.Write(value);
 }
 public static void WriteInt32(NetworkBinaryWriter writer, int value)
 {
     writer.Write(value);
 }
 public static void WriteDouble(NetworkBinaryWriter writer, double value)
 {
     writer.Write(value);
 }
 public static void WriteChar(NetworkBinaryWriter writer, char value)
 {
     writer.Write((ushort) value);
 }
 public static void WriteByte(NetworkBinaryWriter writer, byte value)
 {
     writer.Write(value);
 }
 public static void WriteDouble(NetworkBinaryWriter writer, double value) {
     writer.Write((byte) StreamWireFormattingTag.Double);
     writer.Write(value);
 }
 public static void WriteString(NetworkBinaryWriter writer, string value)
 {
     byte[] bytes = Encoding.UTF8.GetBytes(value);
     writer.Write((ushort) bytes.Length);
     writer.Write(bytes);
 }
 public static void WriteBytes(NetworkBinaryWriter writer,
                               byte[] value,
                               int offset,
                               int length)
 {
     writer.Write((byte) StreamWireFormattingTag.Bytes);
     writer.Write(length);
     writer.Write(value, offset, length);
 }
 public void WriteTo(NetworkBinaryWriter writer, ulong bodySize)
 {
     writer.Write((ushort)0); // weight - not currently used
     writer.Write((ulong)bodySize);
     WritePropertiesTo(new ContentHeaderPropertyWriter(writer));
 }
 public static void WriteUntypedString(NetworkBinaryWriter writer, string value) {
     writer.Write(Encoding.UTF8.GetBytes(value));
     writer.Write((byte) 0);
 }
 public static void WriteBool(NetworkBinaryWriter writer, bool value) {
     writer.Write((byte) StreamWireFormattingTag.Bool);
     writer.Write(value ? (byte) 0x01 : (byte) 0x00);
 }
 public static void WriteFieldValue(NetworkBinaryWriter writer, object value)
 {
     if (value == null)
     {
         WriteOctet(writer, (byte)'V');
     }
     else if (value is string)
     {
         WriteOctet(writer, (byte)'S');
         WriteLongstr(writer, Encoding.UTF8.GetBytes((string)value));
     }
     else if (value is byte[])
     {
         WriteOctet(writer, (byte)'S');
         WriteLongstr(writer, (byte[])value);
     }
     else if (value is int)
     {
         WriteOctet(writer, (byte)'I');
         writer.Write((int)value);
     }
     else if (value is decimal)
     {
         WriteOctet(writer, (byte)'D');
         WriteDecimal(writer, (decimal)value);
     }
     else if (value is AmqpTimestamp)
     {
         WriteOctet(writer, (byte)'T');
         WriteTimestamp(writer, (AmqpTimestamp)value);
     }
     else if (value is IDictionary)
     {
         WriteOctet(writer, (byte)'F');
         WriteTable(writer, (IDictionary)value);
     }
     else if (value is IList)
     {
         WriteOctet(writer, (byte)'A');
         WriteArray(writer, (IList)value);
     }
     else if (value is byte)
     {
         WriteOctet(writer, (byte)'b');
         WriteOctet(writer, (byte)value);
     }
     else if (value is double)
     {
         WriteOctet(writer, (byte)'d');
         writer.Write((double)value);
     }
     else if (value is float)
     {
         WriteOctet(writer, (byte)'f');
         writer.Write((float)value);
     }
     else if (value is long)
     {
         WriteOctet(writer, (byte)'l');
         writer.Write((long)value);
     }
     else if (value is short)
     {
         WriteOctet(writer, (byte)'s');
         writer.Write((short)value);
     }
     else if (value is bool)
     {
         WriteOctet(writer, (byte)'t');
         WriteOctet(writer, (byte)(((bool)value) ? 1 : 0));
     }
     else if (value is BinaryTableValue)
     {
         WriteOctet(writer, (byte)'x');
         WriteLongstr(writer, ((BinaryTableValue)value).Bytes);
     }
     else
     {
         throw new WireFormattingException("Value cannot appear as table value",
                                           value);
     }
 }
 public static void WriteInt16(NetworkBinaryWriter writer, short value) {
     writer.Write((byte) StreamWireFormattingTag.Int16);
     writer.Write(value);
 }
 public static void WriteLonglong(NetworkBinaryWriter writer, ulong val)
 {
     writer.Write((ulong)val);
 }
 public static void WriteChar(NetworkBinaryWriter writer, char value) {
     writer.Write((byte) StreamWireFormattingTag.Char);
     writer.Write((ushort) value);
 }
 public static void WriteOctet(NetworkBinaryWriter writer, byte val)
 {
     writer.Write((byte)val);
 }
 public static void WriteInt64(NetworkBinaryWriter writer, long value) {
     writer.Write((byte) StreamWireFormattingTag.Int64);
     writer.Write(value);
 }
 public static void WriteShortstr(NetworkBinaryWriter writer, string val)
 {
     byte[] bytes = Encoding.UTF8.GetBytes(val);
     int len = bytes.Length;
     if (len > 255)
     {
         throw new WireFormattingException("Short string too long; " +
                                           "UTF-8 encoded length=" + len + ", max=255");
     }
     writer.Write((byte)len);
     writer.Write(bytes);
 }
 public static void WriteSingle(NetworkBinaryWriter writer, float value) {
     writer.Write((byte) StreamWireFormattingTag.Single);
     writer.Write(value);
 }
Esempio n. 29
0
 public void WriteTo(NetworkBinaryWriter writer)
 {
     FinishWriting();
     writer.Write((byte) m_type);
     writer.Write((ushort) m_channel);
     writer.Write((uint) m_payload.Length);
     writer.Write((byte[]) m_payload);
     writer.Write((byte) CommonFraming.Constants.FrameEnd);
 }
        ///<summary>Writes an AMQP "table" to the writer.</summary>
        ///<remarks>
        ///<para>
        /// In this method, we assume that the stream that backs our
        /// NetworkBinaryWriter is a positionable stream - which it is
        /// currently (see Frame.m_accumulator, Frame.GetWriter and
        /// Command.Transmit).
        ///</para>
        ///<para>
        /// Supports the AMQP 0-8/0-9 standard entry types S, I, D, T
        /// and F, as well as the QPid-0-8 specific b, d, f, l, s, t
        /// x and V types.
        ///</para>
        ///</remarks>
        public static void WriteTable(NetworkBinaryWriter writer, IDictionary val)
        {
            if (val == null)
            {
                writer.Write((uint)0);
            }
            else
            {
                Stream backingStream = writer.BaseStream;
                long patchPosition = backingStream.Position;
                writer.Write((uint)0); // length of table - will be backpatched

                foreach (DictionaryEntry entry in val)
                {
                    WriteShortstr(writer, (string)entry.Key);
                    object value = entry.Value;

                    if (value == null)
                    {
                        WriteOctet(writer, (byte)'V');
                    }
                    else if (value is string)
                    {
                        WriteOctet(writer, (byte)'S');
                        WriteLongstr(writer, Encoding.UTF8.GetBytes((string)value));
                    }
                    else if (value is byte[])
                    {
                        WriteOctet(writer, (byte)'S');
                        WriteLongstr(writer, (byte[])value);
                    }
                    else if (value is int)
                    {
                        WriteOctet(writer, (byte)'I');
                        writer.Write((int)value);
                    }
                    else if (value is decimal)
                    {
                        WriteOctet(writer, (byte)'D');
                        WriteDecimal(writer, (decimal)value);
                    }
                    else if (value is AmqpTimestamp)
                    {
                        WriteOctet(writer, (byte)'T');
                        WriteTimestamp(writer, (AmqpTimestamp)value);
                    }
                    else if (value is IDictionary)
                    {
                        WriteOctet(writer, (byte)'F');
                        WriteTable(writer, (IDictionary)value);
                    }
                    else if (value is byte)
                    {
                        WriteOctet(writer, (byte)'b');
                        WriteOctet(writer, (byte)value);
                    }
                    else if (value is double)
                    {
                        WriteOctet(writer, (byte)'d');
                        writer.Write((double)value);
                    }
                    else if (value is float)
                    {
                        WriteOctet(writer, (byte)'f');
                        writer.Write((float)value);
                    }
                    else if (value is long)
                    {
                        WriteOctet(writer, (byte)'l');
                        writer.Write((long)value);
                    }
                    else if (value is short)
                    {
                        WriteOctet(writer, (byte)'s');
                        writer.Write((short)value);
                    }
                    else if (value is bool)
                    {
                        WriteOctet(writer, (byte)'t');
                        WriteOctet(writer, (byte)(((bool)value) ? 1 : 0));
                    }
                    else if (value is BinaryTableValue)
                    {
                        WriteOctet(writer, (byte)'x');
                        WriteLongstr(writer, ((BinaryTableValue)value).Bytes);
                    }
                    else
                    {
                        throw new WireFormattingException("Value cannot appear as table value",
                                                          value);
                    }
                }

                // Now, backpatch the table length.
                long savedPosition = backingStream.Position;
                long tableLength = savedPosition - patchPosition - 4; // offset for length word
                backingStream.Seek(patchPosition, SeekOrigin.Begin);
                writer.Write((uint)tableLength);
                backingStream.Seek(savedPosition, SeekOrigin.Begin);
            }
        }