示例#1
0
        public static byte[] CallV2(int cmd, FDataExtraHandle dataExtra, params object[] args)
        {
            AutoBuffer buffer = new AutoBuffer()
            {
                Args = new List <byte[]>(args.Length)
            };


            foreach (var item in args)
            {
                Type type = item.GetType();

                buffer.Args.Add(PackSingleObject(type, item));
            }


            using (MemoryStream stream = new MemoryStream())
            {
                BinaryWriter bufflist = new BinaryWriter(stream);

                bufflist.Write(BufferFormatV2.GetBytes(cmd));

                byte[] classdata = BufferFormatV2.SerializeObject(buffer);
                bufflist.Write(BufferFormatV2.GetBytes(classdata.Length));
                bufflist.Write(classdata);


                byte[] fdata = null;

                if (dataExtra != null)
                {
                    fdata = dataExtra(stream.ToArray());
                }
                else
                {
                    fdata = stream.ToArray();
                }

                stream.Position = 0;
                stream.SetLength(0);



                int x = fdata.Length;

                if ((fdata.Length + 1) < 128)
                {
                    x += 1;
                }
                else if ((fdata.Length + 2) < 16384)
                {
                    x += 2;
                }
                else if ((fdata.Length + 3) < 2097152)
                {
                    x += 3;
                }
                else
                {
                    x += 4;
                }

                byte[] tmp = BufferFormatV2.GetBytes(x);

                int l = fdata.Length + tmp.Length;

                byte[] data = BufferFormatV2.GetBytes(l);

                bufflist.Write((byte)0xFF);
                bufflist.Write(data);
                bufflist.Write(fdata);

                byte[] pdata = stream.ToArray();
                stream.Dispose();
                return(pdata);
            }
        }