[buffer]: added wrapper with int64 counter

This commit is contained in:
Jean-Philippe Bossuat
2023-07-14 20:21:22 +02:00
parent 69e1f83d01
commit d88a6ef9d8
2 changed files with 17 additions and 0 deletions
+11
View File
@@ -8,6 +8,17 @@ import (
"github.com/tuneinsight/lattigo/v4/utils"
)
// Read reads a slice of bytes from r and copies it on c.
func Read(r Reader, c []byte) (n int64, err error){
slice, err := r.Peek(len(c))
if err != nil {
return int64(len(slice)), err
}
copy(c, slice)
nint, err := r.Discard(len(c))
return int64(nint), err
}
// ReadInt reads an int values from r and stores the result into *c.
func ReadInt(r Reader, c *int) (n int64, err error) {
+6
View File
@@ -6,6 +6,12 @@ import (
"unsafe"
)
// Write writes a slice of bytes to w.
func Write(w Writer, c []byte) (n int64, err error){
nint, err := w.Write(c)
return int64(nint), err
}
// WriteInt writes an int c to w.
func WriteInt(w Writer, c int) (n int64, err error) {
nint, err := WriteUint64(w, uint64(c))