Standard library / encoding/binary
encoding/binary.Uvarint()
Decodes an unsigned varint from bytes. Zero count means incomplete input; negative count means overflow. Expected stdout: '300 2\n'.
Formal Syntax & Structure
go syntaxgo
func Uvarint(buf []byte) (uint64, int)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| buf | []byte | Byte buffer used for the operation; append APIs extend it. |
Return Value
(uint64, int)
Unsigned 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.Uvarint([]byte{0xac, 2}); fmt.Println(v, n) }