/// <summary> /// Write to the buffer. Please make sure that you won't use this memory any more after you hand it in. It will get mangled. /// </summary> /// <param name="buf"> </param> public void Write(byte[] buf) { m_stream.Write(buf, 0, buf.Length); if (m_tail == null) { m_head = m_tail = new BufNode(); m_head.buf = buf; } else { var n = new BufNode(); n.buf = buf; m_tail.next = n; m_tail = n; } }
/// <summary> /// Write to the buffer. Please make sure that you won't use this memory any more after you hand it in. It will get mangled. /// </summary> /// <param name="buf"> </param> public void Write(byte[] buf) { m_stream.Write(buf, 0, buf.Length); if (m_tail == null) { m_head = m_tail = new BufNode(); m_head.buf = buf; } else { var n = new BufNode(); n.buf = buf; m_tail.next = n; m_tail = n; } }
/// <summary> /// Clear the first "offset" bytes of the buffer, so they won't be parsed again. /// </summary> /// <param name="offset"></param> public void Clear(int offset) { int s = 0; int save = -1; BufNode bn = null; for (bn = m_head; bn != null; bn = bn.next) { if (s + bn.buf.Length <= offset) { if (s + bn.buf.Length == offset) { bn = bn.next; break; } s += bn.buf.Length; } else { save = s + bn.buf.Length - offset; break; } } m_head = bn; if (m_head == null) { m_tail = null; } if (save > 0) { byte[] buf = new byte[save]; System.Buffer.BlockCopy(m_head.buf, m_head.buf.Length - save, buf, 0, save); m_head.buf = buf; } m_stream.SetLength(0); for (bn = m_head; bn != null; bn = bn.next) { m_stream.Write(bn.buf, 0, bn.buf.Length); } }
/// <summary> /// Clear the first "offset" bytes of the buffer, so they won't be parsed again. /// </summary> /// <param name="offset"></param> public void Clear(int offset) { int s = 0; int save = -1; BufNode bn = null; for (bn = m_head; bn != null; bn = bn.next) { if (s + bn.buf.Length <= offset) { if (s + bn.buf.Length == offset) { bn = bn.next; break; } s += bn.buf.Length; } else { save = s + bn.buf.Length - offset; break; } } m_head = bn; if (m_head == null) m_tail = null; if (save > 0) { byte[] buf = new byte[save]; System.Buffer.BlockCopy(m_head.buf, m_head.buf.Length - save, buf, 0, save); m_head.buf = buf; } m_stream.SetLength(0); for (bn = m_head; bn != null; bn = bn.next) { m_stream.Write(bn.buf, 0, bn.buf.Length); } }