Standard library / encoding/binary

encoding/binary.Append()

Appends the fixed-size binary representation to an existing buffer. Use explicit fixed-width types, not int. Expected stdout: 'ff0102\n'.

Formal Syntax & Structure

go syntaxgo
func Append(buf []byte, order ByteOrder, data any) ([]byte, error)

Parameters & Attributes

NameTypeDescription
buf[]byteByte buffer used for the operation; append APIs extend it.
orderByteOrderByte ordering used for fixed-width numbers.
dataanyInput bytes for XML, or fixed-size value / destination pointer for binary operations.

Return Value

([]byte, error)

Resulting bytes (possibly partial for decoding) and error.

Working Example

Example Snippetgo
package main
import (  "encoding/binary"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  p, e := binary.Append([]byte{0xff}, binary.BigEndian, uint16(258))  must(e)  fmt.Printf("%x\n", p)}
Go Reference