Standard library / encoding/binary

encoding/binary.Varint()

Decodes a signed varint; the byte count has the same incomplete/overflow convention as Uvarint. Expected stdout: '-2 1\n'.

Formal Syntax & Structure

go syntaxgo
func Varint(buf []byte) (int64, int)

Parameters & Attributes

NameTypeDescription
buf[]byteByte buffer used for the operation; append APIs extend it.

Return Value

(int64, int)

Signed value and byte count; nonpositive count signals incomplete or overflowing input.

Working Example

Example Snippetgo
package main
import (  "encoding/binary"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() { v, n := binary.Varint([]byte{3}); fmt.Println(v, n) }
Go Reference