public static object DeserializeObject(byte[] buf, Type type, SerializerSettings settings)
 {
     using (MemoryStream ms = new MemoryStream(buf))
     {
         using (BinaryTypesReader br = new BinaryTypesReader(ms))
         {
             return(DeserializeObject(br, type, settings, null, null));
         }
     }
 }
        //===============================================================================================
        // Serialize
        //===============================================================================================

        public static byte[] SerializeObject <T>(T value, SerializerSettings settings)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryTypesWriter bw = new BinaryTypesWriter(ms))
                {
                    SerializeObject(typeof(T), value, bw, settings, null, null);
                    return(ms.ToArray());
                }
            }
        }
        internal static object DeserializeObject(BinaryTypesReader br, Type type, SerializerSettings settings, ISerializer serializer, ISerializerArg serializerArg)
        {
            serializer = GetSerializer(type, serializer);
            if (serializer == null)
            {
                throw new Exception($"SerializeObject: serializer not found for type {type.FullName}");
            }

            if (type.IsClass && serializer.CommonNullHandle)
            {
                if (br.ReadBoolean() == false) //null
                {
                    return(null);
                }
            }

            return(serializer.Deserialize(br, type, settings, serializerArg));
        }
        //===============================================================================================
        // Deserialize
        //===============================================================================================


        public static T DeserializeObject <T>(byte[] buf, SerializerSettings settings)
        {
            return((T)DeserializeObject(buf, typeof(T), settings));
        }
        internal static void SerializeObject <T>(Type type, T value, BinaryTypesWriter bw, SerializerSettings settings, ISerializer serializer, ISerializerArg serializerArg)
        {
            serializer = GetSerializer(type, serializer);
            if (serializer == null)
            {
                throw new Exception($"SerializeObject: serializer not found for type {type.FullName}");
            }

            if (type.IsClass && serializer.CommonNullHandle)
            {
                bw.Write(value != null);
                if (value == null)
                {
                    return;
                }
            }

            serializer.Serialize(bw, type, settings, serializerArg, value);
        }
Exemple #6
0
 public static T DeserializeObject <T>(byte[] buf, SerializerSettings settings = null)
 {
     return(Serializer.DeserializeObject <T>(buf, settings));
 }
Exemple #7
0
 public static byte[] SerializeObject <T>(T value, SerializerSettings settings = null)
 {
     return(Serializer.SerializeObject(value, settings));
 }
Exemple #8
0
 public static object DeserializeObject(Type type, byte[] buf, SerializerSettings settings = null)
 {
     return(Serializer.DeserializeObject(buf, type, settings));
 }