cbor

package module
v0.0.0-...-1594b7e Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

README

Tiny-CBOR

CBOR without the reflection.

The long term plan here is to generate Go read / write methods from the struct tags in go-cbor.

Documentation

Index

Constants

View Source
const (
	SimpleFalse     Arg = 20
	SimpleTrue      Arg = 21
	SimpleNull      Arg = 22
	SimpleUndefined Arg = 23
	SimpleUint8         = Arg8  // 24
	SimpleFloat16       = Arg16 // 25
	SimpleFloat32       = Arg32 // 26
	SimpleFloat64       = Arg64 // 27
	// 28..30 reserved
	SimpleBreak Arg = 31
)
View Source
const (
	MajorTypeMask byte = 0b111_00000
)

Variables

View Source
var (
	ErrUnsupportedMajorType = errors.New("cbor: unsupported major type")
	ErrUnsupportedValue     = errors.New("cbor: unsupported value")
	ErrNotWellFormed        = errors.New("cbor: not well formed")
	ErrOverflow             = errors.New("cbor: overflow")
	ErrNestedIndefinite     = errors.New("cbor: nested indefinite")
)

Functions

func ReadAny

func ReadAny(in io.Reader) (any, error)

ReadAny returns the next object form [in] regardless of type. Outputs can be any of int64, uint64, bool, []byte, string, []any, map[any]any, float32, float64, nil.

func ReadArray

func ReadArray(
	in io.Reader,
	readLength func(indefinite bool, length uint64) error,
	readItem func(i uint64, in io.Reader) error,
) error

func ReadBool

func ReadBool(in io.Reader) (bool, error)

func ReadBytes

func ReadBytes(
	in io.Reader,
	readLength func(indefinite bool, length uint64) error,
	out io.Writer,
) error

func ReadFloat

func ReadFloat[T float32 | float64](in io.Reader) (T, error)

func ReadMap

func ReadMap(
	in io.Reader,
	readLength func(indefinite bool, length uint64) error,
	readKeyValue func(in io.Reader) error,
) error

func ReadOver

func ReadOver(in io.Reader) error

ReadOver skips the next object in [in].

func ReadRaw

func ReadRaw(
	in io.Reader,
	out io.Writer,
) error

func ReadSigned

func ReadSigned[T int8 | int16 | int32 | int64](in io.Reader) (T, error)

func ReadTag

func ReadTag(in io.Reader) (uint64, error)

ReadTag reads the next object from [in] as a tag and returns the value.

func ReadUnsigned

func ReadUnsigned[T uint8 | uint16 | uint32 | uint64](in io.Reader) (T, error)

func WriteArrayHeader

func WriteArrayHeader(out io.Writer, length uint64) (int, error)

func WriteBool

func WriteBool(out io.Writer, value bool) (int, error)

func WriteBreak

func WriteBreak(out io.Writer) (int, error)

func WriteBytes

func WriteBytes(out io.Writer, value []byte) (int, error)

func WriteFloat

func WriteFloat[T float16.Float16 | float32 | float64](out io.Writer, value T) (int, error)

func WriteMapHeader

func WriteMapHeader(out io.Writer, length uint64) (int, error)

func WriteNull

func WriteNull(out io.Writer) (int, error)

func WriteSigned

func WriteSigned[T int8 | int16 | int32 | int64](out io.Writer, value T) (int, error)

func WriteString

func WriteString(out io.Writer, value string) (int, error)

func WriteTag

func WriteTag(out io.Writer, value uint64) (int, error)

func WriteUnsigned

func WriteUnsigned[T uint8 | uint16 | uint32 | uint64](out io.Writer, value T) (int, error)

Types

type Arg

type Arg byte
const (
	Arg8  Arg = 24
	Arg16 Arg = 25
	Arg32 Arg = 26
	Arg64 Arg = 27
	// 28..30 reserved
	ArgIndefinite Arg = 31
)

type MajorType

type MajorType byte
const (
	MajorTypeUInt        MajorType = 0 << 5
	MajorTypeNInt        MajorType = 1 << 5
	MajorTypeBstr        MajorType = 2 << 5
	MajorTypeTstr        MajorType = 3 << 5
	MajorTypeArray       MajorType = 4 << 5
	MajorTypeMap         MajorType = 5 << 5
	MajorTypeTagged      MajorType = 6 << 5
	MajorTypeSimpleFloat MajorType = 7 << 5
)

Jump to

Keyboard shortcuts

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