amfcodec

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package amfcodec reads and writes Action Message Format, both AMF0 and AMF3.

The two formats share a package because a value is often encoded in one and referenced from the other. Both directions work on the ordered JSON model in github.com/roberson-io/cchef/internal/jsonval, so an object's keys come back out in the order they went in — which decides the bytes, and is what makes the encoding reproducible.

AMF3's reference tables mean a string, object or trait appears once and is pointed at afterwards; NewTables3 holds that state for one encoding or decoding pass.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode0

func Decode0(r *Reader, refs *[]any) (any, error)

Decode0 reads one AMF0 value. refs holds the objects seen so far, which the reference marker points back into.

func Decode3

func Decode3(r *Reader, t *amf3Tables) (any, error)

Decode3 reads one AMF3 value.

func Encode0

func Encode0(w *Writer, v any) error

Encode0 writes one value in AMF0.

func Encode3

func Encode3(w *Writer, v any) error

Encode3 writes one value in AMF3. Nothing is written by reference: the output is a little larger than it need be, and reads identically.

func NewTables3

func NewTables3() *amf3Tables

NewTables3 returns the reference tables one AMF3 encoding or decoding pass keeps: a value written once is pointed at by index afterwards.

func ParseJSON

func ParseJSON(data []byte) (any, error)

ParseJSON reads JSON into the value kinds the encoders handle, keeping object keys in the order they were written.

Types

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader reads AMF from a byte slice, refusing to read past the end.

func NewReader

func NewReader(b []byte) *Reader

NewReader reads AMF from b.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer builds AMF output. A value AMF3's 29-bit length cannot express is recorded here rather than returned from every call: the limit belongs to the writer, and the caller checks once when the value is complete.

func (*Writer) Bytes

func (w *Writer) Bytes() []byte

Bytes returns what has been written so far.

func (*Writer) Err

func (w *Writer) Err() error

Err reports a value the format could not express. It is recorded here rather than returned from every call that writes one, so a long encoding is not a chain of error checks.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL