cbor

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

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

Go to latest
Published: Apr 25, 2022 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

cbor

Go library for encoding CBOR (RFC 8949) messages

Do not use this library for production code. Use https://github.com/fxamacker/cbor/ instead.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(v interface{}) ([]byte, error)

Types

type AddMapItemFunc

type AddMapItemFunc func(fnkey, fnvalue BuilderContinuation)

type Builder

type Builder struct {
	ModeNaN   ModeNaN
	ModeInf   ModeInf
	ModeFloat ModeFloat
	ModeSort  ModeSort
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder(buffer []byte) *Builder

func (*Builder) AddArray

func (b *Builder) AddArray(n uint64, fn BuilderContinuation)

func (*Builder) AddBool

func (b *Builder) AddBool(v bool)

func (*Builder) AddBytes

func (b *Builder) AddBytes(v []byte)

func (*Builder) AddBytesUnknownLength

func (b *Builder) AddBytesUnknownLength(fn BuilderContinuation)

func (*Builder) AddFloat32

func (b *Builder) AddFloat32(v float32)

func (*Builder) AddFloat64

func (b *Builder) AddFloat64(v float64)

func (*Builder) AddInt

func (b *Builder) AddInt(v int)

func (*Builder) AddInt8

func (b *Builder) AddInt8(v int8)

func (*Builder) AddInt16

func (b *Builder) AddInt16(v int16)

func (*Builder) AddInt32

func (b *Builder) AddInt32(v int32)

func (*Builder) AddInt64

func (b *Builder) AddInt64(v int64)

func (*Builder) AddMap

func (b *Builder) AddMap(length int)

func (*Builder) AddMapItem

func (b *Builder) AddMapItem(k, v BuilderContinuation)

func (*Builder) AddNil

func (b *Builder) AddNil()

func (*Builder) AddRawBytes

func (b *Builder) AddRawBytes(v []byte)

func (*Builder) AddString

func (b *Builder) AddString(v string)

func (*Builder) AddTag

func (b *Builder) AddTag(number uint64)

func (*Builder) AddUint

func (b *Builder) AddUint(v uint)

func (*Builder) AddUint8

func (b *Builder) AddUint8(v uint8)

func (*Builder) AddUint16

func (b *Builder) AddUint16(v uint16)

func (*Builder) AddUint32

func (b *Builder) AddUint32(v uint32)

func (*Builder) AddUint64

func (b *Builder) AddUint64(v uint64)

func (*Builder) AddValue

func (b *Builder) AddValue(v MarshalingValue)

AddValue calls MarshalCBORValue on v, passing a pointer to the builder to append to. If MarshalCBORValue returns an error, it is set on the Builder so that subsequent appends don't have an effect.

func (*Builder) Bytes

func (b *Builder) Bytes() ([]byte, error)

Bytes returns the bytes written by the builder or an error if one has occurred during building.

func (*Builder) Len

func (b *Builder) Len() int

func (*Builder) Marshal

func (b *Builder) Marshal(v interface{})

func (*Builder) SetError

func (b *Builder) SetError(err error)

SetError sets the value to be returned as the error from Bytes. Writes performed after calling SetError are ignored.

type BuilderContinuation

type BuilderContinuation func(*Builder)

BuilderContinuation is a continuation-passing interface for building length-prefixed byte sequences.

type MarshalingValue

type MarshalingValue interface {
	MarshalCBORValue(*Builder) error
}

A MarshalingValue marshals itself into a Builder.

type ModeFloat

type ModeFloat int

ModeFloat specifies which floating-point format should be used as the shortest possible format for CBOR encoding. It is not used for encoding Infinity and NaN values.

const (
	// ModeFloat16 specifies float16 as the shortest form that preserves value.
	// E.g. if float64 can convert to float32 while preserving value, then
	// encoding will also try to convert float32 to float16.  So a float64 might
	// encode as CBOR float64, float32 or float16 depending on the value.
	ModeFloat16 ModeFloat = iota

	// ModeFloatNone makes float values encode without any conversion.
	// E.g. a float32 in Go will encode to CBOR float32.  And
	// a float64 in Go will encode to CBOR float64.
	ModeFloatNone
)

type ModeInf

type ModeInf int

ModeInf specifies how to encode Infinity and overrides ModeFloat. ModeFloat is not used for encoding Infinity and NaN values.

const (
	// ModeInfFloat16 always converts Inf to lossless IEEE binary16 (float16).
	ModeInfFloat16 ModeInf = iota

	// ModeInfNone never converts (used by CTAP2 Canonical CBOR).
	ModeInfNone
)

type ModeNaN

type ModeNaN int

ModeNaN specifies how to encode NaN.

const (
	// ModeNaN7e00 always encodes NaN to 0xf97e00 (CBOR float16 = 0x7e00).
	ModeNaN7e00 ModeNaN = iota

	// ModeNaNNone never modifies or converts NaN to other representations
	// (float64 NaN stays float64, etc. even if it can use float16 without losing
	// any bits).
	ModeNaNNone
)

type ModeSort

type ModeSort int

ModeSort identifies supported sorting order.

const (
	// ModeSortLengthFirst causes map keys or struct fields to be sorted such that:
	//     - If two keys have different lengths, the shorter one sorts earlier;
	//     - If two keys have the same length, the one with the lower value in
	//       (byte-wise) lexical order sorts earlier.
	// It is used in "Canonical CBOR" encoding in RFC 7049 3.9.
	ModeSortLengthFirst ModeSort = iota

	// ModeSortBytewiseLexical causes map keys or struct fields to be sorted in the
	// bytewise lexicographic order of their deterministic CBOR encodings.
	// It is used in "CTAP2 Canonical CBOR" and "Core Deterministic Encoding"
	// in RFC 7049bis.
	ModeSortBytewiseLexical

	// ModeSortNone means no sorting.
	ModeSortNone
)

type RawBytes

type RawBytes []byte

func (RawBytes) MarshalCBORValue

func (r RawBytes) MarshalCBORValue(b *Builder) error

type RawTag

type RawTag struct {
	Number  uint64
	Content RawBytes
}

func (RawTag) MarshalCBORValue

func (t RawTag) MarshalCBORValue(b *Builder) error

type Tag

type Tag struct {
	Number  uint64
	Content interface{}
}

func (Tag) MarshalCBORValue

func (t Tag) MarshalCBORValue(b *Builder) error

Jump to

Keyboard shortcuts

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