public static void WriteLongstr(NetworkBinaryWriter writer, byte[] val, int index, int count) { WriteLong(writer, (uint)count); writer.Write(val, index, count); }
public static void WriteSingle(NetworkBinaryWriter writer, float value) { writer.Write((byte)StreamWireFormattingTag.Single); writer.Write(value); }
public static void WriteString(NetworkBinaryWriter writer, string value) { writer.Write((byte)StreamWireFormattingTag.String); WriteUntypedString(writer, value); }
public static void WriteBool(NetworkBinaryWriter writer, bool value) { writer.Write((byte)StreamWireFormattingTag.Bool); writer.Write(value ? (byte)0x01 : (byte)0x00); }
public static void WriteChar(NetworkBinaryWriter writer, char value) { writer.Write((byte)StreamWireFormattingTag.Char); writer.Write((ushort)value); }
public static void WriteInt64(NetworkBinaryWriter writer, long value) { 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 WriteLongstr(NetworkBinaryWriter writer, byte[] val) { WriteLong(writer, (uint)val.Length); writer.Write(val); }
public static void WriteShort(NetworkBinaryWriter writer, ushort val) { writer.Write((ushort)val); }
private void EmitFlagWord(bool continuationBit) { m_writer.Write((ushort)(continuationBit ? (m_flagWord | 1) : m_flagWord)); m_flagWord = 0; m_bitCount = 0; }
public static void WriteOctet(NetworkBinaryWriter writer, byte val) { writer.Write((byte)val); }
public void WriteTo(NetworkBinaryWriter writer, ulong bodySize) { writer.Write((ushort)0); // weight - not currently used writer.Write(bodySize); WritePropertiesTo(new ContentHeaderPropertyWriter(writer)); }
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 sbyte) { WriteOctet(writer, (byte)'b'); writer.Write((sbyte)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 WriteFieldValue(NetworkBinaryWriter writer, object value) { switch (value) { case null: WriteOctet(writer, (byte)'V'); break; case string val: WriteOctet(writer, (byte)'S'); WriteLongstr(writer, Encoding.UTF8.GetBytes(val)); break; case byte[] val: WriteOctet(writer, (byte)'S'); WriteLongstr(writer, val); break; case int val: WriteOctet(writer, (byte)'I'); writer.Write(val); break; case uint val: WriteOctet(writer, (byte)'i'); writer.Write(val); break; case decimal val: WriteOctet(writer, (byte)'D'); WriteDecimal(writer, val); break; case AmqpTimestamp val: WriteOctet(writer, (byte)'T'); WriteTimestamp(writer, val); break; case IDictionary val: WriteOctet(writer, (byte)'F'); WriteTable(writer, val); break; case IList val: WriteOctet(writer, (byte)'A'); WriteArray(writer, val); break; case byte val: WriteOctet(writer, (byte)'B'); writer.Write(val); break; case sbyte val: WriteOctet(writer, (byte)'b'); writer.Write(val); break; case double val: WriteOctet(writer, (byte)'d'); writer.Write(val); break; case float val: WriteOctet(writer, (byte)'f'); writer.Write(val); break; case long val: WriteOctet(writer, (byte)'l'); writer.Write(val); break; case short val: WriteOctet(writer, (byte)'s'); writer.Write(val); break; case bool val: WriteOctet(writer, (byte)'t'); WriteOctet(writer, (byte)(val ? 1 : 0)); break; case BinaryTableValue val: WriteOctet(writer, (byte)'x'); WriteLongstr(writer, val.Bytes); break; default: throw new WireFormattingException( $"Value of type '{value.GetType().Name}' cannot appear as table value", value); } }
public static void WriteInt16(NetworkBinaryWriter writer, short value) { writer.Write(value); }
public static void WriteLong(NetworkBinaryWriter writer, uint val) { writer.Write((uint)val); }
public static void WriteInt32(NetworkBinaryWriter writer, int value) { writer.Write(value); }
public static void WriteLonglong(NetworkBinaryWriter writer, ulong val) { writer.Write((ulong)val); }
public static void WriteSingle(NetworkBinaryWriter writer, float value) { writer.Write(value); }
///<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); } }
public BodySegmentOutboundFrame(int channel, byte[] body, int offset, int count) : base(FrameType.FrameBody, channel) { NetworkBinaryWriter writer = base.GetWriter(); writer.Write(body, offset, count); }
public static void Write(NetworkBinaryWriter writer, byte[] source, int offset, int count) { writer.Write(source, offset, count); }
public static void WriteInt16(NetworkBinaryWriter writer, short value) { writer.Write((byte)StreamWireFormattingTag.Int16); writer.Write(value); }
public static void WriteByte(NetworkBinaryWriter writer, byte value) { writer.Write(value); }
public static void WriteInt64(NetworkBinaryWriter writer, long value) { writer.Write((byte)StreamWireFormattingTag.Int64); writer.Write(value); }
public static void WriteChar(NetworkBinaryWriter writer, char value) { writer.Write((ushort)value); }
public static void WriteDouble(NetworkBinaryWriter writer, double value) { writer.Write((byte)StreamWireFormattingTag.Double); writer.Write(value); }
public static void WriteDouble(NetworkBinaryWriter writer, double value) { writer.Write(value); }
public static void WriteUntypedString(NetworkBinaryWriter writer, string value) { writer.Write(Encoding.UTF8.GetBytes(value)); writer.Write((byte)0); }
public static void WriteFieldValue(NetworkBinaryWriter writer, object value) { switch (value) { case null: WriteOctet(writer, (byte)'V'); break; case string val: WriteOctet(writer, (byte)'S'); int maxLength = Encoding.UTF8.GetMaxByteCount(val.Length); byte[] bytes = ArrayPool <byte> .Shared.Rent(maxLength); try { int bytesUsed = Encoding.UTF8.GetBytes(val, 0, val.Length, bytes, 0); WriteLongstr(writer, bytes, 0, bytesUsed); } finally { ArrayPool <byte> .Shared.Return(bytes); } break; case byte[] val: WriteOctet(writer, (byte)'S'); WriteLongstr(writer, val); break; case int val: WriteOctet(writer, (byte)'I'); writer.Write(val); break; case uint val: WriteOctet(writer, (byte)'i'); writer.Write(val); break; case decimal val: WriteOctet(writer, (byte)'D'); WriteDecimal(writer, val); break; case AmqpTimestamp val: WriteOctet(writer, (byte)'T'); WriteTimestamp(writer, val); break; case IDictionary val: WriteOctet(writer, (byte)'F'); WriteTable(writer, val); break; case IList val: WriteOctet(writer, (byte)'A'); WriteArray(writer, val); break; case byte val: WriteOctet(writer, (byte)'B'); writer.Write(val); break; case sbyte val: WriteOctet(writer, (byte)'b'); writer.Write(val); break; case double val: WriteOctet(writer, (byte)'d'); writer.Write(val); break; case float val: WriteOctet(writer, (byte)'f'); writer.Write(val); break; case long val: WriteOctet(writer, (byte)'l'); writer.Write(val); break; case short val: WriteOctet(writer, (byte)'s'); writer.Write(val); break; case bool val: WriteOctet(writer, (byte)'t'); WriteOctet(writer, (byte)(val ? 1 : 0)); break; case BinaryTableValue val: WriteOctet(writer, (byte)'x'); WriteLongstr(writer, val.Bytes); break; default: throw new WireFormattingException( $"Value of type '{value.GetType().Name}' cannot appear as table value", value); } }