io: implement ReadBytes()

This commit is contained in:
Evgenii Stratonikov 2019-12-06 18:37:46 +03:00
parent 838050f8b5
commit fccb008594
22 changed files with 72 additions and 38 deletions

View file

@ -132,10 +132,19 @@ func (r *BinReader) ReadVarUint() uint64 {
func (r *BinReader) ReadVarBytes() []byte {
n := r.ReadVarUint()
b := make([]byte, n)
r.ReadLE(b)
r.ReadBytes(b)
return b
}
// ReadBytes copies fixed-size buffer from the reader to provided slice.
func (r *BinReader) ReadBytes(buf []byte) {
if r.Err != nil {
return
}
_, r.Err = io.ReadFull(r.r, buf)
}
// ReadString calls ReadVarBytes and casts the results as a string.
func (r *BinReader) ReadString() string {
b := r.ReadVarBytes()