Пример #1
0
        public static byte[] SerializeObject <T>(T obj, bool structureParity = false, bool compression = false, bool PadRight = false, int PadAmount = 0)
        {
            BoolManager.Reset();
            int         index = 0;
            List <byte> ion   = ToION(obj, ref index);

            BoolManager.UpdateBools(ref ion);
            if (structureParity)
            {
                string parityStr = Parity(typeof(T));
                ion.InsertRange(0, parityStr.StringToByte());
            }

            byte[] ionBytes = ion.ToArray();
            if (PadRight)
            {
                ionBytes = ionBytes.PadRight(PadAmount);
            }
            if (compression)
            {
                ICompress compressor = new DefaultCompression();
                ionBytes = compressor.Compress(ionBytes);
            }
            return(ionBytes);
        }
Пример #2
0
        public static T DeserializeObject <T>(byte[] ion, bool structureParity = false, bool compression = false)
        {
            if (compression)
            {
                ICompress compressor = new DefaultCompression();
                ion = compressor.Decompress(ion);
            }
            BoolManager.Reset();
            int index = 0;

            if (structureParity)
            {
                string parityStr     = Parity(typeof(T));
                string sentParityStr = ion.ByteToString(0, 64);

                if (parityStr != sentParityStr)
                {
                    throw new ParityException();
                }
                index = 64;
            }
            return(FromION <T>(ion, ref index));
        }