gen

package
v3.7.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2017 License: MIT Imports: 13 Imported by: 0

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 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 {
	Index        string // index variable name
	SizeNamed    string // array size
	SizeResolved string // array size
	Els          Elem   // child
	// contains filtered or unexported fields
}

func (*Array) Alias

func (c *Array) Alias(typ string)

func (*Array) Complexity

func (a *Array) Complexity() int

func (*Array) Copy

func (a *Array) Copy() Elem

func (*Array) GetZtype

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

func (*Array) MethodPrefix

func (c *Array) MethodPrefix() string

func (*Array) SetHasMethodPrefix

func (c *Array) SetHasMethodPrefix(hmp HasMethodPrefix)

func (*Array) SetVarname

func (a *Array) SetVarname(s string)

func (*Array) TypeClue

func (a *Array) TypeClue() string

func (*Array) TypeName

func (a *Array) TypeName() string

func (*Array) Varname

func (c *Array) Varname() string

func (*Array) ZeroLiteral

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

type BaseElem

type BaseElem struct {
	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) *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 green.Ztype)

func (*BaseElem) MethodPrefix

func (c *BaseElem) MethodPrefix() string

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) SetHasMethodPrefix

func (c *BaseElem) SetHasMethodPrefix(hmp HasMethodPrefix)

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) TypeClue

func (s *BaseElem) TypeClue() string

func (*BaseElem) TypeName

func (s *BaseElem) TypeName() string

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

func (*BaseElem) Varname

func (c *BaseElem) Varname() string

func (*BaseElem) ZeroLiteral

func (s *BaseElem) ZeroLiteral(v string) 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() green.Ztype

	// for template instantiation with custom method prefix
	MethodPrefix() string
	SetHasMethodPrefix(hmp HasMethodPrefix)

	// The clue is a 3-character string added
	// to on-the-wire field name
	// to salvage the uint -> int fiasco of classic msgpack
	// implementations.
	//
	// The clue and the version together prevent gross
	// decoding type and version mismatches.
	// Avoid Knight Capital like meltdowns and never
	// change a field without bumping the version number.
	TypeClue() string
	// 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 {
	Keyidx string // key variable name
	Validx string // value variable name
	Value  Elem   // value element

	KeyTyp     string
	KeyDeclTyp string
	// contains filtered or unexported fields
}

Map is a map[string]Elem

func (*Map) Alias

func (c *Map) Alias(typ string)

func (*Map) Complexity

func (m *Map) Complexity() int

func (*Map) Copy

func (m *Map) Copy() Elem

func (*Map) GetZtype

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

func (*Map) MethodPrefix

func (c *Map) MethodPrefix() string

func (*Map) SetHasMethodPrefix

func (c *Map) SetHasMethodPrefix(hmp HasMethodPrefix)

func (*Map) SetVarname

func (m *Map) SetVarname(s string)

func (*Map) TypeClue

func (m *Map) TypeClue() string

func (*Map) TypeName

func (m *Map) TypeName() string

func (*Map) Varname

func (c *Map) Varname() 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.GreenConfig) *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 {
	Value Elem
	// contains filtered or unexported fields
}

func (*Ptr) Alias

func (c *Ptr) Alias(typ string)

func (*Ptr) Complexity

func (s *Ptr) Complexity() int

func (*Ptr) Copy

func (s *Ptr) Copy() Elem

func (*Ptr) GetZtype

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

func (*Ptr) MethodPrefix

func (c *Ptr) MethodPrefix() string

func (*Ptr) Needsinit

func (s *Ptr) Needsinit() bool

func (*Ptr) SetHasMethodPrefix

func (c *Ptr) SetHasMethodPrefix(hmp HasMethodPrefix)

func (*Ptr) SetVarname

func (s *Ptr) SetVarname(a string)

func (*Ptr) TypeClue

func (s *Ptr) TypeClue() string

func (*Ptr) TypeName

func (s *Ptr) TypeName() string

func (*Ptr) Varname

func (c *Ptr) Varname() string

func (*Ptr) ZeroLiteral

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

type Slice

type Slice struct {
	Index string
	Els   Elem // The type of each element
	// contains filtered or unexported fields
}

func (*Slice) Alias

func (c *Slice) Alias(typ string)

func (*Slice) Complexity

func (s *Slice) Complexity() int

func (*Slice) Copy

func (s *Slice) Copy() Elem

func (*Slice) GetZtype

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

func (*Slice) MethodPrefix

func (c *Slice) MethodPrefix() string

func (*Slice) SetHasMethodPrefix

func (c *Slice) SetHasMethodPrefix(hmp HasMethodPrefix)

func (*Slice) SetVarname

func (s *Slice) SetVarname(a string)

func (*Slice) TypeClue

func (a *Slice) TypeClue() string

func (*Slice) TypeName

func (s *Slice) TypeName() string

func (*Slice) Varname

func (c *Slice) Varname() string

func (*Slice) ZeroLiteral

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

type Struct

type Struct struct {
	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) Alias

func (c *Struct) Alias(typ string)

func (*Struct) Complexity

func (s *Struct) Complexity() int

func (*Struct) Copy

func (s *Struct) Copy() Elem

func (*Struct) GetZtype

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

func (*Struct) MethodPrefix

func (c *Struct) MethodPrefix() string

func (*Struct) SetHasMethodPrefix

func (c *Struct) SetHasMethodPrefix(hmp HasMethodPrefix)

func (*Struct) SetVarname

func (s *Struct) SetVarname(a string)

func (*Struct) TypeClue

func (s *Struct) TypeClue() string

func (*Struct) TypeName

func (s *Struct) TypeName() string

func (*Struct) Varname

func (c *Struct) Varname() 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.

	// 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

	FieldTagZidClue string
}

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