Standard library / encoding/binary
encoding/binary.ReadUvarint()
Reads one unsigned varint from an io.ByteReader, reporting incomplete or overflowing input as errors. Expected stdout: '300\n'.
Formal Syntax & Structure
go syntaxgo
func ReadUvarint(r io.ByteReader) (uint64, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| r | io.ByteReader | Input stream. |
Return Value
(uint64, error)
Unsigned 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.ReadUvarint(bytes.NewReader([]byte{0xac, 2})); must(e); fmt.Println(v) }