internal Octets Update(Octets oin) { Octets oout = new Octets(); uint ipos = 0, opos = 0; byte[] ibuf = oin.buffer(); uint isize = (uint)oin.size(); uint remain = (uint)MPPC.MPPC_HIST_LEN - histptr - legacy_in; if (isize >= remain) { oout.resize((int)(isize + legacy_in) * 9 / 8 + 6); byte[] obuf = oout.buffer(); Array.Copy(ibuf, ipos, history, histptr + legacy_in, remain); isize -= remain; ipos += remain; compress_block(obuf, ref opos, remain + legacy_in); histptr = 0; for (; isize >= (uint)MPPC.MPPC_HIST_LEN; isize -= (uint)MPPC.MPPC_HIST_LEN, ipos += (uint)MPPC.MPPC_HIST_LEN) { Array.Copy(ibuf, ipos, history, histptr, (int)MPPC.MPPC_HIST_LEN); compress_block(obuf, ref opos, (uint)MPPC.MPPC_HIST_LEN); histptr = 0; } oout.resize((int)opos); } Array.Copy(ibuf, ipos, history, histptr + legacy_in, isize); legacy_in += isize; return oin.swap(oout); }
public override Octets Update(Octets o) { r.NextBytes(o.buffer()); return o; }
public static Command DecodeCommand(Octets content) { MemoryStream ms = new MemoryStream(content.buffer()); BinaryReader br = new BinaryReader(ms); short type = 0; Command cmd = null; try { type = br.ReadInt16(); cmd = CommandList.CreateS2CCommand(type); if (cmd == null) { Debug.Log(string.Format("Command instance not found, type: {0}", (S2C.S2C_COMMAND)type)); return null; } cmd.ReceivedSize = content.size(); cmd.unmarshal(br); if (br.BaseStream.Position != content.size()) { Debug.LogWarning(string.Format("Command decode BufferLength don't match, type: {0}", (S2C.S2C_COMMAND)type)); } } catch (System.Exception) { Debug.LogWarning(string.Format("Command decode error, type: {0}", (S2C.S2C_COMMAND)type)); cmd = null; } return cmd; }