gen

package
v1.1.60 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDangling

func IsDangling(e Elem) bool

func SetSortInterface

func SetSortInterface(sorttype string, sortintf string)

Types

type Array

type Array struct {
	Index    string // index variable name
	Size     string // array size
	SizeHint string // const object referred to by Size
	Els      Elem   // child
	// contains filtered or unexported fields
}

func (*Array) AddCallback added in v1.1.49

func (c *Array) AddCallback(cb Callback)

func (*Array) Alias

func (c *Array) Alias(typ string)

func (*Array) AllocBound added in v1.1.17

func (c *Array) AllocBound() string

func (*Array) Comparable added in v1.1.12

func (a *Array) Comparable() bool

Comparable returns whether this elem's type is comparable.

func (*Array) Complexity

func (a *Array) Complexity() int

func (*Array) Copy

func (a *Array) Copy() Elem

func (*Array) GetCallbacks added in v1.1.49

func (c *Array) GetCallbacks() []Callback

func (*Array) IfZeroExpr

func (a *Array) IfZeroExpr() string

IfZeroExpr returns the expression to compare to zero/empty.

func (*Array) MaxTotalBytes added in v1.1.55

func (c *Array) MaxTotalBytes() string

func (*Array) SetAllocBound added in v1.1.17

func (c *Array) SetAllocBound(s string)

func (*Array) SetMaxTotalBytes added in v1.1.55

func (c *Array) SetMaxTotalBytes(s string)

func (*Array) SetVarname

func (a *Array) SetVarname(s string)

func (*Array) SortInterface

func (c *Array) SortInterface() string

func (*Array) TypeName

func (a *Array) TypeName() string

func (*Array) Varname

func (c *Array) Varname() string

func (*Array) ZeroExpr

func (a *Array) ZeroExpr() string

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

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
	IdentName    string    // name, for Value == IDENT
	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(importPrefix string, id string) *BaseElem

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

func (*BaseElem) AddCallback added in v1.1.49

func (c *BaseElem) AddCallback(cb Callback)

func (*BaseElem) Alias

func (s *BaseElem) Alias(typ string)

func (*BaseElem) AllocBound added in v1.1.17

func (c *BaseElem) AllocBound() 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) Comparable added in v1.1.12

func (s *BaseElem) Comparable() bool

Comparable returns whether this elem's type is comparable.

func (*BaseElem) Complexity

func (s *BaseElem) Complexity() int

func (*BaseElem) Copy

func (s *BaseElem) Copy() Elem

func (*BaseElem) Dangling

func (s *BaseElem) Dangling() bool

func (*BaseElem) FromBase

func (s *BaseElem) FromBase() string

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

func (*BaseElem) GetCallbacks added in v1.1.49

func (c *BaseElem) GetCallbacks() []Callback

func (*BaseElem) IfZeroExpr

func (s *BaseElem) IfZeroExpr() string

IfZeroExpr returns the expression to compare to zero/empty.

func (*BaseElem) MaxTotalBytes added in v1.1.55

func (c *BaseElem) MaxTotalBytes() string

func (*BaseElem) Needsref

func (s *BaseElem) Needsref(b 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) SetAllocBound added in v1.1.17

func (c *BaseElem) SetAllocBound(s string)

func (*BaseElem) SetMaxTotalBytes added in v1.1.55

func (c *BaseElem) SetMaxTotalBytes(s string)

func (*BaseElem) SetVarname

func (s *BaseElem) SetVarname(a string)

func (*BaseElem) SortInterface

func (s *BaseElem) SortInterface() string

SortInterface returns a sort.Interface for sorting a slice of this type.

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

func (s *BaseElem) ZeroExpr() string

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

type Callback added in v1.1.49

type Callback struct {
	Fname        string
	CallbackType CallbackType
}

Callback represents a function that can is expected to be printed into the generated code. for example, at the end of a successful unmarshalling.

func (Callback) GetName added in v1.1.49

func (c Callback) GetName() string

func (Callback) IsUnmarshallCallback added in v1.1.49

func (c Callback) IsUnmarshallCallback() bool

type CallbackType added in v1.1.49

type CallbackType uint64
const UnmarshalCallBack CallbackType = 1

UnmarshalCallBack represents a type callback that should run over the generated code.

type Context

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

func (*Context) ArgsStr

func (c *Context) ArgsStr() string

func (*Context) Pop

func (c *Context) Pop()

func (*Context) PushString

func (c *Context) PushString(s string)

func (*Context) PushVar

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

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

	// SortInterface returns the sort.Interface for sorting a
	// slice of this type.
	SortInterface() string

	// Comparable returns whether the type is comparable, along the lines
	// of the Go spec (https://golang.org/ref/spec#Comparison_operators),
	// used to determine whether we can compare to a zero value to determine
	// zeroness.
	Comparable() bool

	// SetAllocBound specifies the maximum number of elements to allocate
	// when decoding this type.  Meaningful for slices and maps.
	// Blank means unspecified bound.  "-" means no bound.
	SetAllocBound(bound string)

	// AllocBound returns the maximum number of elements to allocate
	// when decoding this type.  Meaningful for slices and maps.
	AllocBound() string

	// SetMaxTotalBytes specifies the maximum number of bytes to allocate when
	// decoding this type.
	// Blank means unspecified bound.  "-" means no bound.
	SetMaxTotalBytes(bound string)

	// MaxTotalBytes specifies the maximum number of bytes to allocate when
	// decoding this type. Meaningful for slices of strings or byteslices.
	MaxTotalBytes() string

	// AddCallback adds to the elem a Callback it should call at the end of marshaling
	AddCallback(Callback)

	// GetCallbacks fetches all callbacks this Elem stored.
	GetCallbacks() []Callback
	// 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
	Key    Elem   // type of map key
	Validx string // value variable name
	Value  Elem   // value element
	// contains filtered or unexported fields
}

Map is a map[string]Elem

func (*Map) AddCallback added in v1.1.49

func (c *Map) AddCallback(cb Callback)

func (*Map) Alias

func (c *Map) Alias(typ string)

func (*Map) AllocBound added in v1.1.17

func (c *Map) AllocBound() string

func (*Map) Comparable added in v1.1.12

func (m *Map) Comparable() bool

Comparable returns whether this elem's type is comparable.

func (*Map) Complexity

func (m *Map) Complexity() int

func (*Map) Copy

func (m *Map) Copy() Elem

func (*Map) GetCallbacks added in v1.1.49

func (c *Map) GetCallbacks() []Callback

func (*Map) IfZeroExpr

func (m *Map) IfZeroExpr() string

IfZeroExpr returns the expression to compare to zero/empty.

func (*Map) MaxTotalBytes added in v1.1.55

func (c *Map) MaxTotalBytes() string

func (*Map) SetAllocBound added in v1.1.17

func (c *Map) SetAllocBound(s string)

func (*Map) SetMaxTotalBytes added in v1.1.55

func (c *Map) SetMaxTotalBytes(s string)

func (*Map) SetVarname

func (m *Map) SetVarname(s string)

func (*Map) SortInterface

func (c *Map) SortInterface() string

func (*Map) TypeName

func (m *Map) TypeName() string

func (*Map) Varname

func (c *Map) Varname() string

func (*Map) ZeroExpr

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 (
	Marshal   Method = 1 << iota // msgp.Marshaler
	Unmarshal                    // msgp.Unmarshaler
	Size                         // msgp.Sizer
	IsZero                       // implement MsgIsZero()
	Test                         // generate tests
	MaxSize                      // msgp.MaxSize

)

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
	Uintptr
	Byte
	Int
	Int8
	Int16
	Int32
	Int64
	Bool
	Intf     // interface{}
	Time     // time.Time
	Ext      // extension
	Error    // error
	Duration // time.Duration

	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, topics *Topics, 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) ([]string, error)

Print prints an Elem.

type Ptr

type Ptr struct {
	Value Elem
	// contains filtered or unexported fields
}

func (*Ptr) AddCallback added in v1.1.49

func (c *Ptr) AddCallback(cb Callback)

func (*Ptr) Alias

func (c *Ptr) Alias(typ string)

func (*Ptr) AllocBound added in v1.1.17

func (c *Ptr) AllocBound() string

func (*Ptr) Comparable added in v1.1.12

func (s *Ptr) Comparable() bool

Comparable returns whether this elem's type is comparable.

func (*Ptr) Complexity

func (s *Ptr) Complexity() int

func (*Ptr) Copy

func (s *Ptr) Copy() Elem

func (*Ptr) GetCallbacks added in v1.1.49

func (c *Ptr) GetCallbacks() []Callback

func (*Ptr) IfZeroExpr

func (s *Ptr) IfZeroExpr() string

IfZeroExpr returns the expression to compare to zero/empty.

func (*Ptr) MaxTotalBytes added in v1.1.55

func (c *Ptr) MaxTotalBytes() string

func (*Ptr) Needsinit

func (s *Ptr) Needsinit() bool

func (*Ptr) SetAllocBound added in v1.1.17

func (c *Ptr) SetAllocBound(s string)

func (*Ptr) SetMaxTotalBytes added in v1.1.55

func (c *Ptr) SetMaxTotalBytes(s string)

func (*Ptr) SetVarname

func (s *Ptr) SetVarname(a string)

func (*Ptr) SortInterface

func (c *Ptr) SortInterface() string

func (*Ptr) TypeName

func (s *Ptr) TypeName() string

func (*Ptr) Varname

func (c *Ptr) Varname() string

func (*Ptr) ZeroExpr

func (s *Ptr) ZeroExpr() string

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

type ShimMode

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) AddCallback added in v1.1.49

func (c *Slice) AddCallback(cb Callback)

func (*Slice) Alias

func (c *Slice) Alias(typ string)

func (*Slice) AllocBound added in v1.1.17

func (c *Slice) AllocBound() string

func (*Slice) Comparable added in v1.1.12

func (s *Slice) Comparable() bool

Comparable returns whether this elem's type is comparable.

func (*Slice) Complexity

func (s *Slice) Complexity() int

func (*Slice) Copy

func (s *Slice) Copy() Elem

func (*Slice) GetCallbacks added in v1.1.49

func (c *Slice) GetCallbacks() []Callback

func (*Slice) IfZeroExpr

func (s *Slice) IfZeroExpr() string

IfZeroExpr returns the expression to compare to zero/empty.

func (*Slice) MaxTotalBytes added in v1.1.55

func (c *Slice) MaxTotalBytes() string

func (*Slice) SetAllocBound added in v1.1.17

func (c *Slice) SetAllocBound(s string)

func (*Slice) SetMaxTotalBytes added in v1.1.55

func (c *Slice) SetMaxTotalBytes(s string)

func (*Slice) SetVarname

func (s *Slice) SetVarname(a string)

func (*Slice) SortInterface

func (c *Slice) SortInterface() string

func (*Slice) TypeName

func (s *Slice) TypeName() string

func (*Slice) Varname

func (c *Slice) Varname() string

func (*Slice) ZeroExpr

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) AddCallback added in v1.1.49

func (c *Struct) AddCallback(cb Callback)

func (*Struct) Alias

func (c *Struct) Alias(typ string)

func (*Struct) AllocBound added in v1.1.17

func (c *Struct) AllocBound() string

func (*Struct) AnyHasTagPart

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

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

func (*Struct) Comparable added in v1.1.12

func (s *Struct) Comparable() bool

Comparable returns whether this elem's type is comparable.

func (*Struct) Complexity

func (s *Struct) Complexity() int

func (*Struct) Copy

func (s *Struct) Copy() Elem

func (*Struct) GetCallbacks added in v1.1.49

func (c *Struct) GetCallbacks() []Callback

func (*Struct) HasAnyStructTag added in v1.1.34

func (s *Struct) HasAnyStructTag() bool

HasAnyStructTag returns true if any of the fields in the struct have a codec: tag. This is used to determine which structs we can skip because they are not intended for encoding/decoding.

func (*Struct) HasUnderscoreStructTag added in v1.1.18

func (s *Struct) HasUnderscoreStructTag() bool

HasUnderscoreStructTag returns true if there is a field named _struct with a codec: tag. This is used to ensure developers don't forget to annotate their structs with omitempty (unless explicitly opted out).

func (*Struct) IfZeroExpr

func (s *Struct) IfZeroExpr() string

IfZeroExpr returns the expression to compare to zero/empty.

func (*Struct) MaxTotalBytes added in v1.1.55

func (c *Struct) MaxTotalBytes() string

func (*Struct) SetAllocBound added in v1.1.17

func (c *Struct) SetAllocBound(s string)

func (*Struct) SetMaxTotalBytes added in v1.1.55

func (c *Struct) SetMaxTotalBytes(s string)

func (*Struct) SetVarname

func (s *Struct) SetVarname(a string)

func (*Struct) SortInterface

func (c *Struct) SortInterface() string

func (*Struct) TypeName

func (s *Struct) TypeName() string

func (*Struct) UnderscoreStructHasTagPart

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

UnderscoreStructHasTagPart returns true if HasTagPart(p) is true for the _struct field.

func (*Struct) Varname

func (c *Struct) Varname() string

func (*Struct) ZeroExpr

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 `codec:""` tag up to the first comma
	FieldTagParts []string // the string inside the `codec:""` tag split by commas
	RawTag        string   // the full struct tag
	HasCodecTag   bool     // has a `codec:` tag
	FieldName     string   // the name of the struct field
	FieldElem     Elem     // the field type
	FieldPath     []string // set of embedded struct names for accessing FieldName
}

func (*StructField) HasTagPart

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

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

type Topics added in v1.1.41

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

func (*Topics) Add added in v1.1.41

func (t *Topics) Add(key, value string)

func (*Topics) Bytes added in v1.1.41

func (t *Topics) Bytes() []byte

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