Standard library / encoding/binary

encoding/binary.AppendVarint()

Appends a signed variable-length integer with sign mapping. Expected stdout: '03\n'.

Formal Syntax & Structure

go syntaxgo
func AppendVarint(buf []byte, x int64) []byte

Parameters & Attributes

NameTypeDescription
buf[]byteByte buffer used for the operation; append APIs extend it.
xint64Integer 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.AppendVarint(nil, -2)) }
Go Reference