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)); }
public Octets Update(Octets oin) { _legacyIn.Append(oin); _blenTotol = (uint)(_legacyIn.Count * 8 - _l); _legacyIn.Reserve(_legacyIn.Count + 3); _rptr = 0; _blen = 7; Octets oout = oin; oout.Clear(); uint histhead = _histptr; while (_blenTotol > _blen) { _adjustL = _l; _adjustRptr = _rptr; uint val = Fetch(); if (val < 0x80000000) { if (!Passbits(8)) { break; } _history[_histptr++] = (byte)(val >> 24); continue; } if (val < 0xc0000000) { if (!Passbits(9)) { break; } _history[_histptr++] = (byte)(((val >> 23) | 0x80) & 0xff); continue; } uint len; uint off = 0; if (val >= 0xf0000000) { if (!Passbits(10)) { break; } off = (val >> 22) & 0x3f; if (off == (uint)Mppc.CtrlOffEob) { uint advance = 8 - (_l & 7); if (advance < 8) { if (!Passbits(advance)) { break; } } oout.Append(_history, (int)histhead, (int)(_histptr - histhead)); if (_histptr == (uint)Mppc.MppcHistLen) { _histptr = 0; } histhead = _histptr; continue; } } else if (val >= 0xe0000000) { if (!Passbits(12)) { break; } off = ((val >> 20) & 0xff) + 64; } else if (val >= 0xc0000000) { if (!Passbits(16)) { break; } off = ((val >> 16) & 0x1fff) + 320; } val = Fetch(); if (val < 0x80000000) { if (!Passbits(1)) { break; } len = 3; } else if (val < 0xc0000000) { if (!Passbits(4)) { break; } len = 4 | ((val >> 28) & 3); } else if (val < 0xe0000000) { if (!Passbits(6)) { break; } len = 8 | ((val >> 26) & 7); } else if (val < 0xf0000000) { if (!Passbits(8)) { break; } len = 16 | ((val >> 24) & 15); } else if (val < 0xf8000000) { if (!Passbits(10)) { break; } len = 32 | ((val >> 22) & 0x1f); } else if (val < 0xfc000000) { if (!Passbits(12)) { break; } len = 64 | ((val >> 20) & 0x3f); } else if (val < 0xfe000000) { if (!Passbits(14)) { break; } len = 128 | ((val >> 18) & 0x7f); } else if (val < 0xff000000) { if (!Passbits(16)) { break; } len = 256 | ((val >> 16) & 0xff); } else if (val < 0xff800000) { if (!Passbits(18)) { break; } len = 0x200 | ((val >> 14) & 0x1ff); } else if (val < 0xffc00000) { if (!Passbits(20)) { break; } len = 0x400 | ((val >> 12) & 0x3ff); } else if (val < 0xffe00000) { if (!Passbits(22)) { break; } len = 0x800 | ((val >> 10) & 0x7ff); } else if (val < 0xfff00000) { if (!Passbits(24)) { break; } len = 0x1000 | ((val >> 8) & 0xfff); } else { _l = _adjustL; _rptr = _adjustRptr; break; } if (_histptr < off || _histptr + len > (uint)Mppc.MppcHistLen) { break; } // Array.Copy(history, histptr - off, history, histptr, histptr - histhead); LameCopy(_history, (int)_histptr, (int)(_histptr - off), (int)len); // Array.Copy(history, histptr - off, history, histptr, len); _histptr += len; } oout.Append(_history, (int)histhead, (int)(_histptr - histhead)); _legacyIn.Erase(0, (int)_rptr); return(oout); }