Documentation ¶
Overview ¶
package zebra specifies the ZebraPack serialization format. To bootstrap, the ZebraPack schema is itself stored in msgpack2 (with optional JSON) format with embedded strings for field names.
Index ¶
- func ZebraSchemaInJsonCompact() []byte
- func ZebraSchemaInJsonPretty() []byte
- func ZebraSchemaInMsgpack2Format() []byte
- type Field
- func (z *Field) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *Field) EncodeMsg(en *msgp.Writer) (err error)
- func (z *Field) MarshalMsg(b []byte) (o []byte, err error)
- func (z *Field) Msgsize() (s int)
- func (z *Field) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (z *Field) UnmarshalMsgWithCfg(bts []byte, cfg *msgp.RuntimeConfig) (o []byte, err error)
- type Schema
- func (z *Schema) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *Schema) EncodeMsg(en *msgp.Writer) (err error)
- func (z *Schema) MarshalMsg(b []byte) (o []byte, err error)
- func (z *Schema) Msgsize() (s int)
- func (z *Schema) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (z *Schema) UnmarshalMsgWithCfg(bts []byte, cfg *msgp.RuntimeConfig) (o []byte, err error)
- func (s *Schema) WriteToGo(w io.Writer, path string, pkg string) (err error)
- func (sch *Schema) ZebraToMsgp2(bts []byte) (out []byte, left []byte, err error)
- type Struct
- func (z *Struct) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *Struct) EncodeMsg(en *msgp.Writer) (err error)
- func (z *Struct) MarshalMsg(b []byte) (o []byte, err error)
- func (z *Struct) Msgsize() (s int)
- func (z *Struct) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (z *Struct) UnmarshalMsgWithCfg(bts []byte, cfg *msgp.RuntimeConfig) (o []byte, err error)
- func (s *Struct) WriteToGo(w io.Writer) (err error)
- type Zkind
- func (z *Zkind) DecodeMsg(dc *msgp.Reader) (err error)
- func (z Zkind) EncodeMsg(en *msgp.Writer) (err error)
- func (z Zkind) MarshalMsg(b []byte) (o []byte, err error)
- func (z Zkind) Msgsize() (s int)
- func (i Zkind) String() string
- func (z *Zkind) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (z *Zkind) UnmarshalMsgWithCfg(bts []byte, cfg *msgp.RuntimeConfig) (o []byte, err error)
- type Ztype
- func (z *Ztype) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *Ztype) EncodeMsg(en *msgp.Writer) (err error)
- func (z *Ztype) MarshalMsg(b []byte) (o []byte, err error)
- func (z *Ztype) Msgsize() (s int)
- func (z *Ztype) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (z *Ztype) UnmarshalMsgWithCfg(bts []byte, cfg *msgp.RuntimeConfig) (o []byte, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ZebraSchemaInJsonCompact ¶ added in v0.300.0
func ZebraSchemaInJsonCompact() []byte
ZebraSchemaInJsonCompact provides the ZebraPack Schema in compact JSON format, length 4152 bytes
func ZebraSchemaInJsonPretty ¶ added in v0.300.0
func ZebraSchemaInJsonPretty() []byte
ZebraSchemaInJsonPretty provides the ZebraPack Schema in pretty JSON format, length 10901 bytes
func ZebraSchemaInMsgpack2Format ¶ added in v0.300.0
func ZebraSchemaInMsgpack2Format() []byte
ZebraSchemaInMsgpack2Format provides the ZebraPack Schema in msgpack2 format, length 3224 bytes
Types ¶
type Field ¶
type Field struct { // Zid is the zebrapack id Zid int64 // the name of the field in the Go schema/source file. FieldGoName string // optional wire-name designated by a // `msg:"tagname"` tag on the struct field. FieldTagName string // human readable/Go type description FieldTypeStr string `msg:",omitempty"` // the broad category of this type. empty if Skip is true FieldCategory Zkind `msg:",omitempty"` // avail if FieldCategory == BaseElemCat FieldPrimitive Zkind `msg:",omitempty"` // the machine-parse-able type tree FieldFullType *Ztype `msg:",omitempty"` // if OmitEmpty then we don't serialize // the field if it has its zero-value. OmitEmpty bool `msg:",omitempty"` // Skip means either type struct{} or // other unserializable type; // or marked as `msg:"-"`. In any case, // if Skip is true: do not serialize // this field when writing, and ignore it // when reading. Skip bool `msg:",omitempty"` // Deprecated means tagged with `deprecated:"true"`. // Compilers/libraries should discourage and warn // users away from writing to such fields, while // not making it impossible to either read or write // the field. Deprecated bool `msg:",omitempty"` }
Field represents fields within a struct.
func (*Field) DecodeMsg ¶
DecodeMsg implements msgp.Decodable We treat empty fields as if we read a Nil from the wire.
func (*Field) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
func (*Field) Msgsize ¶
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Field) UnmarshalMsg ¶
UnmarshalMsg implements msgp.Unmarshaler
func (*Field) UnmarshalMsgWithCfg ¶
type Schema ¶
type Schema struct { // SourcePath gives the path to the original Go // source file that was parsed to produce this schema. SourcePath string // SourcePackage notes the original package presented // by the SourcePath file. SourcePackage string // ZebraSchemaId is a randomly chosen but stable // 53-bit positive integer identifier (see // zebrapack -genid) that can be used to distinguish schemas. ZebraSchemaId int64 // Structs holds the collection of the main data // descriptor, the Struct. The key is identical // to Struct.StructName. // // This a map rather than a slice in order to: // a) insure there are no duplicate struct names; and // b) make decoding easy and fast. Structs map[string]*Struct // Imports archives the imports in the SourcePath // to make it possible to understand other package // type references. Imports []string }
Schema is the top level container in ZebraPack. It all starts here.
func (*Schema) DecodeMsg ¶
DecodeMsg implements msgp.Decodable We treat empty fields as if we read a Nil from the wire.
func (*Schema) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
func (*Schema) Msgsize ¶
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Schema) UnmarshalMsg ¶
UnmarshalMsg implements msgp.Unmarshaler
func (*Schema) UnmarshalMsgWithCfg ¶
type Struct ¶
type Struct struct { // StructName is the typename of the struct in Go. StructName string // Fields hold the individual Field descriptors. Fields []Field }
Struct represents a single message or struct.
func (*Struct) DecodeMsg ¶
DecodeMsg implements msgp.Decodable We treat empty fields as if we read a Nil from the wire.
func (*Struct) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
func (*Struct) Msgsize ¶
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Struct) UnmarshalMsg ¶
UnmarshalMsg implements msgp.Unmarshaler
func (*Struct) UnmarshalMsgWithCfg ¶
type Zkind ¶
type Zkind uint64
Zkind describes the detailed type of the field. Since it also stores the fixed size of a array type, it needs to be large. When serialized as msgpack2, it will be compressed.
Implentation note: primitives must correspond to gen/Primitive, as we will cast/convert them directly.
const ( // primitives. // Implementation note: must correspond to gen/Primitive. Invalid Zkind = 0 Bytes Zkind = 1 // []byte String Zkind = 2 Float32 Zkind = 3 Float64 Zkind = 4 Complex64 Zkind = 5 Complex128 Zkind = 6 Uint Zkind = 7 // 32 or 64 bit; as in Go, matches native word Uint8 Zkind = 8 Uint16 Zkind = 9 Uint32 Zkind = 10 Uint64 Zkind = 11 Byte Zkind = 12 Int Zkind = 13 // as in Go, matches native word size. Int8 Zkind = 14 Int16 Zkind = 15 Int32 Zkind = 16 Int64 Zkind = 17 Bool Zkind = 18 Intf Zkind = 19 // interface{} Time Zkind = 20 // time.Time Ext Zkind = 21 // extension // IDENT means an unrecognized identifier; // it typically means a named struct type. // The Str field in the Ztype will hold the // name of the struct. IDENT Zkind = 22 // compound types // implementation note: should correspond to gen/Elem. BaseElemCat Zkind = 23 MapCat Zkind = 24 StructCat Zkind = 25 SliceCat Zkind = 26 ArrayCat Zkind = 27 PointerCat Zkind = 28 )
func ZkindFromString ¶
func (*Zkind) DecodeMsg ¶
DecodeMsg implements msgp.Decodable We treat empty fields as if we read a Nil from the wire.
func (Zkind) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
func (Zkind) Msgsize ¶
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Zkind) UnmarshalMsg ¶
UnmarshalMsg implements msgp.Unmarshaler
func (*Zkind) UnmarshalMsgWithCfg ¶
type Ztype ¶
type Ztype struct { // Kind gives the exact type for primitives, // and the category for compound types. Kind Zkind // Str holds the struct name when Kind == 22 (IDENT). // Otherwise it typically reflects Kind directly // which is useful for human readability. Str string `msg:",omitempty"` // Domain holds the key type for maps. For // pointers and slices it holds the element type. // For arrays, it holds the fixed size. // Domain is null when Kind is a primitive. Domain *Ztype `msg:",omitempty"` // Range holds the value type for maps. // For arrays (always a fixed size), Range holds // the element type. Otherwise Range is // typically null. Range *Ztype `msg:",omitempty"` }
Ztype describes any type, be it a BaseElem, Map, Struct, Slice, Array, or Pointer.
func (*Ztype) DecodeMsg ¶
DecodeMsg implements msgp.Decodable We treat empty fields as if we read a Nil from the wire.
func (*Ztype) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
func (*Ztype) Msgsize ¶
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Ztype) UnmarshalMsg ¶
UnmarshalMsg implements msgp.Unmarshaler