public override sealed OutStream w(int v) { if (p.m_pos + 1 >= p.m_buf.Length) { p.grow(p.m_pos + 1); } p.m_buf[p.m_pos++] = (byte)v; if (p.m_pos > p.m_size) { p.m_size = p.m_pos; } return(this); }
public override InStream unread(int n) { // unreading a buffer is a bit weird - the typical case // is that we are pushing back the byte we just read in // which case we can just rewind the position; however // if we pushing back a different byte then we need // to shift the entire buffer and insert the byte if (p.m_pos > 0 && p.m_buf[p.m_pos - 1] == (byte)n) { p.m_pos--; } else { if (p.m_size + 1 >= p.m_buf.Length) { p.grow(p.m_size + 1); } System.Array.Copy(p.m_buf, p.m_pos, p.m_buf, p.m_pos + 1, p.m_size); p.m_buf[p.m_pos] = (byte)n; p.m_size++; } return(this); }