Golang encoding/binary.PutUvarint() function example

package encoding/binary

PutUvarint encodes a uint64 into buf(1st parameter) and returns the number of bytes written. If the buffer is too small, PutUvarint will panic.

Golang encoding/binary.PutUvarint() function usage example

 func encodeBlockHandle(dst []byte, b blockHandle) int {
 n := binary.PutUvarint(dst, b.offset)
 m := binary.PutUvarint(dst[n:], b.length)
 return n + m
 }

References :

http://golang.org/pkg/encoding/binary/#PutUvarint

https://github.com/syndtr/goleveldb/blob/master/leveldb/table/table.go

Advertisement