github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/util/varint/varint.go (about) 1 package varint 2 3 import ( 4 "encoding/binary" 5 "io" 6 ) 7 8 type Writer []byte 9 10 func NewWriter() Writer { 11 return make([]byte, binary.MaxVarintLen64) 12 } 13 14 func (buf Writer) Write(w io.Writer, val uint64) (int, error) { 15 n := binary.PutUvarint(buf, val) 16 return w.Write(buf[:n]) 17 } 18 19 func Write(w io.Writer, val uint64) (int, error) { 20 buf := make([]byte, binary.MaxVarintLen64) 21 n := binary.PutUvarint(buf, val) 22 return w.Write(buf[:n]) 23 } 24 25 func Read(r io.ByteReader) (uint64, error) { 26 return binary.ReadUvarint(r) 27 }