Beispiel #1
0
        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}'");
        }
Beispiel #2
0
 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);
     }
 }
Beispiel #3
0
 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 _));
     }
 }
Beispiel #4
0
 internal static void Encode(Multiple <T> multiple, ByteBuffer buffer)
 {
     if (multiple == null)
     {
         AmqpEncoding.EncodeNull(buffer);
     }
     else if (multiple.Count == 1)
     {
         AmqpEncoding.EncodeObject(multiple[0], buffer);
     }
     else
     {
         ArrayEncoding.Encode(multiple.ToArray(), buffer);
     }
 }
Beispiel #5
0
 internal static int GetEncodeSize(Multiple <T> multiple)
 {
     if (multiple == null)
     {
         return(FixedWidth.NullEncoded);
     }
     else if (multiple.Count == 1)
     {
         return(AmqpEncoding.GetObjectEncodeSize(multiple[0]));
     }
     else
     {
         return(ArrayEncoding.GetEncodeSize(multiple.ToArray()));
     }
 }
Beispiel #6
0
        /// <summary>
        /// Returns a new Multiple object that contains items in both Multiple objects.
        /// </summary>
        /// <param name="multiple1">The first Multiple object.</param>
        /// <param name="multiple2">The second Multiple object.</param>
        /// <returns>A Multiple object that contains items in both Multiple objects.</returns>
        public static IList <T> Intersect(Multiple <T> multiple1, Multiple <T> multiple2)
        {
            List <T> list = new List <T>();

            if (multiple1 == null || multiple2 == null)
            {
                return(list);
            }

            foreach (T t1 in multiple1)
            {
                if (multiple2.Contains(t1))
                {
                    list.Add(t1);
                }
            }

            return(list);
        }
Beispiel #7
0
        internal static Multiple <T> Decode(ByteBuffer buffer)
        {
            object value = AmqpEncoding.DecodeObject(buffer);

            if (value == null)
            {
                return(null);
            }
            else if (value is T)
            {
                Multiple <T> multiple = new Multiple <T>();
                multiple.Add((T)value);
                return(multiple);
            }
            else if (value.GetType().IsArray)
            {
                Multiple <T> multiple = new Multiple <T>((T[])value);
                return(multiple);
            }
            else
            {
                throw new AmqpException(AmqpErrorCode.InvalidField, null);
            }
        }