cbor

package module
v0.0.0-...-e21540f Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 5 Imported by: 8

README

Documentation Go workflow CircleCI codecov Go Report Card GitHub tag (latest SemVer)

cbor

One of my favorite formats/encodings: https://cbor.io/

Documentation

Index

Constants

View Source
const (
	FtFloat8Int FeatureFlags
	FtFloat16

	FtDefault    = FtFloat8Int
	FtCompatible = FtFloat16
)
View Source
const (
	ErrOK = iota
	ErrShortBuffer
	ErrIncompatible
	ErrMalformed
	ErrUnexpectedEOF
	ErrOverflow
)

Variables

This section is empty.

Functions

func Dump

func Dump(r []byte) (s string)

func IsBool

func IsBool(raw Tag) bool

func IsFloat

func IsFloat(raw Tag) bool

func IsInt

func IsInt(tag Tag) bool

func IsNum

func IsNum(raw Tag) bool

Types

type Emitter

type Emitter struct {
	Flags FeatureFlags
}

func MakeEmitter

func MakeEmitter() Emitter

func (Emitter) AppendArray

func (e Emitter) AppendArray(b []byte, l int) []byte

func (Emitter) AppendBool

func (e Emitter) AppendBool(b []byte, v bool) []byte

func (Emitter) AppendBreak

func (e Emitter) AppendBreak(b []byte) []byte

func (Emitter) AppendBytes

func (e Emitter) AppendBytes(b, s []byte) []byte

func (Emitter) AppendFloat

func (e Emitter) AppendFloat(b []byte, v float64) []byte

func (Emitter) AppendFloat32

func (e Emitter) AppendFloat32(b []byte, v float32) []byte

func (Emitter) AppendInt

func (e Emitter) AppendInt(b []byte, v int) []byte

func (Emitter) AppendInt64

func (e Emitter) AppendInt64(b []byte, v int64) []byte

func (Emitter) AppendLabel

func (e Emitter) AppendLabel(b []byte, x int) []byte

func (Emitter) AppendMap

func (e Emitter) AppendMap(b []byte, l int) []byte

func (Emitter) AppendNegUint64

func (e Emitter) AppendNegUint64(b []byte, v uint64) []byte

func (Emitter) AppendNone

func (e Emitter) AppendNone(b []byte) []byte

func (Emitter) AppendNull

func (e Emitter) AppendNull(b []byte) []byte

func (Emitter) AppendSimple

func (e Emitter) AppendSimple(b []byte, x Tag) []byte

func (Emitter) AppendString

func (e Emitter) AppendString(b []byte, s string) []byte

func (Emitter) AppendTag

func (e Emitter) AppendTag(b []byte, tag Tag, v int) []byte

func (Emitter) AppendTag64

func (e Emitter) AppendTag64(b []byte, tag Tag, v uint64) []byte

func (Emitter) AppendTagBreak

func (e Emitter) AppendTagBreak(b []byte, tag Tag) []byte

func (Emitter) AppendTagBytes

func (e Emitter) AppendTagBytes(b []byte, tag Tag, s []byte) []byte

func (Emitter) AppendTagString

func (e Emitter) AppendTagString(b []byte, tag Tag, s string) []byte

func (Emitter) AppendTagUnsigned

func (e Emitter) AppendTagUnsigned(b []byte, tag Tag, v uint64) []byte

func (Emitter) AppendUint

func (e Emitter) AppendUint(b []byte, v uint) []byte

func (Emitter) AppendUint64

func (e Emitter) AppendUint64(b []byte, v uint64) []byte

func (Emitter) AppendUndefined

func (e Emitter) AppendUndefined(b []byte) []byte

func (Emitter) InsertLen

func (e Emitter) InsertLen(b []byte, tag Tag, st, l0, l int) []byte

InsertLen inserts length l before value starting at st copying the value bytes forward if needed. It's needed to encode the value of unknown size. You first expect lenth to take one byte, encodes the value and then inserts length moving the value if encoded length size exceeds one byte.

expectedLen := 0
b = e.AppendTag(b, tag, expectedLen)
st := len(b)
b = append(b, ...) // arbitrary value of arbitrary size
l := len(b) - st // for string or bytes
// or l = array/map length
b = e.InsertLen(b, tag, st, expectedLen, l)

func (Emitter) Tag64Size

func (e Emitter) Tag64Size(v int64) int

func (Emitter) TagSize

func (e Emitter) TagSize(v int) int

type Error

type Error int

func (Error) Code

func (e Error) Code() int

func (Error) CodeIndex

func (e Error) CodeIndex() (code, index int)

func (Error) Error

func (e Error) Error() string

func (Error) Index

func (e Error) Index() int

type FeatureFlags

type FeatureFlags int

func (FeatureFlags) Is

func (f FeatureFlags) Is(ff FeatureFlags) bool

type Iterator

type Iterator struct {
	Flags FeatureFlags
}

func MakeIterator

func MakeIterator() Iterator

func (Iterator) Break

func (d Iterator) Break(b []byte, i *int) bool

func (Iterator) Bytes

func (d Iterator) Bytes(b []byte, st int) (v []byte, i int)

func (Iterator) Float

func (d Iterator) Float(b []byte, st int) (v float64, i int)

func (Iterator) Float32

func (d Iterator) Float32(b []byte, st int) (v float32, i int)

func (Iterator) Label

func (d Iterator) Label(b []byte, st int) (lab, i int)

func (Iterator) Raw

func (d Iterator) Raw(b []byte, st int) ([]byte, int)

func (Iterator) Signed

func (d Iterator) Signed(b []byte, st int) (v int64, i int)

func (Iterator) Simple

func (d Iterator) Simple(b []byte, st int) Tag

func (Iterator) Skip

func (d Iterator) Skip(b []byte, st int) (i int)

func (Iterator) SkipTag

func (d Iterator) SkipTag(b []byte, st int) (tag Tag, sub int64, i int)

func (Iterator) Tag

func (d Iterator) Tag(b []byte, st int) (tag Tag, l int64, i int)

func (Iterator) TagOnly

func (d Iterator) TagOnly(b []byte, st int) (tag Tag)

func (Iterator) TagRaw

func (d Iterator) TagRaw(b []byte, st int) (tag Tag)

func (Iterator) Unsigned

func (d Iterator) Unsigned(b []byte, st int) (v uint64, i int)

func (Iterator) UnwrapLabels

func (d Iterator) UnwrapLabels(b []byte, st int) (i int)

type Message

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

type Reader

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

func NewReader

func NewReader(r io.Reader) *Reader

func (*Reader) Decode

func (r *Reader) Decode() (data []byte, err error)

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

func (*Reader) WriteTo

func (r *Reader) WriteTo(w io.Writer) (n int64, err error)

type Tag

type Tag byte
const (
	Int Tag = iota << 5
	Neg
	Bytes
	String
	Array
	Map
	Label
	Simple

	TagMask = 0b1110_0000
	SubMask = 0b0001_1111
)
const (
	Len1 Tag = 24 + iota
	Len2
	Len4
	Len8

	LenBreak Tag = Break
)
const (
	False Tag = 20 + iota
	True
	Null
	Undefined

	Float8
	Float16
	Float32
	Float64

	None Tag = 0

	Break Tag = 31
)

func (Tag) String

func (t Tag) String() string

Jump to

Keyboard shortcuts

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