gen

package
Version: v0.0.0-...-85e4542 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2015 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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

func (a *Array) Complexity() int

func (*Array) Copy

func (a *Array) Copy() Elem

func (*Array) Printable

func (a *Array) Printable() bool

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

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

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

	// Returns whether or not the
	// type is safely printable
	Printable() bool
	// 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 Generator

type Generator interface {
	// Execute writes the method for the provided object.
	Execute(Elem) error
}

Generator is the interface through which code is generated.

var (
	NopGen Generator = nopgen{}
)

func New

func New(m Method, out io.Writer) Generator

New returns a new Generator that generates a particular method and writes its body to the provided io.Writer. The output may not be in canonical Go format.

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

func (m *Map) Complexity() int

func (*Map) Copy

func (m *Map) Copy() Elem

func (*Map) Printable

func (m *Map) Printable() bool

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

type Method

type Method uint8

Method is a method that the generator knows how to generate

const (
	Decode      Method = iota // msgp.Decodable
	Encode                    // msgp.Encodable
	Marshal                   // msgp.Marshaler
	Unmarshal                 // msgp.Unmarshaler
	Size                      // msgp.Sizer
	MarshalTest               // test Marshaler and Unmarshaler
	EncodeTest                // test Encodable and Decodable
)

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

func (s *Ptr) Needsinit() bool

func (*Ptr) Printable

func (s *Ptr) Printable() 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

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

func (s *Slice) Printable() bool

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

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

func (s *Struct) Complexity() int

func (*Struct) Copy

func (s *Struct) Copy() Elem

func (*Struct) Printable

func (s *Struct) Printable() bool

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

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
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL