bstruct

package module
v0.0.0-...-86d4d6d Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: MIT Imports: 9 Imported by: 0

README

bstruct

zero-copy, pre-generated binary encoder/decoder in golang with customization.

performance

type Struct1 struct {
	A	bool
	B	[]bool
	C	Struct2
	D	string
	G	[]string
	E	Slice1
	F	bool
}
type Struct2 struct {
	A bool
}
type Slice1 []struct {
	E string
}
BenchmarkEncode-8      	17996954	        67.08 ns/op	      48 B/op	       2 allocs/op
BenchmarkMarshal-8     	 3224440	       372.8 ns/op	      96 B/op	       1 allocs/op
BenchmarkDecode-8      	22132478	        53.78 ns/op	      48 B/op	       1 allocs/op
BenchmarkUnmarshal-8   	  791223	      1493 ns/op	     272 B/op	       7 allocs/op

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

func NewBuilder

func NewBuilder() *Builder

func (*Builder) Getter

func (e *Builder) Getter(f bool) *Builder

func (*Builder) Print

func (e *Builder) Print(buf io.Writer, pak string) error

func (*Builder) Process

func (e *Builder) Process()

func (*Builder) SetLineWrap

func (e *Builder) SetLineWrap(wrap int) *Builder

func (*Builder) Setter

func (e *Builder) Setter(f bool) *Builder

type Coder

type Coder func(rdwt ast.Expr, ptr ast.Expr, s *Field) []ast.Stmt

type Field

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

func New

func New(typ FieldType) *Field

func NewCustom

func NewCustom(typ ast.Expr, enc, dec Coder) *Field

func NewSlice

func NewSlice(t *Field) *Field

func NewString

func NewString() *Field

func (*Field) Add

func (b *Field) Add(name, comment string, optional bool, field *Field) *Field

func (*Field) Comment

func (b *Field) Comment(comment string) *Field

func (*Field) Reg

func (s *Field) Reg(e *Builder, name string) *Field

func (*Field) Virtual

func (s *Field) Virtual() *Field

type FieldType

type FieldType uint
const (
	FieldInvalid FieldType = iota
	FieldBool
	FieldInt8
	FieldInt16
	FieldInt32
	FieldInt64
	FieldUint8
	FieldUint16
	FieldUint32
	FieldUint64
	FieldFloat32
	FieldFloat64
	FieldString
	FieldSlice
	FieldStruct
	FieldCustom
)

func (FieldType) IsPrimitive

func (ft FieldType) IsPrimitive() bool

func (FieldType) IsType

func (ft FieldType) IsType(t FieldType) bool

func (FieldType) Size

func (ft FieldType) Size() uint

func (FieldType) String

func (ft FieldType) String() string

type Reader

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

func NewReader

func NewReader(data []byte) *Reader

func (*Reader) Copy

func (r *Reader) Copy(ptr unsafe.Pointer, length int)

func (*Reader) Data

func (r *Reader) Data() []byte

func (*Reader) Pos

func (r *Reader) Pos() int

func (*Reader) Read

func (r *Reader) Read(length int) uintptr

func (*Reader) ReadLen

func (r *Reader) ReadLen() int

type StructField

type StructField struct {
	*Field
	// contains filtered or unexported fields
}

type Writer

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

func NewWriter

func NewWriter() *Writer

func (*Writer) Copy

func (w *Writer) Copy(ptr unsafe.Pointer, length int)

func (*Writer) Data

func (w *Writer) Data() []byte

func (*Writer) WriteLen

func (w *Writer) WriteLen(length int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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