internal static Multiple <T> Decode(ByteBuffer buffer) { FormatCode formatCode = AmqpEncoding.ReadFormatCode(buffer); if (formatCode == FormatCode.Null) { return(null); } if (formatCode == FormatCode.Array8 || formatCode == FormatCode.Array32) { T[] array = ArrayEncoding.Decode <T>(buffer, formatCode); return(new Multiple <T>(array)); } if (formatCode == FormatCode.Symbol8 || formatCode == FormatCode.Symbol32) { var symbol = SymbolEncoding.Decode(buffer, formatCode); return(new Multiple <AmqpSymbol>() { symbol } as Multiple <T>); } object value = AmqpEncoding.DecodeObject(buffer, formatCode); if (value is T) { Multiple <T> multiple = new Multiple <T>(); multiple.Add((T)value); return(multiple); } throw new AmqpException(AmqpErrorCode.InvalidField, $"The expected type is '{typeof(T).Name}' but got '{value.GetType().Name}'"); }
public static int GetEncodeSize(Multiple <T> multiple) { if (multiple == null) { return(1); } if ([email protected] != 1) { return(ArrayEncoding.GetEncodeSize <T>([email protected]())); } return(AmqpEncoding.GetObjectEncodeSize(multiple.@value[0])); }
public static void Encode(Multiple <T> multiple, ByteBuffer buffer) { if (multiple == null) { AmqpEncoding.EncodeNull(buffer); return; } if ([email protected] != 1) { ArrayEncoding.Encode <T>([email protected](), buffer); return; } AmqpEncoding.EncodeObject(multiple.@value[0], buffer); }
internal static void Encode(Multiple <T> multiple, ByteBuffer buffer) { if (multiple == null) { AmqpEncoding.EncodeNull(buffer); } else if (multiple.Count == 1) { ArrayEncoding.EncodeValue(multiple, multiple.Count, typeof(T), buffer); } else { ArrayEncoding.Encode(multiple, multiple.Count, typeof(T), buffer); } }
internal static int GetEncodeSize(Multiple <T> multiple) { if (multiple == null) { return(FixedWidth.NullEncoded); } else if (multiple.Count == 1) { return(FixedWidth.FormatCode + ArrayEncoding.GetValueSize(multiple, 1, typeof(T))); } else { return(ArrayEncoding.GetEncodeSize(multiple, multiple.Count, typeof(T), false, out _)); } }
public static void Encode(Multiple <T> multiple, ByteBuffer buffer) { if (multiple == null) { AmqpEncoding.EncodeNull(buffer); } else if (multiple.value.Count == 1) { AmqpEncoding.EncodeObject(multiple.value[0], buffer); } else { ArrayEncoding.Encode(multiple.value.ToArray(), buffer); } }
public static int GetEncodeSize(Multiple <T> multiple) { if (multiple == null) { return(FixedWidth.NullEncoded); } else if (multiple.value.Count == 1) { return(AmqpEncoding.GetObjectEncodeSize(multiple.value[0])); } else { return(ArrayEncoding.GetEncodeSize(multiple.value.ToArray())); } }
/// <summary> /// Decodes an array from the buffer and advances the buffer's position. /// </summary> /// <param name="buffer">The buffer to read.</param> /// <returns>An array.</returns> public static T[] DecodeArray <T>(ByteBuffer buffer) { return(ArrayEncoding.Decode <T>(buffer, 0)); }
/// <summary> /// Encodes an array and appends the bytes to the buffer. /// </summary> /// <typeparam name="T">Type of items in the array.</typeparam> /// <param name="data">The array.</param> /// <param name="buffer">The destination buffer.</param> public static void EncodeArray <T>(T[] data, ByteBuffer buffer) { ArrayEncoding.Encode(data, buffer); }
/// <summary> /// Gets the encode size of an array. /// </summary> /// <typeparam name="T">Type of items in the array.</typeparam> /// <param name="value">The array.</param> /// <returns>Encode size in bytes of the array.</returns> public static int GetArrayEncodeSize <T>(T[] value) { return(ArrayEncoding.GetEncodeSize(value)); }