iprotogen

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IProtoDirective - generate [iproto.MarshalerUnmarshaler] implementation for types marked by this special comment.
	IProtoDirective = "//adv:iproto:"

	// IProtoTag - struct tag for overriding the field's representation
	IProtoTag = "iproto"
)

Variables

This section is empty.

Functions

func GeneratedFileName

func GeneratedFileName(fname string) string

func WithDisableFormatting added in v0.0.11

func WithDisableFormatting(opt *fileEmitOptions)

func WithIgnoreGenerated added in v0.0.11

func WithIgnoreGenerated(opt *pkgParserOptions)

func WithParseTests added in v0.0.11

func WithParseTests(opt *pkgParserOptions)

Types

type Array

type Array struct {
	Len      *ast.BasicLit
	ElemType Type
}

func (Array) EmitMarshaler

func (arr Array) EmitMarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

func (Array) EmitUnmarshaler

func (arr Array) EmitUnmarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

type Bool

type Bool struct {
	TypeExpr ast.Expr
	True     *ast.BasicLit
	False    *ast.BasicLit
}

Bool represents a value with an underlying type bool. TypeExpr is the Go type expression (e.g. identBool for bool, or a defined type like MyBool). When decoding, False byte is decoded as false, and anything else as true (not only the True byte).

func (Bool) EmitMarshaler

func (b Bool) EmitMarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

func (Bool) EmitUnmarshaler

func (b Bool) EmitUnmarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

type ByteArray

type ByteArray struct {
	Len      *ast.BasicLit
	TypeExpr ast.Expr
}

func (ByteArray) EmitMarshaler

func (ByteArray) EmitMarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

func (ByteArray) EmitUnmarshaler

func (ba ByteArray) EmitUnmarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

type Custom

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

func (Custom) EmitMarshaler

func (c Custom) EmitMarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

func (Custom) EmitUnmarshaler

func (c Custom) EmitUnmarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

type Decl

type Decl struct {
	TypeIdent *ast.Ident
	Type      Type
}

func (Decl) EmitMarshalerDecl

func (d Decl) EmitMarshalerDecl(decls []ast.Decl) []ast.Decl

func (Decl) EmitUnmarshalerDecl

func (d Decl) EmitUnmarshalerDecl(decls []ast.Decl) []ast.Decl

type Dumb

type Dumb struct{}

func (Dumb) EmitMarshaler

func (Dumb) EmitMarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

func (Dumb) EmitUnmarshaler

func (d Dumb) EmitUnmarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

type File

type File struct {
	Directives string // before the package token
	PkgName    string

	Decls []Decl
	// contains filtered or unexported fields
}

func (*File) AddType

func (f *File) AddType(ident *ast.Ident, typ Type)

func (File) Emit

func (f File) Emit(optFuncs ...FileEmitOptionsFunc) ([]byte, error)

type FileEmitOptionsFunc

type FileEmitOptionsFunc func(*fileEmitOptions)

type FilesByPath

type FilesByPath map[string]*File

func (FilesByPath) Get

func (fbp FilesByPath) Get(filePath string, pkg *typeparser.Package, directives string) *File

type Float

type Float struct {
	TypeExpr ast.Expr
	Size     int
}

func (Float) EmitMarshaler

func (f Float) EmitMarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

func (Float) EmitUnmarshaler

func (f Float) EmitUnmarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

type Integer

type Integer struct {
	TypeExpr ast.Expr
	Size     int
	Min      int64
	Max      uint64
}

func (Integer) EmitMarshaler

func (i Integer) EmitMarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

func (Integer) EmitUnmarshaler

func (i Integer) EmitUnmarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

type Map

type Map struct {
	LenType   Integer  // LenType.TypeExpr should always be int
	TypeExpr  ast.Expr // type of the map itself
	KeyType   Type
	ValueType Type
}

func (Map) EmitMarshaler

func (m Map) EmitMarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

func (Map) EmitUnmarshaler

func (m Map) EmitUnmarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

type OptionalNull added in v0.0.15

type OptionalNull struct {
	Type       Type       // inner type for the value field
	ValueField *ast.Ident // field name containing the value (e.g. "String", "Int64", "V")
}

OptionalNull wraps a sql.Null* type with a presence byte. Marshal: if .Valid is false, writes 0; otherwise writes 1 followed by the encoded value field. Unmarshal: reads presence byte; if 0, sets Valid=false; if 1, sets Valid=true and reads value.

func (OptionalNull) EmitMarshaler added in v0.0.15

func (o OptionalNull) EmitMarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

func (OptionalNull) EmitUnmarshaler added in v0.0.15

func (o OptionalNull) EmitUnmarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

type OptionalPointer added in v0.0.15

type OptionalPointer struct {
	Type     Type     // inner type (what the pointer points to)
	TypeExpr ast.Expr // the type being pointed to
}

OptionalPointer wraps a pointer type with a presence byte. Marshal: if pointer is nil, writes 0; otherwise writes 1 followed by the value. Unmarshal: reads presence byte; if 0, sets nil; if 1, allocates and reads value.

func (OptionalPointer) EmitMarshaler added in v0.0.15

func (o OptionalPointer) EmitMarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

func (OptionalPointer) EmitUnmarshaler added in v0.0.15

func (o OptionalPointer) EmitUnmarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

type Parser

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

func NewParser

func NewParser(optFuncs ...ParserOptionsFunc) (*Parser, error)

func (*Parser) ParsePackage

func (p *Parser) ParsePackage(pattern string) (FilesByPath, error)

ParsePackage extracts the iproto type descriptions of a package. The pattern is a directory (absolute or starting with "."), or an import path resolved against the module containing the working directory; a "/..." suffix descends into subpackages. The package only has to parse: function bodies are ignored, and declarations without an iproto directive may be arbitrarily broken.

type ParserOptionsFunc

type ParserOptionsFunc func(*pkgParserOptions)

func WithBuildFlag added in v0.0.11

func WithBuildFlag(flag string) ParserOptionsFunc

func WithModuleDir added in v0.0.11

func WithModuleDir(dir string) ParserOptionsFunc

func WithOnlyFile added in v0.0.11

func WithOnlyFile(fname string) ParserOptionsFunc

type Pointer

type Pointer struct {
	Type     Type
	TypeExpr ast.Expr // the type a pointer is pointing to
}

func (Pointer) EmitMarshaler

func (p Pointer) EmitMarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

func (Pointer) EmitUnmarshaler

func (p Pointer) EmitUnmarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

type Slice

type Slice struct {
	LenType  Integer  // LenType.TypeExpr should always be int
	TypeExpr ast.Expr // type of the slice itself, not an element type
	ElemType Type
}

func (Slice) EmitMarshaler

func (sl Slice) EmitMarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

func (Slice) EmitUnmarshaler

func (sl Slice) EmitUnmarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

type StringOrBytes

type StringOrBytes struct {
	LenType  Integer
	TypeExpr ast.Expr
	IsSlice  bool
}

func (StringOrBytes) EmitMarshaler

func (s StringOrBytes) EmitMarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

func (StringOrBytes) EmitUnmarshaler

func (s StringOrBytes) EmitUnmarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

type Struct

type Struct struct {
	Fields []StructField
}

func (Struct) EmitMarshaler

func (s Struct) EmitMarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

func (Struct) EmitUnmarshaler

func (s Struct) EmitUnmarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

type StructField

type StructField struct {
	Ident *ast.Ident
	Type  Type
}

type StructLiteral

type StructLiteral struct {
	Fields   []StructField
	TypeExpr ast.Expr
}

StructLiteral is used for map keys and values

func (StructLiteral) EmitMarshaler

func (s StructLiteral) EmitMarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

func (StructLiteral) EmitUnmarshaler

func (s StructLiteral) EmitUnmarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

type TimeUnixNanoI64 added in v0.0.14

type TimeUnixNanoI64 struct{}

TimeUnixNanoI64 serializes time.Time as nanoseconds since the Unix epoch in int64. Range: 1677-09-21T00:12:43Z to 2262-04-11T23:47:16Z.

func (TimeUnixNanoI64) EmitMarshaler added in v0.0.14

func (TimeUnixNanoI64) EmitMarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

func (TimeUnixNanoI64) EmitUnmarshaler added in v0.0.14

func (TimeUnixNanoI64) EmitUnmarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

type TimeUnixU32 added in v0.0.14

type TimeUnixU32 struct{}

TimeUnixU32 serializes time.Time as seconds since the Unix epoch in uint32. Range: 1970-01-01T00:00:00Z to 2106-02-07T06:28:15Z.

func (TimeUnixU32) EmitMarshaler added in v0.0.14

func (TimeUnixU32) EmitMarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

func (TimeUnixU32) EmitUnmarshaler added in v0.0.14

func (TimeUnixU32) EmitUnmarshaler(x ast.Expr, block []ast.Stmt) []ast.Stmt

type Type

type Type interface {
	EmitMarshaler(ast.Expr, []ast.Stmt) []ast.Stmt
	EmitUnmarshaler(ast.Expr, []ast.Stmt) []ast.Stmt
}

Jump to

Keyboard shortcuts

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