Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeUvarint(in io.Reader) (uint, error)
- func DecodeVarint(in io.Reader) (int, error)
- func EncodeUvarint(out io.Writer, n int) error
- func EncodeVarint(out io.Writer, n int) error
- func Equal(o1 interface{}, o2 interface{}) bool
- func IsZero(v reflect.Value) bool
- func Marshal(data interface{}) ([]byte, error)
- func Pretty(o interface{}) string
- func TagName(tag int) string
- func Unmarshal(b []byte, data interface{}) error
- func ValidMapKey(key interface{}) bool
- func ValidMapKeyType(t reflect.Type) bool
- type AlphaName
- type ArrayOfInt
- type BigStruct
- type BigTest
- type ComplicatedOptions
- type CompoundName
- type Decoder
- func (d *Decoder) BoolValue() bool
- func (d *Decoder) CurrentCount() int
- func (d *Decoder) Decode(data interface{}) error
- func (d *Decoder) DecodeArray() ([]interface{}, error)
- func (d *Decoder) DecodeArrayReflect(v reflect.Value) error
- func (d *Decoder) DecodeMap() (map[string]interface{}, error)
- func (d *Decoder) DecodeMapReflect(v reflect.Value) error
- func (d *Decoder) DecodeReflect(v reflect.Value) error
- func (d *Decoder) DecodeStruct() (map[string]interface{}, error)
- func (d *Decoder) DecodeStructReflect(v reflect.Value) error
- func (d *Decoder) Error() error
- func (d *Decoder) Int16Value() int16
- func (d *Decoder) Int32Value() int32
- func (d *Decoder) Int64Value() int64
- func (d *Decoder) Int8Value() int8
- func (d *Decoder) ParseBool() bool
- func (d *Decoder) ParseBytes() ([]byte, error)
- func (d *Decoder) ParseFloat32() (float32, error)
- func (d *Decoder) ParseFloat64() (float64, error)
- func (d *Decoder) ParseInt() int
- func (d *Decoder) ParseInt64() int64
- func (d *Decoder) ParseString() (string, error)
- func (d *Decoder) ParseSymbol() (string, error)
- func (d *Decoder) ParseTimestamp() (rdl.Timestamp, error)
- func (d *Decoder) ParseUUID() (rdl.UUID, error)
- func (d *Decoder) ParseUnsigned() uint
- func (d *Decoder) ParseUnsigned64() uint64
- func (d *Decoder) ReadInt() int
- func (d *Decoder) ReadInt32() int32
- func (d *Decoder) ReadSize() int
- func (d *Decoder) ReadType() (*Signature, error)
- func (d *Decoder) ReadUnsigned() int
- type Drawing
- type Encoder
- func (enc *Encoder) Bytes() []byte
- func (enc *Encoder) Encode(data interface{}) error
- func (enc *Encoder) EncodeArray(val []interface{}, useMarshallable bool) error
- func (enc *Encoder) EncodeBool(val bool) error
- func (enc *Encoder) EncodeBytes(val []byte) error
- func (enc *Encoder) EncodeFloat32(val float32) error
- func (enc *Encoder) EncodeFloat64(val float64) error
- func (enc *Encoder) EncodeInt16(val int16) error
- func (enc *Encoder) EncodeInt32(val int32) error
- func (enc *Encoder) EncodeInt64(val int64) error
- func (enc *Encoder) EncodeInt8(val int8) error
- func (enc *Encoder) EncodeNull() error
- func (enc *Encoder) EncodeReflect(data interface{}) error
- func (enc *Encoder) EncodeString(val string) error
- func (enc *Encoder) EncodeStruct(val rdl.Struct, useMarshallable bool) error
- func (enc *Encoder) EncodeSymbol(val rdl.Symbol) error
- func (enc *Encoder) EncodeTimestamp(val rdl.Timestamp) error
- func (enc *Encoder) EncodeUUID(val rdl.UUID) error
- func (enc *Encoder) Error() error
- func (enc *Encoder) Flush() error
- func (enc *Encoder) WriteBool(val bool) error
- func (enc *Encoder) WriteBytes(b []byte) error
- func (enc *Encoder) WriteFloat32(n float32) error
- func (enc *Encoder) WriteFloat64(n float64) error
- func (enc *Encoder) WriteInt(n int) error
- func (enc *Encoder) WriteInt16(val int16) error
- func (enc *Encoder) WriteInt32(val int32) error
- func (enc *Encoder) WriteInt64(nn int64) error
- func (enc *Encoder) WriteInt8(val int8) error
- func (enc *Encoder) WriteSize(val int) error
- func (enc *Encoder) WriteString(s string) error
- func (enc *Encoder) WriteSymbol(name string) error
- func (enc *Encoder) WriteTag(val int) error
- func (enc *Encoder) WriteTimestamp(val rdl.Timestamp) error
- func (enc *Encoder) WriteType(sig *Signature) error
- func (enc *Encoder) WriteUUID(u rdl.UUID) error
- func (enc *Encoder) WriteUnsigned(val int) error
- type FieldSignature
- type IntOOBTest
- type LargeInt
- type Latitude
- type LongNumber
- type MapArrayTest
- type MapTest
- type NegativeNumberTest
- type Options
- type Pi
- type Point
- type Polyline
- type Rect
- type RegularInt
- type Shape
- type ShapeVariantTag
- type Signature
- type SimpleName
- type SmallInt
- type StringTest
- type Symbolic
- type TBinMarshallable
- type TBinUnmarshallable
- type TimestampTest
- type TinyInt
- type UUIDTest
- type YEncoded
- type Year
Constants ¶
const AnyTag = 0x10 // used only as a value for array items, map items and keys, and in defstruct.
const ArrayTag = 0x0d // "ARRAYTAG uvarint(size) value*"
const BoolTag = 0x01 // "uvarint(b? 1 : 0)"
const BytesTag = 0x08 // "BYTESTAG uvarint(len) byte*"
const CurVersionTag = VersionTag + (CurrentVersion - 1) // "0001 1000
const CurrentVersion = 1 // the first versioned version
const DefArrayTag = 0x11 // "<newtag> DefArrayTag itemsTag"
const DefEnumTag = 0x15 // "<newtag> DefEnumTag <count> (uvarint(symlen) symbytes*)*"
const DefMapTag = 0x12 // "<newtag> DefMapTag keysTag itemsTag"
const DefStructTag = 0x13 // "<newtag> DefStructTag <fieldcount> (uvarint(fnamelen) fnamebytes* ftypeTag)*"
const DefUnionTag = 0x14 // "<newtag> DefUnionTag <count> variantTag*"
const EnumTag = 0x17
EnumTag identifies unused, reserved tags.
const FirstUserTag = 0x40 //0x40..0x7f all fit in a single byte tag. Subsequent tags take more. The tag is an unsigned varint.
const Float32Tag = 0x06 // "FLOAT32TAG 4_bytes"
const Float64Tag = 0x07 // "FLOAT64TAG 8_bytes"
const Int16Tag = 0x03 // "INT16TAG varint(n)"
const Int32Tag = 0x04 // "INT32TAG varint(n)"
const Int64Tag = 0x05 // "INT64TAG varint(n)"
const Int8Tag = 0x02 // "INT8TAG varint(n)"
const MapTag = 0x0e // "MAPTAG uvarint(size) (<value> <value>)*"
const MaxVersion = VersionDataMask + 1
const MaxVersionTag = VersionTag + VersionDataMask
const MinVersionTag = VersionTag
const NullTag = 0x00 // "nil" or "null"
const StringTag = 0x09 // "STRINGTAG uvarint(utflen) utf8bytes*"
const StructTag = 0x0f // "STRUCTTAG uvarint(size) (<symbol> <value>)*" -- for generic structs (native Go structs are their ownb type/tag)
const SymbolTag = 0x0b // "SYMBOLTAG uvarint(id) [string(name)]" the name is only included the first occurrence
const TimestampTag = 0x0a // "TIMESTAMPTAG double" - represented as seconds since epoch (1970)
const TinyStrDataMask = 0x1f
const TinyStrMaxlen = TinyStrDataMask
const TinyStrTag = 0x20 // "001x xxxx" <utf8byte>*
TinyStrTag is for strings that have a length up to 31 utf8 bytes. Again, this optimization has no effect on packed structs, just the generic encoding (187->160 for my test data). If symbols are used instead of strings, the savings are even bigger. But maps have strings, not symbols, as keys.
const TinyStrTagMask = 0xe0
const UUIDTag = 0x0c // "UUIDTAG byte[16]" = written as 16 bytes, no count
const UnionTag = 0x16
const VersionDataMask = 0x07
const VersionTag = 0x18 // "uvarint(0001 1xxx)"
VersionTag should be the first tag in the stream. v1..v8 are thus supported, after which additional byte(s) will be required. Bits encode (version - 1), i.e. currently encoded "0001 0000".
const VersionTagMask = 0xf8
Variables ¶
var Any = &Signature{Tag: AnyTag}
var Bool = &Signature{Tag: BoolTag}
var Bytes = &Signature{Tag: BytesTag}
var Float32 = &Signature{Tag: Float32Tag}
var Float64 = &Signature{Tag: Float64Tag}
var Int16 = &Signature{Tag: Int16Tag}
var Int32 = &Signature{Tag: Int32Tag}
var Int64 = &Signature{Tag: Int64Tag}
var Int8 = &Signature{Tag: Int8Tag}
var Null = &Signature{Tag: NullTag}
var String = &Signature{Tag: StringTag}
var Symbol = &Signature{Tag: SymbolTag}
var Timestamp = &Signature{Tag: TimestampTag}
var UUID = &Signature{Tag: UUIDTag}
Functions ¶
func DecodeUvarint ¶
DecodeUvarint decodes the uvarint from the Reader.
func DecodeVarint ¶
DecodeVarint decodes the varint from the Reader.
func EncodeUvarint ¶
EncodeUvarint encodes the uvarint to the Writer.
func EncodeVarint ¶
EncodeVarint encodes the varint to the Writer.
func Unmarshal ¶
Unmarshal - decode the TBin byte array into the specified target entity. If the target entity is a pointer to an interface{}, it will decode into the appropriate primitive types, along with map[string]interface{} for any structs and maps, and []interface{} for any arrays. If a pointer to a particular struct type is provided, it is filled with data as best it can, allocating substructure as needed. In this, it tries to imitate the encoding/json behavior.
func ValidMapKey ¶
func ValidMapKey(key interface{}) bool
func ValidMapKeyType ¶
Types ¶
type BigStruct ¶
type BigStruct struct { MyName string `json:"myName"` MyUtfname string `json:"myUtfname"` MyBool bool `json:"myBool"` MyByte int8 `json:"myByte"` MyShort int16 `json:"myShort"` MyInt int32 `json:"myInt"` MyLong int64 `json:"myLong"` MyFloat float32 `json:"myFloat"` MyDouble float64 `json:"myDouble"` MyIntArray []int32 `json:"myIntArray"` MyStringArray []string `json:"myStringArray"` MyMap map[string]int32 `json:"myMap"` MyUuid rdl.UUID `json:"myUuid"` MyStringSubtype azAZ `json:"myStringSubtype"` MyInt32Subtype Year `json:"myInt32Subtype"` MyFloat64Subtype Pi `json:"myFloat64Subtype"` MyTime rdl.Timestamp `json:"myTime"` }
BigStruct -
func NewBigStruct ¶
NewBigStruct - creates an initialized BigStruct instance, returns a pointer to it
func (*BigStruct) UnmarshalJSON ¶
UnmarshalJSON is defined for proper JSON decoding of a BigStruct
type BigTest ¶
type BigTest struct {
Stuff []*BigStruct `json:"stuff"`
}
BigTest -
func NewBigTest ¶
NewBigTest - creates an initialized BigTest instance, returns a pointer to it
func (*BigTest) UnmarshalJSON ¶
UnmarshalJSON is defined for proper JSON decoding of a BigTest
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder - the state for the decoder
func NewDecoder ¶
NewDecoder - create and return a new Encoder. This is a "session" for tbin, i.e. accumulated state for this encoder can make repeated Marshal calls more efficient.
func (*Decoder) CurrentCount ¶
func (*Decoder) DecodeArray ¶
func (*Decoder) DecodeStruct ¶
func (*Decoder) Int16Value ¶
func (*Decoder) Int32Value ¶
func (*Decoder) Int64Value ¶
func (*Decoder) ParseBytes ¶
func (*Decoder) ParseFloat32 ¶
func (*Decoder) ParseFloat64 ¶
func (*Decoder) ParseInt64 ¶
func (*Decoder) ParseString ¶
func (*Decoder) ParseSymbol ¶
func (*Decoder) ParseUnsigned ¶
func (*Decoder) ParseUnsigned64 ¶
func (*Decoder) ReadUnsigned ¶
type Drawing ¶
type Drawing struct {
Shapes []*Shape `json:"shapes"`
}
Drawing -
func NewDrawing ¶
NewDrawing - creates an initialized Drawing instance, returns a pointer to it
func (*Drawing) UnmarshalJSON ¶
UnmarshalJSON is defined for proper JSON decoding of a Drawing
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder - the state for the encoder.
func NewEncoder ¶
NewEncoder - create and return a new Encoder. This is a "session" for tbin, i.e. accumulated state for this encoder can make repeated Marshal calls more efficient.
func (*Encoder) Encode ¶
Encode - this encoder method marshals an arbitrary object. It first checks of the object implements the TBinMarshallable interface, and if so calls the objects Marshal method. Otherwise, it uses reflection on the object to determine how to marshal it.
func (*Encoder) EncodeArray ¶
func (*Encoder) EncodeBool ¶
func (*Encoder) EncodeBytes ¶
func (*Encoder) EncodeFloat32 ¶
func (*Encoder) EncodeFloat64 ¶
func (*Encoder) EncodeInt16 ¶
func (*Encoder) EncodeInt32 ¶
func (*Encoder) EncodeInt64 ¶
func (*Encoder) EncodeInt8 ¶
func (*Encoder) EncodeNull ¶
func (*Encoder) EncodeReflect ¶
EncodeReflect - encode the data *without* using any TbinMarshallable support, relying solely on reflection
func (*Encoder) EncodeString ¶
func (*Encoder) EncodeStruct ¶
func (*Encoder) WriteBytes ¶
func (*Encoder) WriteFloat32 ¶
WriteFloat32 - writes the signed 32 bit float as a varint
func (*Encoder) WriteFloat64 ¶
WriteFloat64 - writes the signed 64 bit float as a varint
func (*Encoder) WriteInt16 ¶
WriteInt16 - writes the signed 16 bit integer as a varint
func (*Encoder) WriteInt32 ¶
WriteInt32 - writes the signed 32 bit integer as a varint
func (*Encoder) WriteInt64 ¶
WriteInt64 - writes the signed 64 bit integer as a varint
func (*Encoder) WriteString ¶
func (*Encoder) WriteSymbol ¶
func (*Encoder) WriteType ¶
WriteType takes a signature and writes the tag for it. If it is the first time the signature has been encountered, a new tag is allocated and written followed by its definition.
func (*Encoder) WriteUnsigned ¶
WriteUnsigned - writes the int as a varuint. The argument is signed instead of unsigned because typical use cases (i.e. len(slice), or 0x40) themselves use int. An error is returned it the value is negative.
type FieldSignature ¶
type FieldSignature struct { Name string `json:"name"` Type *Signature `json:"type"` // contains filtered or unexported fields }
FieldSignature is the description of a single field in a Struct.
type IntOOBTest ¶
type IntOOBTest struct {
Theyear Year `json:"theyear"`
}
IntOOBTest -
func NewIntOOBTest ¶
func NewIntOOBTest(init ...*IntOOBTest) *IntOOBTest
NewIntOOBTest - creates an initialized IntOOBTest instance, returns a pointer to it
func (*IntOOBTest) UnmarshalJSON ¶
func (pTypeDef *IntOOBTest) UnmarshalJSON(b []byte) error
UnmarshalJSON is defined for proper JSON decoding of a IntOOBTest
func (*IntOOBTest) Validate ¶
func (pTypeDef *IntOOBTest) Validate() error
Validate - checks for missing required fields, etc
type MapArrayTest ¶
type MapArrayTest struct {
Locations map[string]ArrayOfInt `json:"locations"`
}
MapArrayTest -
func NewMapArrayTest ¶
func NewMapArrayTest(init ...*MapArrayTest) *MapArrayTest
NewMapArrayTest - creates an initialized MapArrayTest instance, returns a pointer to it
func (*MapArrayTest) Init ¶
func (pTypeDef *MapArrayTest) Init() *MapArrayTest
Init - sets up the instance according to its default field values, if any
func (*MapArrayTest) UnmarshalJSON ¶
func (pTypeDef *MapArrayTest) UnmarshalJSON(b []byte) error
UnmarshalJSON is defined for proper JSON decoding of a MapArrayTest
func (*MapArrayTest) Validate ¶
func (pTypeDef *MapArrayTest) Validate() error
Validate - checks for missing required fields, etc
type MapTest ¶
MapTest -
func NewMapTest ¶
NewMapTest - creates an initialized MapTest instance, returns a pointer to it
func (*MapTest) UnmarshalJSON ¶
UnmarshalJSON is defined for proper JSON decoding of a MapTest
type NegativeNumberTest ¶
type NegativeNumberTest struct {
Mylatitude Latitude `json:"mylatitude"`
}
NegativeNumberTest -
func NewNegativeNumberTest ¶
func NewNegativeNumberTest(init ...*NegativeNumberTest) *NegativeNumberTest
NewNegativeNumberTest - creates an initialized NegativeNumberTest instance, returns a pointer to it
func (*NegativeNumberTest) UnmarshalJSON ¶
func (pTypeDef *NegativeNumberTest) UnmarshalJSON(b []byte) error
UnmarshalJSON is defined for proper JSON decoding of a NegativeNumberTest
func (*NegativeNumberTest) Validate ¶
func (pTypeDef *NegativeNumberTest) Validate() error
Validate - checks for missing required fields, etc
type Options ¶
type Options int
Options - options comment
const ( ONE Options TWO THREE )
Options constants
func NewOptions ¶
func NewOptions(init ...interface{}) Options
NewOptions - return a string representation of the enum
func (Options) MarshalJSON ¶
MarshalJSON is defined for proper JSON encoding of a Options
func (*Options) UnmarshalJSON ¶
UnmarshalJSON is defined for proper JSON decoding of a Options
type Point ¶
Point -
func (*Point) UnmarshalJSON ¶
UnmarshalJSON is defined for proper JSON decoding of a Point
type Polyline ¶
type Polyline struct {
Points []*Point `json:"points"`
}
Polyline -
func NewPolyline ¶
NewPolyline - creates an initialized Polyline instance, returns a pointer to it
func (*Polyline) UnmarshalJSON ¶
UnmarshalJSON is defined for proper JSON decoding of a Polyline
type Rect ¶
Rect -
func (*Rect) UnmarshalJSON ¶
UnmarshalJSON is defined for proper JSON decoding of a Rect
type Shape ¶
type Shape struct { Variant ShapeVariantTag `rdl:"union"` Polyline *Polyline Rect *Rect }
Shape -
type ShapeVariantTag ¶
type ShapeVariantTag int
ShapeVariantTag - generated to support Shape
const ( ShapeVariantPolyline ShapeVariantTag ShapeVariantRect )
Supporting constants
type Signature ¶
type Signature struct { Tag int `json:"tag"` Fields []*FieldSignature `json:"fields,omitempty"` Items *Signature `json:"items,omitempty"` Keys *Signature `json:"keys,omitempty"` Variants []*Signature `json:"variants,omitempty"` Symbols []string `json:"symbols,omitempty"` // contains filtered or unexported fields }
Signature is a minimal description of a type.
func Struct ¶
func Struct(fields ...*FieldSignature) *Signature
func TypeSignature ¶
func TypeSignature(val interface{}) *Signature
TypeSignature returns a Signature for the type of the given data. Reflection is used.
type StringTest ¶
type StringTest struct { Name SimpleName `json:"name"` Parent CompoundName `json:"parent"` Names []SimpleName `json:"names,omitempty" rdl:"optional"` Enc YEncoded `json:"enc,omitempty" rdl:"optional"` }
StringTest -
func NewStringTest ¶
func NewStringTest(init ...*StringTest) *StringTest
NewStringTest - creates an initialized StringTest instance, returns a pointer to it
func (*StringTest) UnmarshalJSON ¶
func (pTypeDef *StringTest) UnmarshalJSON(b []byte) error
UnmarshalJSON is defined for proper JSON decoding of a StringTest
func (*StringTest) Validate ¶
func (pTypeDef *StringTest) Validate() error
Validate - checks for missing required fields, etc
type Symbolic ¶
type Symbolic interface {
Symbol() string
}
Symbolic is an interface wrapping the Symbol() method.
type TBinMarshallable ¶
TBinMarshallable - if an object implements this interface, it is used to marshal objects to TBin. This is optional, a default reflection-based encoder will be used for structs that do not implement this.
type TBinUnmarshallable ¶
TBinUnmarshallable - implement this interface to take control of decoding.
type TimestampTest ¶
TimestampTest -
func NewTimestampTest ¶
func NewTimestampTest(init ...*TimestampTest) *TimestampTest
NewTimestampTest - creates an initialized TimestampTest instance, returns a pointer to it
func (*TimestampTest) UnmarshalJSON ¶
func (pTypeDef *TimestampTest) UnmarshalJSON(b []byte) error
UnmarshalJSON is defined for proper JSON decoding of a TimestampTest
func (*TimestampTest) Validate ¶
func (pTypeDef *TimestampTest) Validate() error
Validate - checks for missing required fields, etc
type UUIDTest ¶
UUIDTest -
func NewUUIDTest ¶
NewUUIDTest - creates an initialized UUIDTest instance, returns a pointer to it
func (*UUIDTest) UnmarshalJSON ¶
UnmarshalJSON is defined for proper JSON decoding of a UUIDTest