Пример #1
0
        public void Read(ref Package pkg)
        {
            lock (locker)
            {
                byte[] bytes = new byte[4];

                fs.Read(bytes, 0, 4);
                var ol = BitConverter.ToInt32(bytes);
                fs.Read(bytes, 0, bytes.Length);
                var cl = BitConverter.ToInt32(bytes);

                pkg.originBytes  = SharedMemory.Rent(ol);
                pkg.originLength = ol;
                pkg.codedBytes   = SharedMemory.Rent(cl);
                pkg.codedLength  = cl;

                fs.Read(pkg.codedBytes, 0, pkg.codedLength);
            }
        }
Пример #2
0
        //static byte[] b1 = new byte[1024 * 1024 * 10];
        //static byte[] b2 = new byte[1024 * 1024 * 3];

        public static void GetBytes(ref Package pkg)
        {
            // 后期如果加入 pkg 的 header 与 tailer 就在此处修改
            pkg.originLength = pkg.msgsAsBytesLength;

            pkg.originBytes = SharedMemory.Rent(pkg.originLength);
            //pkg.originBytes = b1;

            int offset = 0;

            foreach (var msg in pkg.GetMessages())
            {
                CopyMsgToArray(msg, pkg.originBytes, ref offset);
            }

            // 部分短数据压缩后反而会更长
            pkg.codedBytes = SharedMemory.Rent(pkg.originLength + 100);
            //pkg.codedBytes = b2;

            Compress(pkg.originBytes, pkg.originLength, ref pkg.codedBytes, ref pkg.codedLength);
        }