Standard library / encoding/binary

encoding/binary.AppendUvarint()

Appends an unsigned variable-length integer; smaller values use fewer bytes. Expected stdout: 'ffac02\n'.

Formal Syntax & Structure

go syntaxgo
func AppendUvarint(buf []byte, x uint64) []byte

Parameters & Attributes

NameTypeDescription
buf[]byteByte buffer used for the operation; append APIs extend it.
xuint64Integer value to encode, or length for DecodedLen.

Return Value

[]byte

Resulting byte slice.

Working Example

Example Snippetgo
package main
import (  "encoding/binary"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() { fmt.Printf("%x\n", binary.AppendUvarint([]byte{0xff}, 300)) }
Go Reference