typegen

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2021 License: MIT Imports: 16 Imported by: 0

README

cbor-gen

Some basic utilities to generate fast path cbor codecs for your types.

License

MIT

Documentation

Index

Constants

View Source
const (
	MajUnsignedInt = 0
	MajNegativeInt = 1
	MajByteString  = 2
	MajTextString  = 3
	MajArray       = 4
	MajMap         = 5
	MajTag         = 6
	MajOther       = 7
)
View Source
const ByteArrayMaxLen = 2 << 20
View Source
const MaxLength = 8192

Variables

View Source
var (
	CborBoolFalse = []byte{0xf4}
	CborBoolTrue  = []byte{0xf5}
	CborNull      = []byte{0xf6}
)

Functions

func CborEncodeMajorType

func CborEncodeMajorType(t byte, l uint64) []byte

func CborReadHeader

func CborReadHeader(br io.Reader) (byte, uint64, error)

func CborReadHeaderBuf

func CborReadHeaderBuf(br io.Reader, scratch []byte) (byte, uint64, error)

same as the above, just tries to allocate less by using a passed in scratch buffer

func CborWriteHeader

func CborWriteHeader(w io.Writer, t byte, l uint64) error

func EncodeBool

func EncodeBool(b bool) []byte

func GenMapEncodersForType

func GenMapEncodersForType(inpkg string, i interface{}, w io.Writer) error

Generates 'tuple representation' cbor encoders for the given type

func GenTupleEncodersForType

func GenTupleEncodersForType(inpkg string, i interface{}, w io.Writer) error

Generates 'tuple representation' cbor encoders for the given type

func PrintHeaderAndUtilityMethods

func PrintHeaderAndUtilityMethods(w io.Writer, pkg string) error

func ReadByteArray

func ReadByteArray(br io.Reader, maxlen uint64) ([]byte, error)

func ReadCid

func ReadCid(br io.Reader) (cid.Cid, error)

func ReadString

func ReadString(r io.Reader) (string, error)

func ReadStringBuf

func ReadStringBuf(r io.Reader, scratch []byte) (string, error)

func ReadTaggedByteArray

func ReadTaggedByteArray(br io.Reader, exptag uint64, maxlen uint64) ([]byte, error)
func ScanForLinks(br io.Reader, cb func(cid.Cid)) error

func WriteBool

func WriteBool(w io.Writer, b bool) error

func WriteCid

func WriteCid(w io.Writer, c cid.Cid) error

func WriteCidBuf

func WriteCidBuf(buf []byte, w io.Writer, c cid.Cid) error

func WriteMajorTypeHeader

func WriteMajorTypeHeader(w io.Writer, t byte, l uint64) error

TODO: No matter what I do, this function *still* allocates. Its super frustrating. See issue: https://github.com/golang/go/issues/33160

func WriteMajorTypeHeaderBuf

func WriteMajorTypeHeaderBuf(buf []byte, w io.Writer, t byte, l uint64) error

Same as the above, but uses a passed in buffer to avoid allocations

func WriteMapEncodersToFile

func WriteMapEncodersToFile(fname, pkg string, types ...interface{}) error

func WriteTupleEncodersToFile

func WriteTupleEncodersToFile(fname, pkg string, types ...interface{}) error

Types

type BytePeeker

type BytePeeker interface {
	io.Reader
	PeekByte() (byte, error)
}

this is a bit gnarly i should just switch to taking in a byte array at the top level

func GetPeeker

func GetPeeker(r io.Reader) BytePeeker

type CBORMarshaler

type CBORMarshaler interface {
	MarshalCBOR(io.Writer) error
}

type CBORUnmarshaler

type CBORUnmarshaler interface {
	UnmarshalCBOR(io.Reader) error
}

type CborBool

type CborBool bool

func (*CborBool) MarshalCBOR

func (cb *CborBool) MarshalCBOR(w io.Writer) error

func (*CborBool) UnmarshalCBOR

func (cb *CborBool) UnmarshalCBOR(r io.Reader) error

type CborCid

type CborCid cid.Cid

func (*CborCid) MarshalCBOR

func (c *CborCid) MarshalCBOR(w io.Writer) error

func (*CborCid) UnmarshalCBOR

func (c *CborCid) UnmarshalCBOR(r io.Reader) error

type CborInt

type CborInt int64

func (*CborInt) MarshalCBOR

func (ci *CborInt) MarshalCBOR(w io.Writer) error

func (*CborInt) UnmarshalCBOR

func (ci *CborInt) UnmarshalCBOR(r io.Reader) error

type Deferred

type Deferred struct {
	Raw []byte
	// contains filtered or unexported fields
}

func (*Deferred) Child

func (d *Deferred) Child() Deferred

func (*Deferred) MarshalCBOR

func (d *Deferred) MarshalCBOR(w io.Writer) error

func (*Deferred) UnmarshalCBOR

func (d *Deferred) UnmarshalCBOR(br io.Reader) error

type Field

type Field struct {
	Name    string
	Pointer bool
	Type    reflect.Type
	Pkg     string

	IterLabel string
}

func (Field) ElemName

func (f Field) ElemName() string

func (Field) IsArray

func (f Field) IsArray() bool

func (Field) Len

func (f Field) Len() int

func (Field) TypeName

func (f Field) TypeName() string

type GenTypeInfo

type GenTypeInfo struct {
	Name   string
	Fields []Field
}

func ParseTypeInfo

func ParseTypeInfo(pkg string, i interface{}) (*GenTypeInfo, error)

func (GenTypeInfo) MapHeader

func (gti GenTypeInfo) MapHeader() []byte

func (GenTypeInfo) MapHeaderAsByteString

func (gti GenTypeInfo) MapHeaderAsByteString() string

func (*GenTypeInfo) NeedsScratch

func (gti *GenTypeInfo) NeedsScratch() bool

func (GenTypeInfo) TupleHeader

func (gti GenTypeInfo) TupleHeader() []byte

func (GenTypeInfo) TupleHeaderAsByteString

func (gti GenTypeInfo) TupleHeaderAsByteString() string

Jump to

Keyboard shortcuts

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