Exemple #1
0
 public static void ReadMapValue(ByteBuffer buffer, AmqpMap map, int size, int count)
 {
     for (; count > 0; count -= 2)
     {
         object key  = AmqpEncoding.DecodeObject(buffer);
         object item = AmqpCodec.DecodeObject(buffer);
         map[new MapKey(key)] = item;
     }
 }
Exemple #2
0
        public static int GetEncodeSize(AmqpMap value)
        {
            if (value == null)
            {
                return(FixedWidth.NullEncoded);
            }

            int valueSize = GetValueSize(value);

            return(FixedWidth.FormatCode + MapEncoding.GetEncodeWidth(value, valueSize) * 2 + valueSize);
        }
Exemple #3
0
 public override void EncodeObject(object value, bool arrayEncoding, ByteBuffer buffer)
 {
     if (arrayEncoding)
     {
         AmqpMap mapValue = (AmqpMap)value;
         int     size     = FixedWidth.UInt + mapValue.ValueSize;
         MapEncoding.Encode(mapValue, FixedWidth.UInt, size, buffer);
     }
     else
     {
         MapEncoding.Encode((AmqpMap)value, buffer);
     }
 }
Exemple #4
0
        public static void Encode(AmqpMap value, ByteBuffer buffer)
        {
            if (value == null)
            {
                AmqpEncoding.EncodeNull(buffer);
            }
            else
            {
                int encodeWidth = MapEncoding.GetEncodeWidth(value);
                AmqpBitConverter.WriteUByte(buffer, encodeWidth == FixedWidth.UByte ? FormatCode.Map8 : FormatCode.Map32);

                int size = encodeWidth + value.ValueSize;
                MapEncoding.Encode(value, encodeWidth, size, buffer);
            }
        }
Exemple #5
0
        public static int GetValueSize(AmqpMap value)
        {
            int size = 0;

            if (value.Count > 0)
            {
                foreach (KeyValuePair <MapKey, object> item in value)
                {
                    size += AmqpEncoding.GetObjectEncodeSize(item.Key.Key);
                    size += AmqpEncoding.GetObjectEncodeSize(item.Value);
                }
            }

            return(size);
        }
Exemple #6
0
        public static AmqpMap Decode(ByteBuffer buffer, FormatCode formatCode)
        {
            if (formatCode == 0 && (formatCode = AmqpEncoding.ReadFormatCode(buffer)) == FormatCode.Null)
            {
                return(null);
            }

            int size;
            int count;

            AmqpEncoding.ReadSizeAndCount(buffer, formatCode, FormatCode.Map8, FormatCode.Map32, out size, out count);
            AmqpMap map = new AmqpMap();

            MapEncoding.ReadMapValue(buffer, map, size, count);
            return(map);
        }
Exemple #7
0
        static void Encode(AmqpMap value, int width, int size, ByteBuffer buffer)
        {
            if (width == FixedWidth.UByte)
            {
                AmqpBitConverter.WriteUByte(buffer, (byte)size);
                AmqpBitConverter.WriteUByte(buffer, (byte)(value.Count * 2));
            }
            else
            {
                AmqpBitConverter.WriteUInt(buffer, (uint)size);
                AmqpBitConverter.WriteUInt(buffer, (uint)(value.Count * 2));
            }

            if (value.Count > 0)
            {
                foreach (KeyValuePair <MapKey, object> item in value)
                {
                    AmqpEncoding.EncodeObject(item.Key.Key, buffer);
                    AmqpEncoding.EncodeObject(item.Value, buffer);
                }
            }
        }
Exemple #8
0
 static int GetEncodeWidth(AmqpMap value)
 {
     return(AmqpEncoding.GetEncodeWidthByCountAndSize(value.Count * 2, value.ValueSize));
 }
Exemple #9
0
 public static int GetEncodeSize(AmqpMap value)
 {
     return(value == null ?
            FixedWidth.NullEncoded :
            FixedWidth.FormatCode + (MapEncoding.GetEncodeWidth(value) * 2) + value.ValueSize);
 }