cbor

package
v1.2.14 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Size8      = 0x18
	Size16     = 0x19
	Size32     = 0x1a
	Size64     = 0x1b
	SizeStream = 0x1f
)

Type encoding sizes.

View Source
const (
	PosInt   = 0x00 // 0 << 5
	PosInt8  = PosInt + Size8
	PosInt16 = PosInt + Size16
	PosInt32 = PosInt + Size32
	PosInt64 = PosInt + Size64

	NegInt   = 0x20 // 1 << 5
	NegInt8  = NegInt + Size8
	NegInt16 = NegInt + Size16
	NegInt32 = NegInt + Size32
	NegInt64 = NegInt + Size64

	Bytes       = 0x40 // 2 << 5
	Bytes8      = Bytes + Size8
	Bytes16     = Bytes + Size16
	Bytes32     = Bytes + Size32
	Bytes64     = Bytes + Size64
	BytesStream = Bytes + SizeStream

	Utf       = 0x60 // 3 << 5
	Utf8      = Utf + Size8
	Utf16     = Utf + Size16
	Utf32     = Utf + Size32
	Utf64     = Utf + Size64
	UtfStream = Utf + SizeStream

	Array       = 0x80 // 4 << 5
	Array8      = Array + Size8
	Array16     = Array + Size16
	Array32     = Array + Size32
	Array64     = Array + Size64
	ArrayStream = Array + SizeStream

	Map       = 0xa0 // 5 << 5
	Map8      = Map + Size8
	Map16     = Map + Size16
	Map32     = Map + Size32
	Map64     = Map + Size64
	MapStream = Map + SizeStream

	Tag   = 0xc0 // 6 << 5
	Tag8  = Tag + Size8
	Tag16 = Tag + Size16
	Tag32 = Tag + Size32
	Tag64 = Tag + Size64

	Simple = 0xe0 // 7 << 5
)

Basic types.

View Source
const (
	False = Simple + 0x14 + iota
	True
	Nil
	Undefined
	Simple8
	Float16
	Float32
	Float64
	Break = Simple + SizeStream
)

Simple and special types.

View Source
const (
	TagDatetime  = iota // string
	TagTimestamp        // seconds from epoch
	TagPosBigInt
	TagNegBigInt
	TagDecimal
	TagBigFloat
)

Standard tags.

View Source
const (
	MajorTypeMask = 0xe0 // Upper 3 bits of type header defines the major type.
	MinorTypeMask = 0x1f // Lower 5 bits of type header defines the minor type.
)

Variables

View Source
var ErrMissingKey = awserr.New(request.ParamRequiredErrCode, "One of the required keys was not given a value", nil)
View Source
var ErrNaN = awserr.New(request.InvalidParameterErrCode, "cbor: not a number", nil)
View Source
var ErrNegLength = awserr.New(request.ErrCodeSerialization, "cbor: negative length", nil)
View Source
var ErrObjTooBig = awserr.New(request.ErrCodeSerialization, "cbor: object too big", nil)

Functions

func DecodeAttributeValue

func DecodeAttributeValue(reader *Reader) (*dynamodb.AttributeValue, error)

func DecodeItemKey

func DecodeItemKey(reader *Reader, keydef []dynamodb.AttributeDefinition) (map[string]*dynamodb.AttributeValue, error)

func DecodeItemNonKeyAttributes

func DecodeItemNonKeyAttributes(ctx aws.Context, reader *Reader, attrListIdToNames *lru.Lru) (map[string]*dynamodb.AttributeValue, error)

func EncodeAttributeValue

func EncodeAttributeValue(value *dynamodb.AttributeValue, writer *Writer) error

func EncodeItemKey

func EncodeItemKey(item map[string]*dynamodb.AttributeValue, keydef []dynamodb.AttributeDefinition, writer *Writer) error

func EncodeItemNonKeyAttributes

func EncodeItemNonKeyAttributes(ctx aws.Context, item map[string]*dynamodb.AttributeValue, keydef []dynamodb.AttributeDefinition,
	attrNamesListToId *lru.Lru, writer *Writer) error

func EncodeLexDecimal

func EncodeLexDecimal(decimal *Decimal, writer BytesWriter) (int, error)

func GetEncodedItemKey added in v1.1.0

func GetEncodedItemKey(item map[string]*dynamodb.AttributeValue, keydef []dynamodb.AttributeDefinition) ([]byte, error)

Types

type BytesReader

type BytesReader interface {
	io.Reader
	io.ByteReader
}

type BytesWriter

type BytesWriter interface {
	io.Writer
	io.ByteWriter
}

type Decimal

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

Decimal represents an arbitrary-precision signed decimal number. It consists of an arbitrary precision integer unscaled value and a scale. If zero or positive, the scale is the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the scale: unscaled * (10 ** -scale).

func DecodeLexDecimal

func DecodeLexDecimal(reader BytesReader) (*Decimal, error)

func NewDecimal

func NewDecimal(unscaled *big.Int, scale int) *Decimal

func (*Decimal) Scale

func (d *Decimal) Scale() int

func (*Decimal) SetInt

func (d *Decimal) SetInt(v *big.Int) *Decimal

func (*Decimal) SetIntScale

func (d *Decimal) SetIntScale(unscaled *big.Int, scale int) *Decimal

func (*Decimal) SetScale

func (d *Decimal) SetScale(scale int) *Decimal

func (*Decimal) SetString

func (d *Decimal) SetString(s string) (*Decimal, bool)

func (*Decimal) String

func (d *Decimal) String() string

func (*Decimal) Unscaled

func (d *Decimal) Unscaled() *big.Int

type Reader

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

func NewReader

func NewReader(r io.Reader) *Reader

func (*Reader) BytesReader

func (r *Reader) BytesReader() (*Reader, error)

func (*Reader) Close

func (r *Reader) Close() error

func (*Reader) PeekHeader

func (r *Reader) PeekHeader() (hdr byte, err error)

func (*Reader) ReadArrayLength

func (r *Reader) ReadArrayLength() (int, error)

func (*Reader) ReadBigInt

func (r *Reader) ReadBigInt() (*big.Int, error)

func (*Reader) ReadBreak

func (r *Reader) ReadBreak() (err error)

func (*Reader) ReadBytes

func (r *Reader) ReadBytes() ([]byte, error)

func (*Reader) ReadBytesLength added in v1.1.0

func (r *Reader) ReadBytesLength() (int, error)

func (*Reader) ReadCborIntegerToString added in v1.2.6

func (r *Reader) ReadCborIntegerToString() (string, error)

Read a CBOR integer (positive or negative) into a decimal string. Use primitive types unless the magnitude of the value requires a big.Int.

func (*Reader) ReadDecimal

func (r *Reader) ReadDecimal() (*Decimal, error)

func (*Reader) ReadFloat64

func (r *Reader) ReadFloat64() (float64, error)

func (*Reader) ReadInt deprecated

func (r *Reader) ReadInt() (int, error)

Deprecated: See the comment on ReadInt64().

func (*Reader) ReadInt64 deprecated

func (r *Reader) ReadInt64() (int64, error)

Deprecated: This method is not safe for reading values that use the high-order bit, because an int64 only has 63 bits for the value's magnitude, but CBOR negative and positive integers have 64 bits (the sign is in the major type). It is left here because it is used to read many values that are safely within the range of an int64, like ports, attribute ids, and parameter counts. However, it is not safe for reading DynamoDB item attribute values. For that use ReadCborIntegerToString().

func (*Reader) ReadMapLength

func (r *Reader) ReadMapLength() (int, error)

func (*Reader) ReadNil

func (r *Reader) ReadNil() (err error)

func (*Reader) ReadRawBytes added in v1.2.0

func (r *Reader) ReadRawBytes(o io.Writer) error

func (*Reader) ReadString

func (r *Reader) ReadString() (string, error)

type Writer

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

A Writer writes cbor-encoded data.

func NewWriter

func NewWriter(w io.Writer) *Writer

func (*Writer) Close

func (w *Writer) Close() error

func (*Writer) Flush

func (w *Writer) Flush() error

func (*Writer) Write

func (w *Writer) Write(b []byte) error

func (*Writer) WriteArrayHeader

func (w *Writer) WriteArrayHeader(elems int) error

func (*Writer) WriteArrayStreamHeader

func (w *Writer) WriteArrayStreamHeader() error

func (*Writer) WriteBigInt

func (w *Writer) WriteBigInt(value *big.Int) error

func (*Writer) WriteBoolean

func (w *Writer) WriteBoolean(b bool) error

func (*Writer) WriteBytes

func (w *Writer) WriteBytes(b []byte) error

func (*Writer) WriteDecimal

func (w *Writer) WriteDecimal(value *Decimal) (err error)

func (*Writer) WriteFloat

func (w *Writer) WriteFloat(v float32) error

func (*Writer) WriteFloat64

func (w *Writer) WriteFloat64(v float64) error

func (*Writer) WriteInt

func (w *Writer) WriteInt(value int) error

func (*Writer) WriteInt64

func (w *Writer) WriteInt64(value int64) error

func (*Writer) WriteMapHeader

func (w *Writer) WriteMapHeader(pairs int) error

func (*Writer) WriteMapStreamHeader

func (w *Writer) WriteMapStreamHeader() error

func (*Writer) WriteNull

func (w *Writer) WriteNull() error

func (*Writer) WriteStreamBreak

func (w *Writer) WriteStreamBreak() error

func (*Writer) WriteString

func (w *Writer) WriteString(s string) error

func (*Writer) WriteTag

func (w *Writer) WriteTag(tag uint64) error

Jump to

Keyboard shortcuts

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