cbor

package
v0.0.0-...-f98e9bb Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

This file implements the CBOR specification see: https://www.rfc-editor.org/rfc/rfc8949.html

Index

Constants

This section is empty.

Variables

View Source
var ErrNotWellFormedCBOR = fmt.Errorf("not well-formed (%w)", common.ErrBadInput)

Functions

func Decode

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

func Encode

func Encode(something any) ([]byte, error)

Types

type AdditionalInfo

type AdditionalInfo byte

5 least significant bits of the first byte of a CBOR encoding. mask: 0b000_11111

const (
	OneByteArgument   AdditionalInfo = 24
	TwoByteArgument   AdditionalInfo = 25
	FourByteArgument  AdditionalInfo = 26
	EightByteArgument AdditionalInfo = 27
	NoArgument        AdditionalInfo = 31
)

type DataItem

type DataItem struct {
	MajorType
	AdditionalInfo

	// variably sized argument for the additional info.
	Argument [8]byte

	// optional content of the CBOR encoding
	Content []byte

	Children []*DataItem
}

func DataItemFromBytes

func DataItemFromBytes(data []byte) (*DataItem, error)

func NewDataType

func NewDataType(something any) (*DataItem, error)

func (*DataItem) Bytes

func (item *DataItem) Bytes() ([]byte, error)

func (*DataItem) Length

func (item *DataItem) Length() uint64

func (*DataItem) String

func (item *DataItem) String() string

func (*DataItem) Value

func (item *DataItem) Value() (any, error)

type MajorType

type MajorType byte

3 most significant bits of the first byte of a CBOR encoding. mask: 0b111_00000 see: https://www.rfc-editor.org/rfc/rfc8949.html#name-major-types

const (
	UnsignedUint64  MajorType = 0
	NegativeInt64   MajorType = 1
	ByteString      MajorType = 2
	TextString      MajorType = 3
	ArrayData       MajorType = 4
	MapData         MajorType = 5
	TaggedData      MajorType = 6
	SimpleValueData MajorType = 7
)

func (MajorType) String

func (major MajorType) String() string

type SimpleValue

type SimpleValue AdditionalInfo

https://www.rfc-editor.org/rfc/rfc8949.html#name-floating-point-numbers-and-

const (
	SimpleValue_false      SimpleValue = 20
	SimpleValue_true       SimpleValue = 21
	SimpleValue_null       SimpleValue = 22
	SimpleValue_undefined  SimpleValue = 23
	SimpleValue_extended   SimpleValue = 24
	SimpleValue_float16    SimpleValue = 25
	SimpleValue_float32    SimpleValue = 26
	SimpleValue_float64    SimpleValue = 27
	SimpleValue_reserved_1 SimpleValue = 28
	SimpleValue_reserved_2 SimpleValue = 29
	SimpleValue_reserved_3 SimpleValue = 30
	SimpleValue_break      SimpleValue = 31
)

Jump to

Keyboard shortcuts

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