io: implement ReadBytes()
This commit is contained in:
parent
838050f8b5
commit
fccb008594
22 changed files with 72 additions and 38 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue