Golang encoding/binary.PutVarint() function example

package encoding/binary

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

Golang encoding/binary.PutVarint() function usage example

 var l64 int64
 l64 = int64(len("abcdefg"))
 lenstore := make([]byte, 8)
 binary.PutVarint(lenstore, l64)

Reference :

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

Advertisement