Example #1
0
 public FudgeSerializationContext(FudgeContext context, SerializationTypeMap typeMap, IFudgeStreamWriter writer, IFudgeTypeMappingStrategy typeMappingStrategy)
 {
     this.context             = context;
     this.writer              = writer;
     this.typeMap             = typeMap;
     this.typeMappingStrategy = typeMappingStrategy;
 }
 public FudgeDeserializationContext(FudgeContext context, SerializationTypeMap typeMap, IFudgeTypeMappingStrategy typeMappingStrategy)
 {
     this.context             = context;
     this.typeMap             = typeMap;
     this.objectList          = new List <MsgAndObj>();
     this.stack               = new Stack <State>();
     this.typeMappingStrategy = typeMappingStrategy;
 }
        public void PicksUpPropertiesFromContext()
        {
            var context = new FudgeContext();

            var map1 = new SerializationTypeMap(context);
            Assert.True(map1.AllowTypeDiscovery);

            context.SetProperty(ContextProperties.AllowTypeDiscoveryProperty, false);
            var map2 = new SerializationTypeMap(context);
            Assert.False(map2.AllowTypeDiscovery);
        }
        public void AllowTypeDiscoveryBehaviour()
        {
            var context = new FudgeContext();
            var map = new SerializationTypeMap(context);

            map.AllowTypeDiscovery = false;
            Assert.Null(map.GetSurrogate(typeof(Reflect.Tick)));
            Assert.Equal(-1, map.GetTypeId(typeof(Reflect.Tick)));

            map.AllowTypeDiscovery = true;
            Assert.NotNull(map.GetSurrogate(typeof(Reflect.Tick)));
            Assert.NotEqual(-1, map.GetTypeId(typeof(Reflect.Person)));
        }
        /// <summary>
        /// Constructs a new <see cref="FudgeSerializer"/> instance.
        /// </summary>
        /// <param name="context"><see cref="FudgeContext"/> for the serializer.</param>
        /// <param name="typeMap">Typemap to use rather than creating a default one.</param>
        public FudgeSerializer(FudgeContext context, SerializationTypeMap typeMap)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (typeMap == null)
            {
                // REVIEW 2010-02-02 t0rx -- Have serialization type map as context property?
                typeMap = new SerializationTypeMap(context);
            }

            this.context = context;
            this.typeMap = typeMap;

            this.TypeMappingStrategy = (IFudgeTypeMappingStrategy)context.GetProperty(ContextProperties.TypeMappingStrategyProperty, new DefaultTypeMappingStrategy());
        }
        public void CircularReference()
        {
            var typeMap = new SerializationTypeMap(context);
            typeMap.RegisterType(typeof(Explicit.Sibling));
            typeMap.RegisterType(typeof(Explicit.Address), new Explicit.AddressSerializer());
            var serializer = new FudgeSerializer(context, typeMap);

            var bob = new Explicit.Sibling { Name = "Bob" };
            var shirley = new Explicit.Sibling { Name = "Shirley" };
            bob.Siblings.Add(shirley);
            shirley.Siblings.Add(bob);                          // Create our cycle

            var msg = serializer.SerializeToMsg(bob);

            var bob2 = (Explicit.Sibling)serializer.Deserialize(msg);
            Assert.NotSame(bob, bob2);
            Assert.Equal(1, bob2.Siblings.Count);
            var shirley2 = (Explicit.Sibling)bob2.Siblings[0];
            Assert.NotSame(shirley, shirley2);
            Assert.Equal(1, shirley2.Siblings.Count);
            Assert.Same(bob2, shirley2.Siblings[0]);
        }
        public void SimpleExampleWithSurrogate()
        {
            var typeMap = new SerializationTypeMap(context);
            typeMap.RegisterType(typeof(Explicit.Address), new Explicit.AddressSerializer());
            var serializer = new FudgeSerializer(context, typeMap);

            var address = new Explicit.Address("Our House", "In the middle of our street", "MD1");
            var msg = serializer.SerializeToMsg(address);

            var address2 = (Explicit.Address)serializer.Deserialize(msg);

            Assert.Equal(address.Line1, address2.Line1);
            Assert.Equal(address.Line2, address2.Line2);
            Assert.Equal(address.Zip, address2.Zip);
        }
        public void SimpleExampleWithIFudgeSerializable()
        {
            var typeMap = new SerializationTypeMap(context);
            typeMap.RegisterType(typeof(Explicit.Tick));
            var serializer = new FudgeSerializer(context, typeMap);

            var tick = new Explicit.Tick { Ticker = "FOO", Bid = 12.3, Offer = 12.9 };
            var msg = serializer.SerializeToMsg(tick);

            var tick2 = (Explicit.Tick)serializer.Deserialize(msg);

            Assert.Equal(tick.Ticker, tick2.Ticker);
            Assert.Equal(tick.Bid, tick2.Bid);
            Assert.Equal(tick.Offer, tick2.Offer);
        }
        public void ReferencedObject()
        {
            var typeMap = new SerializationTypeMap(context);
            typeMap.RegisterType(typeof(Explicit.Sibling));
            typeMap.RegisterType(typeof(Explicit.Address), new Explicit.AddressSerializer());
            var serializer = new FudgeSerializer(context, typeMap);

            var bob = new Explicit.Sibling { Name = "Bob" };
            var shirley = new Explicit.Sibling { Name = "Shirley" };
            bob.Siblings.Add(shirley);                          // We don't reciprocate yet as that would generate a cycle

            var msg = serializer.SerializeToMsg(bob);

            var bob2 = (Explicit.Sibling)serializer.Deserialize(msg);
            Assert.NotSame(bob, bob2);
            Assert.Equal(1, bob2.Siblings.Count);
            Assert.NotSame(shirley, bob2.Siblings[0]);
            Assert.Equal("Shirley", bob2.Siblings[0].Name);
        }
        public void InlineObject()
        {
            var typeMap = new SerializationTypeMap(context);
            typeMap.RegisterType(typeof(Explicit.Person));
            typeMap.RegisterType(typeof(Explicit.Address), new Explicit.AddressSerializer());
            var serializer = new FudgeSerializer(context, typeMap);

            var person = new Explicit.Person { Name = "Bob", MainAddress = new Explicit.Address("Foo", "Bar", null) };
            var msg = serializer.SerializeToMsg(person);

            var person2 = (Explicit.Person)serializer.Deserialize(msg);
            Assert.NotSame(person.MainAddress, person2.MainAddress);
            Assert.Equal(person.MainAddress.Line1, person2.MainAddress.Line1);
        }
 private StreamingFudgeDeserializationContext(FudgeContext context, SerializationTypeMap typeMap, IFudgeTypeMappingStrategy typeMappingStrategy, FudgeStreamReaderMsgWriter msgWriter)
     : base(context, typeMap, typeMappingStrategy, msgWriter.Map)
 {
     this.msgWriter = msgWriter;
     msgWriter.DeserializationContext = this;
 }
 public StreamingFudgeDeserializationContext(FudgeContext context, SerializationTypeMap typeMap, IFudgeStreamReader reader, IFudgeTypeMappingStrategy typeMappingStrategy)
     : this(context, typeMap, typeMappingStrategy, new FudgeStreamReaderMsgWriter(context, reader))
 {
 }
 public ReaderFudgeDeserializationContext(FudgeContext context, SerializationTypeMap typeMap, IFudgeStreamReader reader, IFudgeTypeMappingStrategy typeMappingStrategy)
     : base(context, typeMap, typeMappingStrategy)
 {
     this.msgWriter = new FudgeMsgStreamWriter(context);
     this.pipe = new FudgeStreamPipe(reader, msgWriter);
 }
Example #14
0
 private StreamingFudgeDeserializationContext(FudgeContext context, SerializationTypeMap typeMap, IFudgeTypeMappingStrategy typeMappingStrategy, FudgeStreamReaderMsgWriter msgWriter)
     : base(context, typeMap, typeMappingStrategy, msgWriter.Map)
 {
     this.msgWriter = msgWriter;
     msgWriter.DeserializationContext = this;
 }
Example #15
0
 public StreamingFudgeDeserializationContext(FudgeContext context, SerializationTypeMap typeMap, IFudgeStreamReader reader, IFudgeTypeMappingStrategy typeMappingStrategy)
     : this(context, typeMap, typeMappingStrategy, new FudgeStreamReaderMsgWriter(context, reader))
 {
 }
 public ReaderFudgeDeserializationContext(FudgeContext context, SerializationTypeMap typeMap, IFudgeStreamReader reader, IFudgeTypeMappingStrategy typeMappingStrategy)
     : base(context, typeMap, typeMappingStrategy)
 {
     this.msgWriter = new FudgeMsgStreamWriter(context);
     this.pipe      = new FudgeStreamPipe(reader, msgWriter);
 }