io: add Grow
to BinWriter
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
c69670c85b
commit
dacf025dd9
1 changed files with 9 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
package io
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"reflect"
|
||||
|
@ -144,3 +145,11 @@ func (w *BinWriter) WriteVarBytes(b []byte) {
|
|||
func (w *BinWriter) WriteString(s string) {
|
||||
w.WriteVarBytes([]byte(s))
|
||||
}
|
||||
|
||||
// Grow tries to increase underlying buffer capacity so that at least n bytes
|
||||
// can be written without reallocation. If the writer is not a buffer, this is a no-op.
|
||||
func (w *BinWriter) Grow(n int) {
|
||||
if b, ok := w.w.(*bytes.Buffer); ok {
|
||||
b.Grow(n)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue