NOTE: this should only be called with a number that is guaranteed to be less than len(mw.buf). typically, it is called with a constant. NOTE: this is a hot code path
(n int)
| 195 | // |
| 196 | // NOTE: this is a hot code path |
| 197 | func (mw *Writer) require(n int) (int, error) { |
| 198 | c := len(mw.buf) |
| 199 | wl := mw.wloc |
| 200 | if c-wl < n { |
| 201 | if err := mw.flush(); err != nil { |
| 202 | return 0, err |
| 203 | } |
| 204 | wl = mw.wloc |
| 205 | } |
| 206 | mw.wloc += n |
| 207 | return wl, nil |
| 208 | } |
| 209 | |
| 210 | func (mw *Writer) Append(b ...byte) error { |
| 211 | if mw.avail() < len(b) { |
no test coverage detected