gen

package
v4.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2017 License: MIT Imports: 14 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CryptoRandInt64

func CryptoRandInt64() int64

Use crypto/rand to get an random int64.

func IsEmptyBool

func IsEmptyBool(f string) string

func IsEmptyNumber

func IsEmptyNumber(f string) string

func IsEmptyTime

func IsEmptyTime(f string) string

func IsLenZero

func IsLenZero(f string) string

func IsNilInterface

func IsNilInterface(f string) string

func IsPrintable

func IsPrintable(e Elem) bool

func MathRandInt64

func MathRandInt64() int64

func SeedOurMathRandSrc

func SeedOurMathRandSrc(seed int64)

func SetFilename

func SetFilename(fn string)

Types

type Array

type Array struct {
	Common
	Index        string // index variable name
	SizeNamed    string // array size
	SizeResolved string // array size
	Els          Elem   // child
}

func (*Array) Complexity

func (a *Array) Complexity() int

func (*Array) Copy

func (a *Array) Copy() Elem

func (*Array) GetZtype

func (a *Array) GetZtype() (r zebra.Ztype)

func (*Array) IsInInterfaceSlice

func (s *Array) IsInInterfaceSlice() bool

func (*Array) IsInterface

func (s *Array) IsInterface() bool

func (*Array) SetIsInInterfaceSlice

func (s *Array) SetIsInInterfaceSlice()

func (*Array) SetVarname

func (a *Array) SetVarname(s string)

func (*Array) TypeName

func (a *Array) TypeName() string

func (*Array) ZeroLiteral

func (a *Array) ZeroLiteral(v string) string

type BaseElem

type BaseElem struct {
	Common
	ShimToBase   string    // shim to base type, or empty
	ShimFromBase string    // shim from base type, or empty
	Value        Primitive // Type of element
	Convert      bool      // should we do an explicit conversion?
	// contains filtered or unexported fields
}

BaseElem is an element that can be represented by a primitive MessagePack type.

func Ident

func Ident(id string, isIface bool) *BaseElem

Ident returns the *BaseElem that corresponds to the provided identity.

func (*BaseElem) Alias

func (s *BaseElem) Alias(typ string)

func (*BaseElem) BaseName

func (s *BaseElem) BaseName() string

BaseName returns the string form of the base type (e.g. Float64, Ident, etc)

func (*BaseElem) BaseType

func (s *BaseElem) BaseType() string

func (*BaseElem) Complexity

func (s *BaseElem) Complexity() int

func (*BaseElem) Copy

func (s *BaseElem) Copy() Elem

func (*BaseElem) FromBase

func (s *BaseElem) FromBase() string

FromBase, used if Convert==true, is used as {{Varname}} = {{FromBase}}(tmp)

func (*BaseElem) GetZtype

func (s *BaseElem) GetZtype() (r zebra.Ztype)

func (*BaseElem) IsInInterfaceSlice

func (s *BaseElem) IsInInterfaceSlice() bool

func (*BaseElem) IsInterface

func (s *BaseElem) IsInterface() bool

func (*BaseElem) Needsref

func (s *BaseElem) Needsref(b bool)

func (*BaseElem) Printable

func (s *BaseElem) Printable() bool

func (*BaseElem) Resolved

func (s *BaseElem) Resolved() bool

Resolved returns whether or not the type of the element is a primitive or a builtin provided by the package.

func (*BaseElem) SetIsInInterfaceSlice

func (s *BaseElem) SetIsInInterfaceSlice()

func (*BaseElem) SetVarname

func (s *BaseElem) SetVarname(a string)

func (*BaseElem) ToBase

func (s *BaseElem) ToBase() string

ToBase, used if Convert==true, is used as tmp = {{ToBase}}({{Varname}})

func (*BaseElem) TypeName

func (s *BaseElem) TypeName() string

TypeName returns the syntactically correct Go type name for the base element.

func (*BaseElem) ZeroLiteral

func (s *BaseElem) ZeroLiteral(v string) string

type Common

type Common struct {
	Skip bool
	// contains filtered or unexported fields
}

Common data/methods for every Elem

func (*Common) Alias

func (c *Common) Alias(typ string)

func (*Common) GetZid

func (c *Common) GetZid() int64

func (*Common) MethodPrefix

func (c *Common) MethodPrefix() string

func (*Common) SetHasMethodPrefix

func (c *Common) SetHasMethodPrefix(hmp HasMethodPrefix)

func (*Common) SetVarname

func (c *Common) SetVarname(s string)

func (*Common) SetZid

func (c *Common) SetZid(zid int64)

func (*Common) SkipMe

func (c *Common) SkipMe() bool

func (*Common) Varname

func (c *Common) Varname() string

type Elem

type Elem interface {
	// SetVarname sets this nodes
	// variable name and recursively
	// sets the names of all its children.
	// In general, this should only be
	// called on the parent of the tree.
	SetVarname(s string)

	// Varname returns the variable
	// name of the element.
	Varname() string

	// TypeName is the canonical
	// go type name of the node
	// e.g. "string", "int", "map[string]float64"
	// OR the alias name, if it has been set.
	TypeName() string

	// Alias sets a type (alias) name
	Alias(typ string)

	// Copy should perform a deep copy of the object
	Copy() Elem

	// Complexity returns a measure of the
	// complexity of element (greater than
	// or equal to 1.)
	Complexity() int

	// ZeroLiteral returns the literal expression
	// needed to initialize an element named v to its
	// zero value. e.g. 0 for numbers, "" for strings,
	// or Truck{} for a struct Truck.
	ZeroLiteral(v string) string

	// GetZtype provides type info in a uniform way.
	GetZtype() zebra.Ztype

	// for template instantiation with custom method prefix
	MethodPrefix() string
	SetHasMethodPrefix(hmp HasMethodPrefix)
	IsInterface() bool
	IsInInterfaceSlice() bool
	SetIsInInterfaceSlice()

	SkipMe() bool
	SetZid(zid int64)
	GetZid() int64
	// contains filtered or unexported methods
}

Elem is a go type capable of being serialized into MessagePack. It is implemented by *Ptr, *Struct, *Array, *Slice, *Map, and *BaseElem.

type HasMethodPrefix

type HasMethodPrefix interface {
	MethodPrefix() string
}

type Map

type Map struct {
	Common
	Keyidx string // key variable name
	Validx string // value variable name
	Value  Elem   // value element

	KeyTyp     string
	KeyDeclTyp string
}

Map is a map[string]Elem

func (*Map) Complexity

func (m *Map) Complexity() int

func (*Map) Copy

func (m *Map) Copy() Elem

func (*Map) GetZtype

func (m *Map) GetZtype() (r zebra.Ztype)

func (*Map) IsInInterfaceSlice

func (s *Map) IsInInterfaceSlice() bool

func (*Map) IsInterface

func (s *Map) IsInterface() bool

func (*Map) SetIsInInterfaceSlice

func (m *Map) SetIsInInterfaceSlice()

func (*Map) SetVarname

func (m *Map) SetVarname(s string)

func (*Map) TypeName

func (m *Map) TypeName() string

func (*Map) ZeroLiteral

func (m *Map) ZeroLiteral(v string) string

type Method

type Method uint16

Method is a bitfield representing something that the generator knows how to print.

const (
	Decode      Method = 1 << iota // msgp.Decodable
	Encode                         // msgp.Encodable
	Marshal                        // msgp.Marshaler
	Unmarshal                      // msgp.Unmarshaler
	Size                           // msgp.Sizer
	Test                           // generate tests
	FieldsEmpty                    // support omitempty tag

)

func (Method) String

func (m Method) String() string

String implements fmt.Stringer

type Primitive

type Primitive uint8

Base is one of the base types

const (
	Invalid Primitive = iota
	Bytes
	String
	Float32
	Float64
	Complex64
	Complex128
	Uint
	Uint8
	Uint16
	Uint32
	Uint64
	Byte
	Int
	Int8
	Int16
	Int32
	Int64
	Bool
	Intf // interface{}
	Time // time.Time
	Ext  // extension

	IDENT // IDENT means an unrecognized identifier
)

this is effectively the list of currently available ReadXxxx / WriteXxxx methods.

func (Primitive) String

func (k Primitive) String() string

type Printer

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

func NewPrinter

func NewPrinter(m Method, out io.Writer, tests io.Writer, cfg *cfg.ZebraConfig) *Printer

func (*Printer) ApplyDirective

func (p *Printer) ApplyDirective(pass Method, t TransformPass)

ApplyDirective applies a directive to a named pass and all of its dependents.

func (*Printer) Print

func (p *Printer) Print(e Elem) error

Print prints an Elem.

type Ptr

type Ptr struct {
	Common
	Value Elem
}

func (*Ptr) Complexity

func (s *Ptr) Complexity() int

func (*Ptr) Copy

func (s *Ptr) Copy() Elem

func (*Ptr) GetZtype

func (s *Ptr) GetZtype() (r zebra.Ztype)

func (*Ptr) IsInInterfaceSlice

func (s *Ptr) IsInInterfaceSlice() bool

func (*Ptr) IsInterface

func (s *Ptr) IsInterface() bool

func (*Ptr) Needsinit

func (s *Ptr) Needsinit() bool

func (*Ptr) SetIsInInterfaceSlice

func (s *Ptr) SetIsInInterfaceSlice()

func (*Ptr) SetVarname

func (s *Ptr) SetVarname(a string)

func (*Ptr) TypeName

func (s *Ptr) TypeName() string

func (*Ptr) ZeroLiteral

func (s *Ptr) ZeroLiteral(v string) string

type Slice

type Slice struct {
	Common
	Index string
	Els   Elem // The type of each element
}

func (*Slice) Complexity

func (s *Slice) Complexity() int

func (*Slice) Copy

func (s *Slice) Copy() Elem

func (*Slice) GetZtype

func (s *Slice) GetZtype() (r zebra.Ztype)

func (*Slice) IsInInterfaceSlice

func (s *Slice) IsInInterfaceSlice() bool

func (*Slice) IsInterface

func (s *Slice) IsInterface() bool

func (*Slice) SetIsInInterfaceSlice

func (s *Slice) SetIsInInterfaceSlice()

func (*Slice) SetVarname

func (s *Slice) SetVarname(a string)

func (*Slice) TypeName

func (s *Slice) TypeName() string

func (*Slice) ZeroLiteral

func (a *Slice) ZeroLiteral(v string) string

type Struct

type Struct struct {
	Common
	Fields  []StructField // field list
	AsTuple bool          // write as an array instead of a map

	KeyTyp string

	SkipCount int
	// contains filtered or unexported fields
}

func (*Struct) Complexity

func (s *Struct) Complexity() int

func (*Struct) Copy

func (s *Struct) Copy() Elem

func (*Struct) GetZtype

func (s *Struct) GetZtype() (r zebra.Ztype)

func (*Struct) IsInInterfaceSlice

func (s *Struct) IsInInterfaceSlice() bool

func (*Struct) IsInterface

func (s *Struct) IsInterface() bool

func (*Struct) SetIsInInterfaceSlice

func (s *Struct) SetIsInInterfaceSlice()

func (*Struct) SetVarname

func (s *Struct) SetVarname(a string)

func (*Struct) TypeName

func (s *Struct) TypeName() string

func (*Struct) ZeroLiteral

func (s *Struct) ZeroLiteral(v string) string

type StructField

type StructField struct {
	FieldTag   string // the string inside the `msg:""` tag
	FieldName  string // the name of the struct field
	FieldElem  Elem   // the field type
	OmitEmpty  bool   // if the tag `msg:",omitempty"` was found
	Deprecated bool   // if the tag `deprecated:"true"` was found
	Skip       bool   // if msg:"-" or field is type struct{}
	ShowZero   bool   // if msg:",showzero" tag was found.
	IsIface    bool   // the field type is an interface?

	// ZebraId defaults to -1, meaning not-tagged with a zebra id.
	// if ZebraId >= 0, then the tag `zebra:"N"` was found, with ZebraId == N.
	ZebraId int64
}

func (*StructField) IsInterface

func (s *StructField) IsInterface() bool

func (*StructField) SkipMe

func (s *StructField) SkipMe() bool

type TransformPass

type TransformPass func(Elem) Elem

TransformPass is a pass that transforms individual elements. (Note that if the returned is different from the argument, it should not point to the same objects.)

func IgnoreTypename

func IgnoreTypename(name string) TransformPass

IgnoreTypename is a pass that just ignores types of a given name.

Jump to

Keyboard shortcuts

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