Documentation
¶
Index ¶
- Constants
- Variables
- func CborEncodeMajorType(t byte, l uint64) []byte
- func CborReadHeader(br io.Reader) (byte, uint64, error)
- func CborReadHeaderBuf(br io.Reader, scratch []byte) (byte, uint64, error)
- func CborWriteHeader(w io.Writer, t byte, l uint64) error
- func EncodeBool(b bool) []byte
- func GenMapEncodersForType(gti *GenTypeInfo, w io.Writer) error
- func GenTupleEncodersForType(gti *GenTypeInfo, w io.Writer) error
- func MakeByteString(h []byte) string
- func PrintHeaderAndUtilityMethods(w io.Writer, pkg string, typeInfos []*GenTypeInfo) error
- func ReadByteArray(br io.Reader, maxlen uint64) ([]byte, error)
- func ReadCid(br io.Reader) (cid.Cid, error)
- func ReadFullStringIntoBuf(cr *CborReader, buf []byte, maxLength uint64) (int, bool, error)
- func ReadString(r io.Reader) (string, error)
- func ReadStringBuf(r io.Reader, _ []byte) (string, error)deprecated
- func ReadStringWithMax(r io.Reader, maxLength uint64) (string, error)
- func ReadTaggedByteArray(br io.Reader, exptag uint64, maxlen uint64) (bs []byte, err error)
- func ScanForLinks(br io.Reader, cb func(cid.Cid)) (err error)
- func ValidateCBOR(b []byte) error
- func WriteBool(w io.Writer, b bool) error
- func WriteByteArray(bw io.Writer, bytes []byte) error
- func WriteCid(w io.Writer, c cid.Cid) error
- func WriteCidBuf(buf []byte, w io.Writer, c cid.Cid) error
- func WriteMajorTypeHeader(w io.Writer, t byte, l uint64) error
- func WriteMajorTypeHeaderBuf(buf []byte, w io.Writer, t byte, l uint64) error
- func WriteMapEncodersToFile(fname, pkg string, types ...interface{}) error
- func WriteTupleEncodersToFile(fname, pkg string, types ...interface{}) error
- type BytePeeker
- type CBORMarshaler
- type CBORUnmarshaler
- type CborBool
- type CborCid
- type CborInt
- type CborReader
- type CborTime
- type CborWriter
- type Deferred
- type Field
- type Gen
- func (g Gen) GenMapEncodersForType(gti *GenTypeInfo, w io.Writer) error
- func (g Gen) GenTupleEncodersForType(gti *GenTypeInfo, w io.Writer) error
- func (g Gen) PrintHeaderAndUtilityMethods(w io.Writer, pkg string, typeInfos []*GenTypeInfo) error
- func (g Gen) WriteMapEncodersToFile(fname, pkg string, types ...interface{}) error
- func (g Gen) WriteTupleEncodersToFile(fname, pkg string, types ...interface{}) error
- type GenTypeInfo
- type Import
Constants ¶
const ( MajUnsignedInt = 0 MajNegativeInt = 1 MajByteString = 2 MajTextString = 3 MajArray = 4 MajMap = 5 MajTag = 6 MajOther = 7 )
const ByteArrayMaxLen = 2 << 20
const FieldNameSelf = "."
FieldNameSelf is the name of the field that is the marshal target itself. This is used in non-struct types which are handled like transparent structs.
const MaxLenTag = "maxlen"
const MaxLength = 8192
const NoUsrMaxLen = -1
Variables ¶
var ( CborBoolFalse = []byte{0xf4} CborBoolTrue = []byte{0xf5} CborNull = []byte{0xf6} )
Functions ¶
func CborEncodeMajorType ¶
func CborReadHeaderBuf ¶
same as the above, just tries to allocate less by using a passed in scratch buffer
func EncodeBool ¶
func GenMapEncodersForType ¶
func GenMapEncodersForType(gti *GenTypeInfo, w io.Writer) error
GenMapEncodersForType is a convenience wrapper around Gen.GenMapEncodersForType using default options.
func GenTupleEncodersForType ¶
func GenTupleEncodersForType(gti *GenTypeInfo, w io.Writer) error
GenTupleEncodersForType is a convenience wrapper around Gen.GenTupleEncodersForType using default options.
func MakeByteString ¶
func PrintHeaderAndUtilityMethods ¶
func PrintHeaderAndUtilityMethods(w io.Writer, pkg string, typeInfos []*GenTypeInfo) error
PrintHeaderAndUtilityMethods is a convenience wrapper around Gen.PrintHeaderAndUtilityMethods using default options.
func ReadFullStringIntoBuf ¶ added in v0.3.0
ReadFullStringIntoBuf will read a string off the given stream, consuming the entire cbor item if the string on the stream is longer than the buffer, the string is discarded and 'false' is returned Note: Will only read data into the buffer if the data fits into the buffer, otherwise the bytes are discarded entirely
func ReadTaggedByteArray ¶
func ValidateCBOR ¶
ValidateCBOR validates that a byte array is a single valid CBOR object.
func WriteByteArray ¶
WriteByteArray encodes a byte array as a cbor byte-string.
func WriteMajorTypeHeader ¶
TODO: No matter what I do, this function *still* allocates. Its super frustrating. See issue: https://github.com/golang/go/issues/33160
func WriteMajorTypeHeaderBuf ¶
Same as the above, but uses a passed in buffer to avoid allocations
func WriteMapEncodersToFile ¶
WriteMapFileEncodersToFile is a convenience wrapper around Gen.WriteMapEncodersToFile using default options.
func WriteTupleEncodersToFile ¶
WriteTupleFileEncodersToFile is a convenience wrapper around Gen.WriteTupleEncodersToFile using default options.
Types ¶
type BytePeeker ¶
type BytePeeker interface { io.Reader io.ByteScanner }
BytePeeker combines the Reader and ByteScanner interfaces.
func GetPeeker ¶
func GetPeeker(r io.Reader) BytePeeker
type CBORMarshaler ¶
type CBORUnmarshaler ¶
type CborReader ¶
type CborReader struct {
// contains filtered or unexported fields
}
func NewCborReader ¶
func NewCborReader(r io.Reader) *CborReader
func (*CborReader) ReadByte ¶
func (cr *CborReader) ReadByte() (byte, error)
func (*CborReader) ReadHeader ¶
func (cr *CborReader) ReadHeader() (byte, uint64, error)
func (*CborReader) SetReader ¶
func (cr *CborReader) SetReader(r io.Reader)
func (*CborReader) UnreadByte ¶
func (cr *CborReader) UnreadByte() error
type CborWriter ¶
type CborWriter struct {
// contains filtered or unexported fields
}
func NewCborWriter ¶
func NewCborWriter(w io.Writer) *CborWriter
func (*CborWriter) CborWriteHeader ¶
func (cw *CborWriter) CborWriteHeader(t byte, l uint64) error
func (*CborWriter) SetWriter ¶
func (cw *CborWriter) SetWriter(w io.Writer)
func (*CborWriter) WriteMajorTypeHeader ¶
func (cw *CborWriter) WriteMajorTypeHeader(t byte, l uint64) error
func (*CborWriter) WriteString ¶
func (cw *CborWriter) WriteString(s string) (int, error)
type Field ¶
type Gen ¶
type Gen struct { MaxArrayLength int // Default: 8192 (MaxLength) MaxByteLength int // Default: 2<<20 (ByteArrayMaxLen) MaxStringLength int // Default: 8192 (MaxLength) // Write output file in order of type names SortTypeNames bool }
Gen is a configurable code generator for CBOR types. Use this instead of the convenience functions to have more control over the generated code.
func (Gen) GenMapEncodersForType ¶
func (g Gen) GenMapEncodersForType(gti *GenTypeInfo, w io.Writer) error
Generates 'tuple representation' cbor encoders for the given type
func (Gen) GenTupleEncodersForType ¶
func (g Gen) GenTupleEncodersForType(gti *GenTypeInfo, w io.Writer) error
Generates 'tuple representation' cbor encoders for the given type
func (Gen) PrintHeaderAndUtilityMethods ¶
func (Gen) WriteMapEncodersToFile ¶
WriteMapFileEncodersToFile generates map backed MarshalCBOR and UnmarshalCBOR implementations for the given types in the specified file, with the specified package name.
The MarshalCBOR and UnmarshalCBOR implementations will marshal/unmarshal each type's fields as a map of field names to field values.
func (Gen) WriteTupleEncodersToFile ¶
WriteTupleFileEncodersToFile generates array backed MarshalCBOR and UnmarshalCBOR implementations for the given types in the specified file, with the specified package name.
The MarshalCBOR and UnmarshalCBOR implementations will marshal/unmarshal each type's fields as a fixed-length CBOR array of field values.
type GenTypeInfo ¶
func ParseTypeInfo ¶
func ParseTypeInfo(itype interface{}) (*GenTypeInfo, error)
func (*GenTypeInfo) Imports ¶
func (gti *GenTypeInfo) Imports() []Import
func (GenTypeInfo) MapHeader ¶
func (gti GenTypeInfo) MapHeader() []byte
func (GenTypeInfo) MapHeaderAsByteString ¶
func (gti GenTypeInfo) MapHeaderAsByteString() string
func (*GenTypeInfo) MaxMapKeyLength ¶ added in v0.3.0
func (gti *GenTypeInfo) MaxMapKeyLength() int
func (GenTypeInfo) TupleHeader ¶
func (gti GenTypeInfo) TupleHeader() []byte
func (GenTypeInfo) TupleHeaderAsByteString ¶
func (gti GenTypeInfo) TupleHeaderAsByteString() string