Standard library / encoding/binary

encoding/binary.ReadVarint()

Reads one signed varint from a byte reader. Expected stdout: '-2\n'.

Formal Syntax & Structure

go syntaxgo
func ReadVarint(r io.ByteReader) (int64, error)

Parameters & Attributes

NameTypeDescription
rio.ByteReaderInput stream.

Return Value

(int64, error)

Signed value and error.

Working Example

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