GO-binary.PutUvarint在数值大于127时加1

All is in the title.

The GO function binary.PutUvarint add 1 when the numeric value is above 127.

I have searched on stack overflow and github issue and i not found response.

So I post this message to know if somebody can help.

Thank you (Sorry for my bad English)

b := make([]byte, binary.MaxVarintLen64)

binary.PutUvarint(b, 129)
fmt.Println(b)
// output
// [129 1 0 0 0 0 0 0 0 0]

binary.LittleEndian.PutUint64(b, 129)
fmt.Println(b)
// output
// [129 0 0 0 0 0 0 0 0 0]

I have searched on stack overflow and github issue and i not found response.


The first place to look is the Go package documentation.

Package binary

import "encoding/binary"

The varint functions encode and decode single integer values using a variable-length encoding; smaller values require fewer bytes. For a specification, see https://developers.google.com/protocol-buffers/docs/encoding.

Always read the documentation.