Documentation
¶
Overview ¶
Package ufcbor provides utilities for fast and reflect-less CBOR decoding and encoding.
Index ¶
- Constants
- type Decoder
- func (d *Decoder) AppendBytes(orig, b []byte) (res, rest []byte)
- func (d *Decoder) DecodeArrayStart(b []byte) (l uint64, rest []byte)
- func (d *Decoder) DecodeInt64(b []byte) (n int64, rest []byte)
- func (d *Decoder) DecodeMapStart(b []byte) (l uint64, rest []byte)
- func (d *Decoder) DecodeUint64(b []byte) (u uint64, rest []byte)
- func (d *Decoder) Err() (err error)
- type Encoder
- func (e Encoder) EncodeArrayStart(orig []byte, l uint64) (res []byte)
- func (e Encoder) EncodeBytes(orig, b []byte) (res []byte)
- func (e Encoder) EncodeInt64(orig []byte, n int64) (res []byte)
- func (e Encoder) EncodeMapStart(orig []byte, l uint64) (res []byte)
- func (e Encoder) EncodeUint64(orig []byte, u uint64) (res []byte)
Constants ¶
const ( HeaderUintTinyMin = 0x00 HeaderUintTinyMax = 0x17 HeaderUint8 = 0x18 HeaderUint16 = 0x19 HeaderUint32 = 0x1a HeaderUint64 = 0x1b HeaderIntTinyMin = 0x20 HeaderIntTinyMax = 0x37 HeaderInt8 = 0x38 HeaderInt16 = 0x39 HeaderInt32 = 0x3a HeaderInt64 = 0x3b HeaderBytesTinyMin = 0x40 HeaderBytesTinyMax = 0x57 HeaderBytes8 = 0x58 HeaderBytes16 = 0x59 HeaderBytes32 = 0x5a HeaderBytes64 = 0x5b HeaderArrayTinyMin = 0x80 HeaderArrayTinyMax = 0x97 HeaderArray8 = 0x98 HeaderArray16 = 0x99 HeaderArray32 = 0x9a HeaderArray64 = 0x9b HeaderMapTinyMin = 0xa0 HeaderMapTinyMax = 0xb7 HeaderMap8 = 0xb8 HeaderMap16 = 0xb9 HeaderMap32 = 0xba HeaderMap64 = 0xbb )
Header constants.
See https://www.rfc-editor.org/rfc/rfc8949.html#name-jump-table-for-initial-byte.
const ( ValueIntTinyMin = -0x18 ValueIntTinyMax = -0x01 ValueUintTinyMin = 0x00 ValueUintTinyMax = 0x17 )
Value constants.
See https://www.rfc-editor.org/rfc/rfc8949.html#name-jump-table-for-initial-byte.
const TinyMask = 0b0001_1111
TinyMask is the bit mask for obtaining tiny values in headers.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder is a simple, performant CBOR decoder. All methods save the first error they encounter, and the error should be checked by calling Decoder.Err. Decoder operates with byte slices as opposed to an io.Reader to improve performance by reducing the amount of virtual calls and buffer allocations on the client side.
func NewDecoder ¶
func NewDecoder() (d Decoder)
NewDecoder returns a new properly initialized decoder. d is a value and not a pointer to spare allocations.
func (*Decoder) AppendBytes ¶
AppendBytes decodes a CBOR byte string from b, appends it to orig and returns it. rest is the rest of b after consuming the byte string. If there are errors, res is orig and rest is b.
func (*Decoder) DecodeArrayStart ¶
DecodeArrayStart decodes a start of a CBOR array with the length l, if b contains it. rest is the rest of b after consuming the array start. If there are errors, l is 0 and rest is b.
func (*Decoder) DecodeInt64 ¶
DecodeInt64 decodes a CBOR signed integer, if b contains it. rest is the rest of b after consuming the integer. If there are errors, n is 0 and rest is b.
func (*Decoder) DecodeMapStart ¶
DecodeMapStart decodes a start of a CBOR map with the length l, if b contains it. rest is the rest of b after consuming the array start. If there are errors, l is 0 and rest is b.
func (*Decoder) DecodeUint64 ¶
DecodeUint64 decodes a CBOR unsigned integer, if b contains it. rest is the rest of b after consuming the unsigned integer. If there are errors, u is 0 and rest is b.
type Encoder ¶
type Encoder struct{}
Encoder is a simple, performant CBOR encoder. It handles byte slices as opposed to an io.Writer to improve performance by reducing the amount of virtual calls and buffer allocations on the client side.
TODO(a.garipov): Consider turning into functions.
TODO(a.garipov): Move to golibs/cborutil.
func NewEncoder ¶
func NewEncoder() (e Encoder)
NewEncoder returns a new properly initialized Encoder.
func (Encoder) EncodeArrayStart ¶
EncodeArrayStart appends a start of a CBOR array with the length l to orig and returns it.
func (Encoder) EncodeBytes ¶
EncodeBytes appends b as a CBOR byte string to orig and returns it.
func (Encoder) EncodeInt64 ¶
EncodeInt64 appends n as a CBOR signed integer to orig and returns it.
func (Encoder) EncodeMapStart ¶
EncodeMapStart appends a start of a CBOR map with the length l to orig and returns it.