public static object DecodeObject(ByteBuffer buffer) { FormatCode formatCode = AmqpEncoding.ReadFormatCode(buffer); if (formatCode == 64) { return(null); } if (formatCode != 0) { return(AmqpEncoding.DecodeObject(buffer, formatCode)); } object obj = AmqpCodec.DecodeObject(buffer); Func <AmqpDescribed> func = null; if (obj is AmqpSymbol) { Dictionary <string, Func <AmqpDescribed> > strs = AmqpCodec.knownTypesByName; AmqpSymbol amqpSymbol = (AmqpSymbol)obj; strs.TryGetValue(amqpSymbol.Value, out func); } else if (obj is ulong) { AmqpCodec.knownTypesByCode.TryGetValue((ulong)obj, out func); } if (func == null) { return(new DescribedType(obj, AmqpCodec.DecodeObject(buffer))); } AmqpDescribed amqpDescribed = func(); amqpDescribed.DecodeValue(buffer); return(amqpDescribed); }
public static AmqpDescribed DecodeAmqpDescribed(ByteBuffer buffer, Dictionary <string, Func <AmqpDescribed> > byName, Dictionary <ulong, Func <AmqpDescribed> > byCode) { AmqpDescribed amqpDescribed = AmqpCodec.CreateAmqpDescribed(buffer, byName, byCode); if (amqpDescribed != null) { amqpDescribed.DecodeValue(buffer); } return(amqpDescribed); }
/// <summary> /// Decodes an <see cref="AmqpDescribed"/> object from the buffer. /// </summary> /// <param name="buffer">The input buffer.</param> /// <returns>An AmqpDescribed object.</returns> public static AmqpDescribed DecodeAmqpDescribed(ByteBuffer buffer) { AmqpDescribed value = CreateAmqpDescribed(buffer, knownTypesByName, knownTypesByCode); if (value != null) { value.DecodeValue(buffer); } return(value); }
public static AmqpDescribed DecodeAmqpDescribed( ByteBuffer buffer, Dictionary <string, Func <AmqpDescribed> > byName, Dictionary <ulong, Func <AmqpDescribed> > byCode) { AmqpDescribed value = CreateAmqpDescribed(buffer, byName, byCode); if (value != null) { value.DecodeValue(buffer); } return(value); }
/// <summary> /// Decodes an AMQP object from the buffer and advances the buffer's position. /// </summary> /// <param name="buffer">The buffer to read.</param> /// <returns>An AMQP object.</returns> public static object DecodeObject(ByteBuffer buffer) { FormatCode formatCode = AmqpEncoding.ReadFormatCode(buffer); if (formatCode == FormatCode.Null) { return(null); } else if (formatCode == FormatCode.Described) { object descriptor = AmqpCodec.DecodeObject(buffer); Func <AmqpDescribed> knownTypeCtor = null; if (descriptor is AmqpSymbol) { knownTypesByName.TryGetValue(((AmqpSymbol)descriptor).Value, out knownTypeCtor); } else if (descriptor is ulong) { knownTypesByCode.TryGetValue((ulong)descriptor, out knownTypeCtor); } if (knownTypeCtor != null) { AmqpDescribed amqpDescribed = knownTypeCtor(); amqpDescribed.DecodeValue(buffer); return(amqpDescribed); } else { object value = AmqpCodec.DecodeObject(buffer); return(new DescribedType(descriptor, value)); } } else { return(AmqpEncoding.DecodeObject(buffer, formatCode)); } }