示例#1
0
        public DotNetSerializableCodec(
            IFieldCodec <Type> typeCodec,
            IFieldCodec <string> stringCodec,
            IFieldCodec <object> objectCodec,
            IUntypedCodecProvider untypedCodecProvider)
        {
            this.typeCodec            = typeCodec;
            this.untypedCodecProvider = untypedCodecProvider;
            var entrySerializer        = new SerializationEntryCodec(stringCodec, objectCodec);
            var constructorFactory     = new SerializationConstructorFactory();
            var serializationCallbacks = new SerializationCallbacksFactory();
            var formatterConverter     = new FormatterConverter();

            this.objectSerializer = new ObjectSerializer(
                entrySerializer,
                constructorFactory,
                serializationCallbacks,
                formatterConverter,
                this.streamingContext);

            this.valueTypeSerializerFactory = new ValueTypeSerializerFactory(
                entrySerializer,
                constructorFactory,
                serializationCallbacks,
                formatterConverter,
                this.streamingContext);
        }
示例#2
0
 public ListCodec(IFieldCodec <T> fieldCodec, IFieldCodec <int> intCodec, IUntypedCodecProvider codecProvider, ListActivator <T> activator)
 {
     this.fieldCodec    = fieldCodec;
     this.intCodec      = intCodec;
     this.codecProvider = codecProvider;
     this.activator     = activator;
 }
示例#3
0
 public DictionaryCodec(
     IFieldCodec <KeyValuePair <TKey, TValue> > pairCodec,
     IUntypedCodecProvider codecProvider,
     IFieldCodec <IEqualityComparer <TKey> > comparerCodec,
     DictionaryActivator <TKey, TValue> activator)
 {
     this.pairCodec     = pairCodec;
     this.codecProvider = codecProvider;
     this.comparerCodec = comparerCodec;
     this.activator     = activator;
 }
示例#4
0
 public JsonCodec(
     IUntypedCodecProvider codecProvider,
     JsonSerializerSettings settings   = null,
     Func <Type, bool> isSupportedFunc = null)
 {
     this.codecProvider = codecProvider;
     this.settings      = settings ?? new JsonSerializerSettings
     {
         TypeNameHandling = TypeNameHandling.All,
         TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Full
     };
     this.isSupportedFunc = isSupportedFunc ?? (_ => true);
 }
示例#5
0
        private static object DeserializeFromMarker(
            Reader reader,
            SerializerSession session,
            Field field,
            IUntypedCodecProvider serializers,
            UnknownFieldMarker marker,
            uint reference,
            Type lastResortFieldType)
        {
            // Create a reader at the position specified by the marker.
            var referencedReader = new Reader(reader.GetBuffers());

            referencedReader.Advance(marker.Offset);

            // Determine the correct type for the field.
            var fieldType = marker.Field.FieldType ?? field.FieldType ?? lastResortFieldType;

            // Get a serializer for that type.
            var specificSerializer = serializers.GetCodec(fieldType);

            // Reset the session's reference id so that the deserialized object overwrites the marker.
            var originalCurrentReferenceId = session.ReferencedObjects.CurrentReferenceId;

            session.ReferencedObjects.CurrentReferenceId = reference - 1;

            // Deserialize the object, replacing the marker in the session.
            try
            {
                return(specificSerializer.ReadValue(referencedReader, session, marker.Field));
            }
            finally
            {
                // Revert the reference id.
                session.ReferencedObjects.CurrentReferenceId = originalCurrentReferenceId;
            }
        }
示例#6
0
 public AbstractTypeSerializer(IUntypedCodecProvider codecProvider)
 {
     this.codecProvider = codecProvider;
 }
示例#7
0
 public JsonCodec(IUntypedCodecProvider codecProvider) : this(codecProvider, null, null)
 {
 }
示例#8
0
 public ArrayCodec(IFieldCodec <T> fieldCodec, IFieldCodec <int> intCodec, IUntypedCodecProvider codecProvider)
 {
     this.fieldCodec    = fieldCodec;
     this.intCodec      = intCodec;
     this.codecProvider = codecProvider;
 }
示例#9
0
        public static object ReadReference(Reader reader, SerializerSession session, Field field, IUntypedCodecProvider serializers, Type expectedType)
        {
            var reference = reader.ReadVarUInt32();

            if (!session.ReferencedObjects.TryGetReferencedObject(reference, out object value))
            {
                ThrowReferenceNotFound(expectedType, reference);
            }

            switch (value)
            {
            case UnknownFieldMarker marker:
                return(DeserializeFromMarker(reader, session, field, serializers, marker, reference, expectedType));

            default:
                return(value);
            }
        }
示例#10
0
 public static T ReadReference <T>(Reader reader, SerializerSession session, Field field, IUntypedCodecProvider serializers)
 {
     return((T)ReadReference(reader, session, field, serializers, typeof(T)));
 }
示例#11
0
 public ObjectCodec(IUntypedCodecProvider codecProvider)
 {
     this.codecProvider = codecProvider;
 }
示例#12
0
 public ConcreteTypeSerializer(IActivator <TField> activator, IUntypedCodecProvider codecProvider, IPartialSerializerProvider partialSerializerProvider)
 {
     this.activator     = activator;
     this.codecProvider = codecProvider;
     this.serializer    = partialSerializerProvider.GetPartialSerializer <TField>();
 }
示例#13
0
 public TypeSerializerCodec(IUntypedCodecProvider codecProvider)
 {
     this.codecProvider = codecProvider;
 }
示例#14
0
 public StringCodec(IUntypedCodecProvider codecProvider)
 {
     this.codecProvider = codecProvider;
 }
示例#15
0
 public MultiDimensionalArrayCodec(IUntypedCodecProvider codecProvider, IFieldCodec <int[]> intArrayCodec, IFieldCodec <T> elementCodec)
 {
     this.codecProvider = codecProvider;
     this.intArrayCodec = intArrayCodec;
     this.elementCodec  = elementCodec;
 }
示例#16
0
 public ByteArrayCodec(IUntypedCodecProvider codecProvider)
 {
     this.codecProvider = codecProvider;
 }