msgpgen

package module
v0.0.0-...-de706b7 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2020 License: MIT Imports: 25 Imported by: 0

README

``msgpgen`` - Alternative code generator wrapper for ``msgp``
=============================================================

Note: This badly needed a lick of paint before Go Modules came onto the scene,
and should now be considered obsolete/unmaintained. Having said that, if you
depend on this and you run into trouble with it, please open an issue and I'll
see if I can help.

-----

``msgpgen`` combines `tinylib/msgp <https://github.com/tinylib/msgp>`_ with
`shabbyrobe/structer <https://github.com/shabbyrobe/structer>`_ to solve a few
issues with the code generating portion of ``tinylib/msgp``.

It supports:

- All the same arguments as the old generator

It differs:

- ``ignore`` and ``shim`` directives must be declared using the full package
  path.

It adds:

- Support for non-local identifiers, by simply generating the code for those
  identifiers in the relevant package.

- Automatic shimming of primitives

- Automatic handling of interface types

- Silencing spurious warnings

- Alternative methods of searching for types, including using a flat file
  containing a whitelist, or searching for all types that implement an
  interface.

It has the following issues (which should all be fixed at some point):

- Import recursion is not limited. ``msgpgen`` will blindly traverse any user
  package it finds in your gopath and will generate code into it.

- Ignored fields (with the tag `msg:"-"`) produce a warning in the output which
  is not currently quashed.

We may be able to support:

- #163 Embedded fields behaviour

It solves the following issues in the msgp tracker:

- #183 Generator output severity labels
- #158 Workaround for types that are defined in another package?
- #141 Directive ignore all
- #128 Best effort warnings re: external types
- #47 Keep track of imports (boy does it ever do that)


Using
-----

To generate msgpack for all types in and under ``mypkg`` that implement
interface ``mypkg.Msg``, then recursively generate all types in other packages
in your GOPATH that those types reference,
use the following::

    //go:generate msgpgen -iface mypkg.Msg -import mypkg/...

.. warning:: The recursion is not currenty limited by the -import flag, though
   it will be.

Documentation

Index

Constants

View Source
const (
	LogTypeSet = "typeset"

	// Log code indicating an error occurred in the types.Config.Error
	// callback, but execution continued.
	LogTypesConfigError = 1

	// Log code indicating an error was returned by types.Config.Check, but
	// execution continued.
	LogTypeCheck = 2
)

Variables

View Source
var ShimModes = map[ShimMode]bool{Cast: true, Convert: true}

Functions

func Generate

func Generate(tpset *structer.TypePackageSet, state *State, dctvCache *DirectivesCache, config Config) (err error)

func ParseTag

func ParseTag(tag string) (t structtag.Tag)

ParseTag parses the `msg:"..."` struct tag

Types

type AllowExtraDirective

type AllowExtraDirective struct {
	Types []string
}

func (AllowExtraDirective) Build

func (*AllowExtraDirective) Populate

func (i *AllowExtraDirective) Populate(args []string, kwargs map[string]string) error

type Cleanup

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

func (*Cleanup) Cleanup

func (c *Cleanup) Cleanup(err *error)

func (*Cleanup) Push

func (c *Cleanup) Push(path string)

type Config

type Config struct {
	Types               []structer.TypeName
	GenTests            bool
	GenIO               bool
	GenMarshal          bool
	GenVersion          bool
	Unexported          bool
	TempDirName         string
	FileTemplate        string
	TestTemplate        string
	VersionFileTemplate string
	KeepTemp            bool
	AllowExtra          bool
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig() Config

type Directive

type Directive interface {
	Build(tpset *structer.TypePackageSet, pkg string) (string, error)
	Populate(args []string, kwargs map[string]string) error
}

func ParseDirective

func ParseDirective(input string) (Directive, error)

type Directives

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

func NewDirectives

func NewDirectives(tpset *structer.TypePackageSet, pkg string) *Directives

type DirectivesCache

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

func NewDirectivesCache

func NewDirectivesCache(tpset *structer.TypePackageSet) *DirectivesCache

func (*DirectivesCache) Ensure

func (d *DirectivesCache) Ensure(pkg string) (*Directives, error)

func (*DirectivesCache) Ignored

func (d *DirectivesCache) Ignored(dctvs *Directives, fullName structer.TypeName) bool

func (*DirectivesCache) IgnoredPkg

func (d *DirectivesCache) IgnoredPkg(fullName structer.TypeName) (bool, error)

type IgnoreDirective

type IgnoreDirective struct {
	Types []string
}

func (IgnoreDirective) Build

func (i IgnoreDirective) Build(tpset *structer.TypePackageSet, pkg string) (string, error)

func (*IgnoreDirective) Populate

func (i *IgnoreDirective) Populate(args []string, kwargs map[string]string) error

type InterceptDirective

type InterceptDirective struct {
	Type  string
	Using string
}

func (InterceptDirective) Build

func (i InterceptDirective) Build(tpset *structer.TypePackageSet, pkg string) (string, error)

func (*InterceptDirective) Populate

func (i *InterceptDirective) Populate(args []string, kwargs map[string]string) error

type Log

type Log interface {
	Log(category string, code int, message string, args ...interface{})
}

type ShimDirective

type ShimDirective struct {
	Type     string
	As       string
	ToFunc   string
	FromFunc string
	Mode     ShimMode
}

func (ShimDirective) Build

func (i ShimDirective) Build(tpset *structer.TypePackageSet, pkg string) (string, error)

func (*ShimDirective) Populate

func (i *ShimDirective) Populate(args []string, kwargs map[string]string) error

type ShimMode

type ShimMode string
const (
	Cast    ShimMode = "cast"
	Convert ShimMode = "convert"
)

type State

type State struct {
	Types  StateTypes
	NextID int  `json:"-"`
	New    bool `json:"-"`
}

func LoadStateFromFile

func LoadStateFromFile(file string) (*State, error)

func (*State) EnsureType

func (s *State) EnsureType(t structer.TypeName) (int, error)

func (*State) Init

func (s *State) Init() error

func (*State) SaveToFile

func (s *State) SaveToFile(file string) (err error)

func (*State) SortedNames

func (s *State) SortedNames() []structer.TypeName

type StateTypes

type StateTypes map[structer.TypeName]int

func (StateTypes) MarshalJSON

func (s StateTypes) MarshalJSON() (b []byte, err error)

func (*StateTypes) UnmarshalJSON

func (s *StateTypes) UnmarshalJSON(b []byte) error

type TempFile

type TempFile struct {
	Name string
	Keep bool
	// contains filtered or unexported fields
}

func OpenTempFile

func OpenTempFile(dir, prefix string) (t *TempFile, err error)

func TouchTempFile

func TouchTempFile(dir, prefix string) (t *TempFile, err error)

func (*TempFile) Cleanup

func (t *TempFile) Cleanup(err *error)

func (*TempFile) Close

func (t *TempFile) Close() error

func (*TempFile) Copy

func (t *TempFile) Copy(dest string, perms os.FileMode) (err error)

func (*TempFile) Read

func (t *TempFile) Read(p []byte) (n int, err error)

func (*TempFile) Reopen

func (t *TempFile) Reopen(offset int64, whence int) (n int64, err error)

func (*TempFile) Seek

func (t *TempFile) Seek(offset int64, whence int) (int64, error)

func (*TempFile) Write

func (t *TempFile) Write(p []byte) (n int, err error)

type TupleDirective

type TupleDirective struct {
	Types []string
}

func (TupleDirective) Build

func (i TupleDirective) Build(tpset *structer.TypePackageSet, pkg string) (string, error)

func (*TupleDirective) Populate

func (i *TupleDirective) Populate(args []string, kwargs map[string]string) error

type TypeParents

type TypeParents []structer.TypeName

func (TypeParents) Clone

func (t TypeParents) Clone() TypeParents

func (TypeParents) Next

type TypeQueue

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

func NewTypeQueue

func NewTypeQueue(tpset *structer.TypePackageSet) *TypeQueue

func (*TypeQueue) Add

func (q *TypeQueue) Add(originPkg string, name string, obj types.Object, typ types.Type) *TypeQueueItem

func (*TypeQueue) AddObj

func (q *TypeQueue) AddObj(originPkg string, obj types.Object) *TypeQueueItem

func (*TypeQueue) AddType

func (q *TypeQueue) AddType(originPkg string, name string, typ types.Type) *TypeQueueItem

func (*TypeQueue) Dequeue

func (q *TypeQueue) Dequeue() *TypeQueueItem

type TypeQueueItem

type TypeQueueItem struct {
	OriginPkg string
	Name      string
	Obj       types.Object
	Type      types.Type
	Parents   TypeParents
}

func (*TypeQueueItem) Key

func (tqi *TypeQueueItem) Key() string

func (*TypeQueueItem) Parent

func (tqi *TypeQueueItem) Parent() *structer.TypeName

func (*TypeQueueItem) SetParents

func (tqi *TypeQueueItem) SetParents(parents []structer.TypeName) *TypeQueueItem

func (*TypeQueueItem) String

func (tqi *TypeQueueItem) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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