public override void streamWriteFunc(Stopwatch sw)
        {
            base.binaryWritedValue = base.serializedValue;

            sw.Start();

            MemoryStream ms = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(ms);

            if (WriteArrayHeader16(bw, base.binaryWritedValue.nullsv1))
            {
                foreach (var item in base.binaryWritedValue.nullsv1)
                {
                    StringStruct.WriteString16(bw, item);
                }
            }

            if (WriteArrayHeader32(bw, base.binaryWritedValue.nullia32))
            {
                foreach (var item in base.binaryWritedValue.nullia32)
                {
                    bw.Write(item);
                }
            }

            if (WriteArrayHeader16(bw, base.binaryWritedValue.emptysv1))
            {
                foreach (var item in base.binaryWritedValue.emptysv1)
                {
                    StringStruct.WriteString16(bw, item);
                }
            }

            if (WriteArrayHeader32(bw, base.binaryWritedValue.emptyia32))
            {
                foreach (var item in base.binaryWritedValue.emptyia32)
                {
                    bw.Write(item);
                }
            }

            if (WriteArrayHeader16(bw, base.binaryWritedValue.fa32))
            {
                foreach (var item in base.binaryWritedValue.fa32)
                {
                    bw.Write(item);
                }
            }

            if (WriteArrayHeader16(bw, base.binaryWritedValue.sv1))
            {
                foreach (var item in base.binaryWritedValue.sv1)
                {
                    StringStruct.WriteString16(bw, item);
                }
            }

            if (WriteArrayHeader32(bw, base.binaryWritedValue.ia32))
            {
                foreach (var item in base.binaryWritedValue.ia32)
                {
                    bw.Write(item);
                }
            }

            if (WriteArrayHeader16(bw, base.binaryWritedValue.isa))
            {
                foreach (var item in base.binaryWritedValue.isa)
                {
                    IntegerStruct.Write(bw, item);
                }
            }

            sw.Stop();

            base.streamWriteBuffer = ms.ToArray();
        }
        public override void streamReadFunc(Stopwatch sw)
        {
            sw.Start();

            MemoryStream ms = new MemoryStream(base.streamWriteBuffer);
            BinaryReader br = new BinaryReader(ms);

            var r = new ArrayStruct();

            // nullsv1, int16
            var ex16 = ReadArrayHeader16(br);

            if (ex16.Item1)
            {
                r.nullsv1 = new string[ex16.Item2];
                for (int i = 0; i < ex16.Item2; i++)
                {
                    r.nullsv1[i] = StringStruct.ReadString16(br);
                }
            }

            //nullia32, int32
            var ex32 = ReadArrayHeader32(br);

            if (ex32.Item1)
            {
                r.nullia32 = new int[ex32.Item2];

                for (int i = 0; i < ex32.Item2; i++)
                {
                    r.nullia32[i] = br.ReadInt32();
                }
            }

            //emptysv1, int16
            ex16 = ReadArrayHeader16(br);

            if (ex16.Item1)
            {
                r.emptysv1 = new string[ex16.Item2];
                for (int i = 0; i < ex16.Item2; i++)
                {
                    r.emptysv1[i] = StringStruct.ReadString16(br);
                }
            }

            //emptyia32, int32
            ex32 = ReadArrayHeader32(br);

            if (ex32.Item1)
            {
                r.emptyia32 = new int[ex32.Item2];

                for (int i = 0; i < ex32.Item2; i++)
                {
                    r.emptyia32[i] = br.ReadInt32();
                }
            }

            //fa32, int16
            ex16 = ReadArrayHeader16(br);

            if (ex16.Item1)
            {
                r.fa32 = new float[ex16.Item2];
                for (int i = 0; i < ex16.Item2; i++)
                {
                    r.fa32[i] = br.ReadSingle();
                }
            }

            //sv1, int16
            ex16 = ReadArrayHeader16(br);

            if (ex16.Item1)
            {
                r.sv1 = new string[ex16.Item2];
                for (int i = 0; i < ex16.Item2; i++)
                {
                    r.sv1[i] = StringStruct.ReadString16(br);
                }
            }

            ex32 = ReadArrayHeader32(br);

            if (ex32.Item1)
            {
                r.ia32 = new int[ex32.Item2];
                for (int i = 0; i < ex32.Item2; i++)
                {
                    r.ia32[i] = br.ReadInt32();
                }
            }

            ex16 = ReadArrayHeader16(br);

            if (ex16.Item1)
            {
                r.isa = new IntegerStruct[ex16.Item2];
                for (int i = 0; i < ex16.Item2; i++)
                {
                    r.isa[i] = IntegerStruct.Read(br);
                }
            }

            sw.Stop();

            base.binaryReadedValue = r;
        }
Exemple #3
0
        static void Main(string[] args)
        {
            DebugTemp.TStruct.Debug();

            Test t = new Test();

            BinarySerializer.TypeStorage.Instance.PreCompileBinaryStructs(Assembly.GetExecutingAssembly());

            Structs.StringStruct     _ss = new Structs.StringStruct();
            Structs.IntegerStruct    _is = new Structs.IntegerStruct();
            Structs.FloatStruct      _fs = new Structs.FloatStruct();
            Structs.ArrayStruct      _as = new Structs.ArrayStruct();
            Structs.ListStruct       _ls = new Structs.ListStruct();
            Structs.DictionaryStruct _ds = new Structs.DictionaryStruct();
            Structs.OtherStruct      _os = new Structs.OtherStruct();

            int iteration = 1000;

            Console.WriteLine("BinarySerializer");
            t.Run(iteration, "Integer Serialize", _is.bsSerializeAction);
            t.Run(iteration, "Integer Desserialize", _is.bsDesserializeAction);

            Console.WriteLine();
            Console.WriteLine("Stream");
            t.Run(iteration, "Integer Write", _is.streamWriteFunc);
            t.Run(iteration, "Integer Read", _is.streamReadFunc);

            _is.Compare();


            Console.WriteLine();
            Console.WriteLine("BinarySerializer");
            t.Run(iteration, "Float Serialize", _fs.bsSerializeAction);
            t.Run(iteration, "Float Desserialize", _fs.bsDesserializeAction);

            Console.WriteLine();
            Console.WriteLine("Stream");
            t.Run(iteration, "Float Write", _fs.streamWriteFunc);
            t.Run(iteration, "Float Read", _fs.streamReadFunc);

            _fs.Compare();

            Console.WriteLine();
            Console.WriteLine("BinarySerializer");
            t.Run(iteration, "String Serialize", _ss.bsSerializeAction);
            t.Run(iteration, "String Desserialize", _ss.bsDesserializeAction);

            Console.WriteLine();
            Console.WriteLine("Stream");
            t.Run(iteration, "String Write", _ss.streamWriteFunc);
            t.Run(iteration, "String Read", _ss.streamReadFunc);

            _ss.Compare();

            Console.WriteLine();
            Console.WriteLine("BinarySerializer");

            t.Run(iteration, "Array Serialize", _as.bsSerializeAction);
            t.Run(iteration, "Array Desserialize", _as.bsDesserializeAction);

            Console.WriteLine();
            Console.WriteLine("Stream");
            t.Run(iteration, "Array Write", _as.streamWriteFunc);
            t.Run(iteration, "Array Read", _as.streamReadFunc);

            _as.Compare();

            Console.WriteLine();
            Console.WriteLine("BinarySerializer");

            t.Run(iteration, "List Serialize", _ls.bsSerializeAction);
            t.Run(iteration, "List Desserialize", _ls.bsDesserializeAction);

            Console.WriteLine();
            Console.WriteLine("Stream");
            t.Run(iteration, "List Write", _ls.streamWriteFunc);
            t.Run(iteration, "List Read", _ls.streamReadFunc);

            _ls.Compare();

            Console.WriteLine();
            Console.WriteLine("BinarySerializer");

            t.Run(iteration, "Dictionary Serialize", _ds.bsSerializeAction);
            t.Run(iteration, "Dictionary Desserialize", _ds.bsDesserializeAction);

            Console.WriteLine();
            Console.WriteLine("Stream");
            t.Run(iteration, "Dictionary Write", _ds.streamWriteFunc);
            t.Run(iteration, "Dictionary Read", _ds.streamReadFunc);

            _ds.Compare();

            Console.WriteLine();
            Console.WriteLine("BinarySerializer");

            t.Run(iteration, "Other Serialize", _os.bsSerializeAction);
            t.Run(iteration, "Other Desserialize", _os.bsDesserializeAction);

            Console.WriteLine();
            Console.WriteLine("Stream");
            t.Run(iteration, "Other Write", _os.streamWriteFunc);
            t.Run(iteration, "Other Read", _os.streamReadFunc);

            _os.Compare();

            Console.ReadKey();
        }