Beispiel #1
0
        public static SerializableType CreatePrimitiveType(Type type)
        {
            // encoder is pre-determined
            EncodingBase encoder = AmqpEncoding.GetEncoding(type);

            return(new Primitive(type, encoder));
        }
Beispiel #2
0
 public DescribedValueType(string symbol, Func <TValue, TAs> getter, Func <TAs, TValue> setter) : base(null, typeof(TValue))
 {
     this.symbol  = symbol;
     this.encoder = AmqpEncoding.GetEncoding(typeof(TAs));
     this.getter  = getter;
     this.setter  = setter;
 }
Beispiel #3
0
        public static AmqpDescribed CreateAmqpDescribed(ByteBuffer buffer, Dictionary <string, Func <AmqpDescribed> > byName, Dictionary <ulong, Func <AmqpDescribed> > byCode)
        {
            FormatCode formatCode = AmqpEncoding.ReadFormatCode(buffer);

            if (formatCode == 64)
            {
                return(null);
            }
            EncodingBase.VerifyFormatCode(formatCode, 0, buffer.Offset);
            Func <AmqpDescribed> func = null;

            formatCode = AmqpEncoding.ReadFormatCode(buffer);
            if (formatCode == 163 || formatCode == 179)
            {
                AmqpSymbol amqpSymbol = SymbolEncoding.Decode(buffer, formatCode);
                byName.TryGetValue(amqpSymbol.Value, out func);
            }
            else if (formatCode == 68 || formatCode == 128 || formatCode == 83)
            {
                ulong?nullable = ULongEncoding.Decode(buffer, formatCode);
                byCode.TryGetValue(nullable.Value, out func);
            }
            if (func == null)
            {
                throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInvalidFormatCode(formatCode, buffer.Offset));
            }
            return(func());
        }
Beispiel #4
0
 public Converted(AmqpType amqpType, Type source, Type target,
                  Func <object, Type, object> getTarget, Func <object, Type, object> getSource)
     : base(null, target)
 {
     this.AmqpType  = amqpType;
     this.source    = source;
     this.target    = target;
     this.getTarget = getTarget;
     this.getSource = getSource;
     this.encoder   = AmqpEncoding.GetEncoding(target);
 }
 public override void EncodeObject(object value, bool arrayEncoding, ByteBuffer buffer)
 {
     if (arrayEncoding)
     {
         object       describedValue = ((DescribedType)value).Value;
         EncodingBase encoding       = AmqpEncoding.GetEncoding(describedValue);
         encoding.EncodeObject(describedValue, true, buffer);
     }
     else
     {
         DescribedEncoding.Encode((DescribedType)value, buffer);
     }
 }
 public override int GetObjectEncodeSize(object value, bool arrayEncoding)
 {
     if (arrayEncoding)
     {
         object       describedValue = ((DescribedType)value).Value;
         EncodingBase encoding       = AmqpEncoding.GetEncoding(describedValue);
         return(encoding.GetObjectEncodeSize(describedValue, true));
     }
     else
     {
         return(DescribedEncoding.GetEncodeSize((DescribedType)value));
     }
 }
Beispiel #7
0
        internal static AmqpDescribed CreateAmqpDescribed(
            ByteBuffer buffer,
            Dictionary <string, Func <AmqpDescribed> > byName,
            Dictionary <ulong, Func <AmqpDescribed> > byCode)
        {
            FormatCode formatCode = AmqpEncoding.ReadFormatCode(buffer);

            if (formatCode == FormatCode.Null)
            {
                return(null);
            }

            EncodingBase.VerifyFormatCode(formatCode, buffer.Offset, FormatCode.Described);

            Func <AmqpDescribed> knownTypeCtor = null;

            formatCode = AmqpEncoding.ReadFormatCode(buffer);
            if (formatCode == FormatCode.Symbol8 || formatCode == FormatCode.Symbol32)
            {
                AmqpSymbol name = SymbolEncoding.Decode(buffer, formatCode);
                byName.TryGetValue(name.Value, out knownTypeCtor);
            }
            else if (formatCode == FormatCode.ULong0 || formatCode == FormatCode.ULong || formatCode == FormatCode.SmallULong)
            {
                ulong code = ULongEncoding.Decode(buffer, formatCode).Value;
                byCode.TryGetValue(code, out knownTypeCtor);
            }

            if (knownTypeCtor == null)
            {
                throw AmqpEncoding.GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, buffer.Offset));
            }

            AmqpDescribed value = knownTypeCtor();

            return(value);
        }
Beispiel #8
0
 public PremitiveType(Type type)
 {
     this.encoder = AmqpEncoding.GetEncoding(type);
 }
Beispiel #9
0
 public Primitive(Type type, EncodingBase encoder)
     : base(null, type)
 {
     this.AmqpType = AmqpType.Primitive;
     this.encoder = encoder;
 }
Beispiel #10
0
 public Converted(AmqpType amqpType, Type source, Type target,
     Func<object, object> getTarget, Func<object, object> getSource)
     : base(null, target)
 {
     this.AmqpType = amqpType;
     this.source = source;
     this.target = target;
     this.GetTarget = getTarget;
     this.GetSource = getSource;
     this.encoder = AmqpEncoding.GetEncoding(target);
 }
Beispiel #11
0
 public Primitive(Type type, EncodingBase encoder)
     : base(null, type)
 {
     this.AmqpType = AmqpType.Primitive;
     this.encoder  = encoder;
 }
Beispiel #12
0
 public SingleValueType(Type type, EncodingBase encoder) : base(null, type)
 {
     this.encoder = encoder;
 }