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) []byteParameters & Attributes
| Name | Type | Description |
|---|---|---|
| buf | []byte | Byte buffer used for the operation; append APIs extend it. |
| x | int64 | Integer 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)) }