Exemplo n.º 1
0
        private Octets Update(Octets oin)
        {
            var  oout = new Octets();
            uint ipos = 0, opos = 0;

            byte[] ibuf   = oin.ByteArray;
            var    isize  = (uint)oin.Count;
            uint   remain = (uint)Mppc.MppcHistLen - _histptr - _legacyIn;

            if (isize >= remain)
            {
                oout.Resize((int)(isize + _legacyIn) * 9 / 8 + 6);
                byte[] obuf = oout.ByteArray;
                Array.Copy(ibuf, ipos, _history, _histptr + _legacyIn, remain);
                isize -= remain;
                ipos  += remain;
                compress_block(obuf, ref opos, remain + _legacyIn);
                _histptr = 0;

                for (;
                     isize >= (uint)Mppc.MppcHistLen;
                     isize -= (uint)Mppc.MppcHistLen, ipos += (uint)Mppc.MppcHistLen)
                {
                    Array.Copy(ibuf, ipos, _history, _histptr, (int)Mppc.MppcHistLen);
                    compress_block(obuf, ref opos, (uint)Mppc.MppcHistLen);
                    _histptr = 0;
                }
                oout.Resize((int)opos);
            }

            Array.Copy(ibuf, ipos, _history, _histptr + _legacyIn, isize);
            _legacyIn += isize;
            return(oin.Swap(oout));
        }
Exemplo n.º 2
0
        public Octets Final(Octets oin)
        {
            if (oin.Count == 0 && _legacyIn == 0)
            {
                return(oin);
            }

            Octets oout  = Update(oin);
            int    osize = oout.Count;

            oout.Reserve(osize + (int)_legacyIn * 9 / 8 + 6);
            byte[] obuf = oout.ByteArray;
            var    opos = (uint)osize;

            compress_block(obuf, ref opos, _legacyIn);
            oout.Resize((int)opos);
            return(oin.Swap(oout));
        }