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);
         }
     }
 }
Пример #2
0
        public override void WriteValue(Stream stream, object value, SerializerSession session)
        {
            var bytes = session.GetBuffer(Int32Serializer.Size);

            var data = decimal.GetBits((decimal)value);

            Int32Serializer.WriteValueImpl(stream, data[0], bytes);
            Int32Serializer.WriteValueImpl(stream, data[1], bytes);
            Int32Serializer.WriteValueImpl(stream, data[2], bytes);
            Int32Serializer.WriteValueImpl(stream, data[3], bytes);
        }
Пример #3
0
 private static void WriteValues <T>(T[] array, Stream stream, ValueSerializer elementSerializer, SerializerSession session)
 {
     Int32Serializer.WriteValueImpl(stream, array.Length, session);
     if (typeof(T).IsFixedSizeType())
     {
         var size   = typeof(T).GetTypeSize();
         var result = new byte[array.Length * size];
         Buffer.BlockCopy(array, 0, result, 0, result.Length);
         stream.Write(result);
     }
     else
     {
         foreach (var value in array)
         {
             elementSerializer.WriteValue(stream, value, session);
         }
     }
 }
Пример #4
0
        public override object ReadValue(Stream stream, DeserializerSession session)
        {
            var bytes = session.GetBuffer(Int32Serializer.Size);

            var parts = new[]
            {
                Int32Serializer.ReadValueImpl(stream, bytes),
                Int32Serializer.ReadValueImpl(stream, bytes),
                Int32Serializer.ReadValueImpl(stream, bytes),
                Int32Serializer.ReadValueImpl(stream, bytes)
            };
            var sign = (parts[3] & 0x80000000) != 0;

            var scale    = (byte)((parts[3] >> 16) & 0x7F);
            var newValue = new decimal(parts[0], parts[1], parts[2], sign, scale);

            return(newValue);
        }
 public override void WriteValue(Stream stream, object value, SerializerSession session)
 {
     Int32Serializer.WriteValueImpl(stream, (int)value, session);
 }