gen

package
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: MIT Imports: 7 Imported by: 59

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPrintable

func IsPrintable(e Elem) bool

Types

type Array

type Array struct {
	Index string // index variable name
	Size  string // array size
	Els   Elem   // child
	// contains filtered or unexported fields
}

func (*Array) Alias

func (c *Array) Alias(typ string)

func (*Array) AllowNil added in v1.1.7

func (c *Array) AllowNil() bool

func (*Array) Complexity

func (a *Array) Complexity() int

func (*Array) Copy

func (a *Array) Copy() Elem

func (*Array) IfZeroExpr added in v1.1.1

func (a *Array) IfZeroExpr() string

IfZeroExpr unsupported

func (*Array) SetVarname

func (a *Array) SetVarname(s string)

func (*Array) TypeName

func (a *Array) TypeName() string

func (*Array) Varname

func (c *Array) Varname() string

func (*Array) ZeroExpr added in v1.1.1

func (a *Array) ZeroExpr() string

ZeroExpr returns the zero/empty expression or empty string if not supported. Unsupported for this case.

type BaseElem

type BaseElem struct {
	ShimMode     ShimMode  // Method used to shim
	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) AllowNil added in v1.1.7

func (s *BaseElem) AllowNil() bool

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) IfZeroExpr added in v1.1.1

func (s *BaseElem) IfZeroExpr() string

IfZeroExpr returns the expression to compare to zero/empty.

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

func (c *BaseElem) Varname() string

func (*BaseElem) ZeroExpr added in v1.1.1

func (s *BaseElem) ZeroExpr() string

ZeroExpr returns the zero/empty expression or empty string if not supported.

type Context added in v1.1.0

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

func (*Context) ArgsStr added in v1.1.0

func (c *Context) ArgsStr() string

func (*Context) Pop added in v1.1.0

func (c *Context) Pop()

func (*Context) PushString added in v1.1.0

func (c *Context) PushString(s string)

func (*Context) PushVar added in v1.1.0

func (c *Context) PushVar(s 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

	// ZeroExpr returns the expression for the correct zero/empty
	// value.  Can be used for assignment.
	// Returns "" if zero/empty not supported for this Elem.
	ZeroExpr() string

	// AllowNil will return true for types that can be nil but doesn't automatically check.
	// This is true for slices and maps.
	AllowNil() bool

	// IfZeroExpr returns the expression to compare to zero/empty
	// for this type.  It is meant to be used in an if statement
	// and may include the simple statement form followed by
	// semicolon and then the expression.
	// Returns "" if zero/empty not supported for this Elem.
	IfZeroExpr() 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 Map

type Map struct {
	Keyidx string // key variable name
	Validx string // value variable name
	Value  Elem   // value element
	// contains filtered or unexported fields
}

Map is a map[string]Elem

func (*Map) Alias

func (c *Map) Alias(typ string)

func (*Map) AllowNil added in v1.1.7

func (m *Map) AllowNil() bool

AllowNil is true for maps.

func (*Map) Complexity

func (m *Map) Complexity() int

func (*Map) Copy

func (m *Map) Copy() Elem

func (*Map) IfZeroExpr added in v1.1.1

func (m *Map) IfZeroExpr() string

IfZeroExpr returns the expression to compare to zero/empty.

func (*Map) SetVarname

func (m *Map) SetVarname(s string)

func (*Map) TypeName

func (m *Map) TypeName() string

func (*Map) Varname

func (c *Map) Varname() string

func (*Map) ZeroExpr added in v1.1.1

func (m *Map) ZeroExpr() string

ZeroExpr returns the zero/empty expression or empty string if not supported. Always "nil" for this case.

type Method

type Method uint8

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

)

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
	Duration // time.Duration
	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) *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) AllowNil added in v1.1.7

func (c *Ptr) AllowNil() bool

func (*Ptr) Complexity

func (s *Ptr) Complexity() int

func (*Ptr) Copy

func (s *Ptr) Copy() Elem

func (*Ptr) IfZeroExpr added in v1.1.1

func (s *Ptr) IfZeroExpr() string

IfZeroExpr returns the expression to compare to zero/empty.

func (*Ptr) Needsinit

func (s *Ptr) Needsinit() bool

func (*Ptr) SetVarname

func (s *Ptr) SetVarname(a string)

func (*Ptr) TypeName

func (s *Ptr) TypeName() string

func (*Ptr) Varname

func (c *Ptr) Varname() string

func (*Ptr) ZeroExpr added in v1.1.1

func (s *Ptr) ZeroExpr() string

ZeroExpr returns the zero/empty expression or empty string if not supported. Always "nil" for this case.

type ShimMode added in v1.1.0

type ShimMode int
const (
	Cast ShimMode = iota
	Convert
)

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) AllowNil added in v1.1.7

func (s *Slice) AllowNil() bool

AllowNil is true for slices.

func (*Slice) Complexity

func (s *Slice) Complexity() int

func (*Slice) Copy

func (s *Slice) Copy() Elem

func (*Slice) IfZeroExpr added in v1.1.1

func (s *Slice) IfZeroExpr() string

IfZeroExpr returns the expression to compare to zero/empty.

func (*Slice) SetVarname

func (s *Slice) SetVarname(a string)

func (*Slice) TypeName

func (s *Slice) TypeName() string

func (*Slice) Varname

func (c *Slice) Varname() string

func (*Slice) ZeroExpr added in v1.1.1

func (s *Slice) ZeroExpr() string

ZeroExpr returns the zero/empty expression or empty string if not supported. Always "nil" for this case.

type Struct

type Struct struct {
	Fields  []StructField // field list
	AsTuple bool          // write as an array instead of a map
	// contains filtered or unexported fields
}

func (*Struct) Alias

func (c *Struct) Alias(typ string)

func (*Struct) AllowNil added in v1.1.7

func (c *Struct) AllowNil() bool

func (*Struct) AnyHasTagPart added in v1.1.1

func (s *Struct) AnyHasTagPart(pname string) bool

AnyHasTagPart returns true if HasTagPart(p) is true for any field.

func (*Struct) Complexity

func (s *Struct) Complexity() int

func (*Struct) Copy

func (s *Struct) Copy() Elem

func (*Struct) IfZeroExpr added in v1.1.1

func (s *Struct) IfZeroExpr() string

IfZeroExpr returns the expression to compare to zero/empty.

func (*Struct) SetVarname

func (s *Struct) SetVarname(a string)

func (*Struct) TypeName

func (s *Struct) TypeName() string

func (*Struct) Varname

func (c *Struct) Varname() string

func (*Struct) ZeroExpr added in v1.1.1

func (s *Struct) ZeroExpr() string

ZeroExpr returns the zero/empty expression or empty string if not supported.

type StructField

type StructField struct {
	FieldTag      string   // the string inside the `msg:""` tag up to the first comma
	FieldTagParts []string // the string inside the `msg:""` tag split by commas
	RawTag        string   // the full struct tag
	FieldName     string   // the name of the struct field
	FieldElem     Elem     // the field type
}

func (*StructField) HasTagPart added in v1.1.1

func (sf *StructField) HasTagPart(pname string) bool

HasTagPart returns true if the specified tag part (option) is present.

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