public static object ReadFieldValue(NetworkBinaryReader reader) { object value = null; byte discriminator = reader.ReadByte(); switch ((char)discriminator) { case 'S': value = ReadLongstr(reader); break; case 'I': value = reader.ReadInt32(); break; case 'D': value = ReadDecimal(reader); break; case 'T': value = ReadTimestamp(reader); break; case 'F': value = ReadTable(reader); break; case 'A': value = ReadArray(reader); break; case 'b': value = ReadOctet(reader); break; case 'd': value = reader.ReadDouble(); break; case 'f': value = reader.ReadSingle(); break; case 'l': value = reader.ReadInt64(); break; case 's': value = reader.ReadInt16(); break; case 't': value = (ReadOctet(reader) != 0); break; case 'x': value = new BinaryTableValue(ReadLongstr(reader)); break; case 'V': value = null; break; default: throw new SyntaxError("Unrecognised type in table: " + (char) discriminator); } return value; }
public static long ReadInt64(NetworkBinaryReader reader) { return reader.ReadInt64(); }
///<exception cref="EndOfStreamException"/> ///<exception cref="ProtocolViolationException"/> public static object ReadObject(NetworkBinaryReader reader) { int typeTag = reader.ReadByte(); switch (typeTag) { case -1: throw new EndOfStreamException("End of StreamMessage reached"); case (int) StreamWireFormattingTag.Bool: { byte value = reader.ReadByte(); switch (value) { case 0x00: return false; case 0x01: return true; default: { string message = string.Format("Invalid boolean value in StreamMessage: {0}", value); throw new ProtocolViolationException(message); } } } case (int) StreamWireFormattingTag.Byte: return reader.ReadByte(); case (int) StreamWireFormattingTag.Bytes: { int length = reader.ReadInt32(); if (length == -1) { return null; } else { return reader.ReadBytes(length); } } case (int) StreamWireFormattingTag.Int16: return reader.ReadInt16(); case (int) StreamWireFormattingTag.Char: return (char) reader.ReadUInt16(); case (int) StreamWireFormattingTag.Int32: return reader.ReadInt32(); case (int) StreamWireFormattingTag.Int64: return reader.ReadInt64(); case (int) StreamWireFormattingTag.Single: return reader.ReadSingle(); case (int) StreamWireFormattingTag.Double: return reader.ReadDouble(); case (int) StreamWireFormattingTag.String: return ReadUntypedString(reader); case (int) StreamWireFormattingTag.Null: return null; default: { string message = string.Format("Invalid type tag in StreamMessage: {0}", typeTag); throw new ProtocolViolationException(message); } } }
///<summary>Reads an AMQP "table" definition from the reader.</summary> ///<remarks> /// 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. ///</remarks> public static IDictionary ReadTable(NetworkBinaryReader reader) { Hashtable table = new Hashtable(); long tableLength = reader.ReadUInt32(); Stream backingStream = reader.BaseStream; long startPosition = backingStream.Position; while ((backingStream.Position - startPosition) < tableLength) { string key = ReadShortstr(reader); object value = null; byte discriminator = reader.ReadByte(); switch ((char)discriminator) { case 'S': value = ReadLongstr(reader); break; case 'I': value = reader.ReadInt32(); break; case 'D': value = ReadDecimal(reader); break; case 'T': value = ReadTimestamp(reader); break; case 'F': value = ReadTable(reader); break; case 'b': value = ReadOctet(reader); break; case 'd': value = reader.ReadDouble(); break; case 'f': value = reader.ReadSingle(); break; case 'l': value = reader.ReadInt64(); break; case 's': value = reader.ReadInt16(); break; case 't': value = (ReadOctet(reader) != 0); break; case 'x': value = new BinaryTableValue(ReadLongstr(reader)); break; case 'V': value = null; break; default: throw new SyntaxError("Unrecognised type in table: " + (char) discriminator); } if (!table.ContainsKey(key)) { table[key] = value; } } return table; }