Beispiel #1
0
        public static T Deserialize <T>(Stream stream)
        {
            var dataInfo = SerializeTypeInfo.ReadFromStream <T>(stream);
            var refInfo  = SerializeTypeInfo.Parse <T>();

            if (!refInfo.Verify(dataInfo))
            {
                throw new Exception("Invalid type info");
            }
            return(ReadData <T>(stream, refInfo));
        }
Beispiel #2
0
        public static byte[] Serialize <T>(T t, bool extraInfo = false)
        {
            var stream   = new MemoryStream();
            var dataInfo = SerializeTypeInfo.Parse(t);

            dataInfo.WriteToStream(stream, extraInfo);
            //WriteData

            WriteData(stream, t, dataInfo);

            return(stream.ToArray());
        }
        public static SerializeTypeInfo ReadFromStream <T>(Stream s)
        {
            var typeDataInfo = SerializeTypeInfo.Parse <T>();

            var deserializeDataInfo = ReadFromStream(s);

            if (!typeDataInfo.Verify(deserializeDataInfo))
            {
                throw new Exception("type verify failed!");
            }

            return(deserializeDataInfo);
        }