Beispiel #1
0
 public override void WriteValue(Stream stream, object value, SerializerSession session)
 {
     if (value == null)
     {
         StringSerializer.WriteValueImpl(stream, null, session);
     }
     else
     {
         var type = (Type)value;
         int existingId;
         if (session.Serializer.Options.PreserveObjectReferences && session.TryGetObjectId(type, out existingId))
         {
             ObjectReferenceSerializer.Instance.WriteManifest(stream, session);
             ObjectReferenceSerializer.Instance.WriteValue(stream, existingId, session);
         }
         else
         {
             if (session.Serializer.Options.PreserveObjectReferences)
             {
                 session.TrackSerializedObject(type);
             }
             //type was not written before, add it to the tacked object list
             var name = type.GetShortAssemblyQualifiedName();
             StringSerializer.WriteValueImpl(stream, name, session);
         }
     }
 }
Beispiel #2
0
 public override void WriteValue(Stream stream, object value, SerializerSession session)
 {
     if (value == null)
     {
         stream.WriteInt32(-1);
     }
     else
     {
         var type = (Type)value;
         int existingId;
         if (session.Serializer.Options.PreserveObjectReferences && session.TryGetObjectId(type, out existingId))
         {
             ObjectReferenceSerializer.Instance.WriteManifest(stream, null, session);
             ObjectReferenceSerializer.Instance.WriteValue(stream, existingId, session);
         }
         else
         {
             //type was not written before, add it to the tacked object list
             var name = type.GetShortAssemblyQualifiedName();
             if (session.Serializer.Options.PreserveObjectReferences)
             {
                 session.TrackSerializedObject(type);
             }
             // ReSharper disable once PossibleNullReferenceException
             // ReSharper disable once AssignNullToNotNullAttribute
             var bytes = Encoding.UTF8.GetBytes(name);
             stream.WriteLengthEncodedByteArray(bytes);
         }
     }
 }
Beispiel #3
0
 public override void WriteValue(Stream stream, object value, SerializerSession session)
 {
     if (value == null)
     {
         StringSerializer.WriteValueImpl(stream,null,session);
     }
     else
     {
         var type = (Type) value;
         int existingId;
         if (session.Serializer.Options.PreserveObjectReferences && session.TryGetObjectId(type, out existingId))
         {
             ObjectReferenceSerializer.Instance.WriteManifest(stream, session);
             ObjectReferenceSerializer.Instance.WriteValue(stream, existingId, session);
         }
         else
         {
             if (session.Serializer.Options.PreserveObjectReferences)
             {
                 session.TrackSerializedObject(type);
             }
             //type was not written before, add it to the tacked object list
             var name = type.GetShortAssemblyQualifiedName();
             StringSerializer.WriteValueImpl(stream, name, session);
         }
     }
 }
Beispiel #4
0
 public override void WriteValue(Stream stream, object value, SerializerSession session)
 {
     if (value == null)
     {
         stream.WriteInt32(-1);
     }
     else
     {
         var type = (Type) value;
         int existingId;
         if (session.Serializer.Options.PreserveObjectReferences && session.TryGetObjectId(type, out existingId))
         {
             ObjectReferenceSerializer.Instance.WriteManifest(stream, null, session);
             ObjectReferenceSerializer.Instance.WriteValue(stream, existingId, session);
         }
         else
         { 
             //type was not written before, add it to the tacked object list
             var name = type.GetShortAssemblyQualifiedName();
             if (session.Serializer.Options.PreserveObjectReferences)
             {
                 session.TrackSerializedObject(type);
             }
             // ReSharper disable once PossibleNullReferenceException
             // ReSharper disable once AssignNullToNotNullAttribute
             var bytes = Encoding.UTF8.GetBytes(name);
             stream.WriteLengthEncodedByteArray(bytes);
         }
     }
 }
 public override void WriteValue(Stream stream, object value, SerializerSession session)
 {
     if (value == null)
     {
         stream.WriteLengthEncodedByteArray(EmptyArray <byte> .Instance, session);
     }
     else
     {
         var type = (Type)value;
         if (session.Serializer.Options.PreserveObjectReferences && session.TryGetObjectId(type, out int existingId))
         {
             ObjectReferenceSerializer.Instance.WriteManifest(stream, session);
             ObjectReferenceSerializer.Instance.WriteValue(stream, existingId, session);
         }
         else
         {
             if (session.Serializer.Options.PreserveObjectReferences)
             {
                 session.TrackSerializedObject(type);
             }
             //type was not written before, add it to the tacked object list
             var typeKey = AntTypeSerializer.GetTypeKeyFromType(type);
             stream.WriteLengthEncodedByteArray(typeKey.TypeName, session);
             Int32Serializer.WriteValueImpl(stream, typeKey.HashCode, session);
         }
     }
 }
            static void Writer(Stream stream, object o, SerializerSession session)
            {
                session.TrackSerializedObject(o);
                var pid = (PID)o;

                StringSerializer.WriteValueImpl(stream, pid.Address, session);
                StringSerializer.WriteValueImpl(stream, pid.Id, session);
            }
        public override void WriteValue(Stream stream, object value, SerializerSession session)
        {
            var bytes = (byte[])value;

            stream.WriteLengthEncodedByteArray(bytes, session);

            if (session.Serializer.Options.PreserveObjectReferences)
            {
                session.TrackSerializedObject(bytes);
            }
        }
Beispiel #8
0
        public override void WriteValue(Stream stream, object value, SerializerSession session)
        {
            if (session.Serializer.Options.PreserveObjectReferences)
            {
                session.TrackSerializedObject(value);
            }
            var elementType       = value.GetType().GetElementType();
            var elementSerializer = session.Serializer.GetSerializerByType(elementType);

            elementSerializer.WriteManifest(stream, session); //write array element type
            // ReSharper disable once PossibleNullReferenceException
            WriteValues((dynamic)value, stream, elementSerializer, session);
        }
Beispiel #9
0
 private static void WriteHashSet <T>(HashSet <T> set, Stream stream, SerializerSession session, Type elementType,
                                      ValueSerializer elementSerializer, bool preserveObjectReferences)
 {
     if (preserveObjectReferences)
     {
         session.TrackSerializedObject(set);
     }
     // ReSharper disable once PossibleNullReferenceException
     Int32Serializer.WriteValueImpl(stream, set.Count, session);
     foreach (var item in set)
     {
         stream.WriteObject(item, elementType, elementSerializer, preserveObjectReferences, session);
     }
 }
Beispiel #10
0
        private static void WriteValues <T>(LinkedList <T> llist, Stream stream, Type elementType, ValueSerializer elementSerializer,
                                            SerializerSession session, bool preserveObjectReferences)
        {
            if (preserveObjectReferences)
            {
                session.TrackSerializedObject(llist);
            }

            Int32Serializer.WriteValueImpl(stream, llist.Count, session);
            foreach (var value in llist)
            {
                stream.WriteObject(value, elementType, elementSerializer, preserveObjectReferences, session);
            }
        }
Beispiel #11
0
        private static void WriteValues <T>(T[] array, Stream stream, Type elementType, ValueSerializer elementSerializer,
                                            SerializerSession session, bool preserveObjectReferences)
        {
            if (preserveObjectReferences)
            {
                session.TrackSerializedObject(array);
            }

            Int32Serializer.WriteValueImpl(stream, array.Length, session);
            foreach (var value in array)
            {
                stream.WriteObject(value, elementType, elementSerializer, preserveObjectReferences, session);
            }
        }