cbor

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2022 License: Apache-2.0 Imports: 4 Imported by: 17

README

tinygo-cbor

Documentation

Index

Constants

View Source
const (
	TypeU8ShortMin    = 0x00
	TypeU8ShortMax    = 0x17
	TypeU8            = 0x18
	TypeU16           = 0x19
	TypeU32           = 0x1a
	TypeU64           = 0x1b
	TypeI8ShortMin    = 0x20
	TypeI8ShortMax    = 0x37
	TypeI8            = 0x38
	TypeI16           = 0x39
	TypeI32           = 0x3a
	TypeI64           = 0x3b
	TypeBytesIndef    = 0x5f
	TypeArrayIndef    = 0x9f
	TypeMapIndef      = 0xbf
	TypeTagMax        = 0xdb
	TypeBoolFalse     = 0xf4
	TypeBoolTrue      = 0xf5
	TypeNull          = 0xf6
	TypeUndefined     = 0xf7
	TypeF16           = 0xf9
	TypeF32           = 0xfa
	TypeF64           = 0xfb
	TypeBreak         = 0xff
	TypeMajorUnsigned = 0x00 // major type : high 3 bits
	TypeMajorSigned   = 0x20 // major type : high 3 bits
	TypeMajorBytes    = 0x40 // major type : high 3 bits
	TypeMajorText     = 0x60 // major type : high 3 bits
	TypeMajorArray    = 0x80 // major type : high 3 bits
	TypeMajorMap      = 0xa0 // major type : high 3 bits
	TypeMajorTagged   = 0xc0 // major type : high 3 bits
	TypeMajorSimple   = 0xe0 // major type : high 3 bits
)

Variables

View Source
var ErrRange = errors.New("range error")

Functions

func InfoOf

func InfoOf(b uint8) uint8

Get additional info of the byte (low 5 bits)

func ToBytes

func ToBytes(codec Codec) ([]byte, error)

ToBytes creates a `[]byte` from `codec`.

func TypeOf

func TypeOf(b uint8) uint8

Get major type if the byte (high 3 bits)

Types

type Codec

type Codec interface {
	Decode(decoder *Decoder) error
	Encode(encoder Writer) error
}

Codec is the interface that applies to data structures that can encode to and decode from the MessagPack format.

type DataReader

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

func NewDataReader

func NewDataReader(buffer []byte) DataReader

func (*DataReader) CheckError

func (d *DataReader) CheckError() error

check whether any errors have occurred

func (*DataReader) Discard

func (d *DataReader) Discard(length uint32) error

func (*DataReader) GetBytes

func (d *DataReader) GetBytes(length uint32) ([]byte, error)

func (*DataReader) GetFloat32

func (d *DataReader) GetFloat32() (float32, error)

func (*DataReader) GetFloat64

func (d *DataReader) GetFloat64() (float64, error)

func (*DataReader) GetInt16

func (d *DataReader) GetInt16() (int16, error)

func (*DataReader) GetInt32

func (d *DataReader) GetInt32() (int32, error)

func (*DataReader) GetInt64

func (d *DataReader) GetInt64() (int64, error)

func (*DataReader) GetInt8

func (d *DataReader) GetInt8() (int8, error)

func (*DataReader) GetUint16

func (d *DataReader) GetUint16() (uint16, error)

func (*DataReader) GetUint32

func (d *DataReader) GetUint32() (uint32, error)

func (*DataReader) GetUint64

func (d *DataReader) GetUint64() (uint64, error)

func (*DataReader) GetUint8

func (d *DataReader) GetUint8() (uint8, error)

func (*DataReader) PeekUint8

func (d *DataReader) PeekUint8() (uint8, error)

func (*DataReader) SetBytes

func (d *DataReader) SetBytes(src []byte) error

func (*DataReader) SetFloat32

func (d *DataReader) SetFloat32(value float32) error

func (*DataReader) SetFloat64

func (d *DataReader) SetFloat64(value float64) error

func (*DataReader) SetInt16

func (d *DataReader) SetInt16(value int16) error

func (*DataReader) SetInt32

func (d *DataReader) SetInt32(value int32) error

func (*DataReader) SetInt64

func (d *DataReader) SetInt64(value int64) error

func (*DataReader) SetInt8

func (d *DataReader) SetInt8(value int8) error

func (*DataReader) SetUint16

func (d *DataReader) SetUint16(value uint16) error

func (*DataReader) SetUint32

func (d *DataReader) SetUint32(value uint32) error

func (*DataReader) SetUint64

func (d *DataReader) SetUint64(value uint64) error

func (*DataReader) SetUint8

func (d *DataReader) SetUint8(value uint8) error

type Decoder

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

func NewDecoder

func NewDecoder(buffer []byte) Decoder

func (*Decoder) IsNextNil

func (d *Decoder) IsNextNil() (bool, error)

func (*Decoder) Pos

func (d *Decoder) Pos() uint32

private function - exposed for debugging

func (*Decoder) ReadArraySize

func (d *Decoder) ReadArraySize() (uint32, bool, error)

For arrays of defined length, second value in return tuple should be false.

func (*Decoder) ReadBool

func (d *Decoder) ReadBool() (bool, error)

func (*Decoder) ReadByteArray

func (d *Decoder) ReadByteArray() ([]byte, error)

func (*Decoder) ReadFloat32

func (d *Decoder) ReadFloat32() (float32, error)

func (*Decoder) ReadFloat64

func (d *Decoder) ReadFloat64() (float64, error)

func (*Decoder) ReadInt16

func (d *Decoder) ReadInt16() (int16, error)

func (*Decoder) ReadInt32

func (d *Decoder) ReadInt32() (int32, error)

func (*Decoder) ReadInt64

func (d *Decoder) ReadInt64() (int64, error)

func (*Decoder) ReadInt8

func (d *Decoder) ReadInt8() (int8, error)

func (*Decoder) ReadMapSize

func (d *Decoder) ReadMapSize() (uint32, bool, error)

func (*Decoder) ReadNull

func (d *Decoder) ReadNull() (bool, error)

func (*Decoder) ReadString

func (d *Decoder) ReadString() (string, error)

Read string of defined length

func (*Decoder) ReadTag

func (d *Decoder) ReadTag() (uint64, error)

func (*Decoder) ReadUint16

func (d *Decoder) ReadUint16() (uint16, error)

func (*Decoder) ReadUint32

func (d *Decoder) ReadUint32() (uint32, error)

func (*Decoder) ReadUint64

func (d *Decoder) ReadUint64() (uint64, error)

func (*Decoder) ReadUint8

func (d *Decoder) ReadUint8() (uint8, error)

func (*Decoder) Skip

func (d *Decoder) Skip() error

type Encoder

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

func NewEncoder

func NewEncoder(buffer []byte) Encoder

func (*Encoder) CheckError

func (e *Encoder) CheckError() error

check whether any errors have occurred

func (*Encoder) WriteArraySize

func (e *Encoder) WriteArraySize(length uint32)

func (*Encoder) WriteBool

func (e *Encoder) WriteBool(value bool)

cbor ok

func (*Encoder) WriteByteArray

func (e *Encoder) WriteByteArray(value []byte)

func (*Encoder) WriteFloat32

func (e *Encoder) WriteFloat32(value float32)

func (*Encoder) WriteFloat64

func (e *Encoder) WriteFloat64(value float64)

func (*Encoder) WriteInt16

func (e *Encoder) WriteInt16(value int16)

cbor ok

func (*Encoder) WriteInt32

func (e *Encoder) WriteInt32(value int32)

cbor ok

func (*Encoder) WriteInt64

func (e *Encoder) WriteInt64(value int64)

func (*Encoder) WriteInt8

func (e *Encoder) WriteInt8(value int8)

cbor ok

func (*Encoder) WriteMapSize

func (e *Encoder) WriteMapSize(length uint32)

func (*Encoder) WriteNil

func (e *Encoder) WriteNil()

cbor ok

func (*Encoder) WriteString

func (e *Encoder) WriteString(value string)

func (*Encoder) WriteUint16

func (e *Encoder) WriteUint16(value uint16)

func (*Encoder) WriteUint32

func (e *Encoder) WriteUint32(value uint32)

func (*Encoder) WriteUint64

func (e *Encoder) WriteUint64(value uint64)

cbor ok

func (*Encoder) WriteUint8

func (e *Encoder) WriteUint8(value uint8)

type ReadError

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

func NewReadError

func NewReadError(s string) ReadError

func (ReadError) Error

func (r ReadError) Error() string

type Sizer

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

func NewSizer

func NewSizer() Sizer

func (*Sizer) CheckError

func (s *Sizer) CheckError() error

check whether any errors have occurred

func (*Sizer) Len

func (s *Sizer) Len() uint32

func (*Sizer) WriteArraySize

func (s *Sizer) WriteArraySize(length uint32)

func (*Sizer) WriteBool

func (s *Sizer) WriteBool(value bool)

func (*Sizer) WriteByteArray

func (s *Sizer) WriteByteArray(value []byte)

func (*Sizer) WriteFloat32

func (s *Sizer) WriteFloat32(value float32)

func (*Sizer) WriteFloat64

func (s *Sizer) WriteFloat64(value float64)

func (*Sizer) WriteInt16

func (s *Sizer) WriteInt16(value int16)

func (*Sizer) WriteInt32

func (s *Sizer) WriteInt32(value int32)

func (*Sizer) WriteInt64

func (s *Sizer) WriteInt64(value int64)

func (*Sizer) WriteInt8

func (s *Sizer) WriteInt8(value int8)

func (*Sizer) WriteMapSize

func (s *Sizer) WriteMapSize(length uint32)

func (*Sizer) WriteNil

func (s *Sizer) WriteNil()

func (*Sizer) WriteString

func (s *Sizer) WriteString(value string)

func (*Sizer) WriteUint16

func (s *Sizer) WriteUint16(value uint16)

func (*Sizer) WriteUint32

func (s *Sizer) WriteUint32(value uint32)

func (*Sizer) WriteUint64

func (s *Sizer) WriteUint64(value uint64)

func (*Sizer) WriteUint8

func (s *Sizer) WriteUint8(value uint8)

type Writer

type Writer interface {
	WriteNil()
	WriteBool(value bool)
	WriteInt8(value int8)
	WriteInt16(value int16)
	WriteInt32(value int32)
	WriteInt64(value int64)
	WriteUint8(value uint8)
	WriteUint16(value uint16)
	WriteUint32(value uint32)
	WriteUint64(value uint64)
	WriteFloat32(value float32)
	WriteFloat64(value float64)
	WriteString(value string)
	WriteByteArray(value []byte)
	WriteArraySize(length uint32)
	WriteMapSize(length uint32)
	CheckError() error
}

Writer is the interface for writing data using the MessagePack format.

Jump to

Keyboard shortcuts

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