encoding

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 8 Imported by: 4

Documentation

Overview

Package encoding handles Tezos binary encoding

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ctx

func Ctx(ctx *Context) func(*[]flag, *Context)

func Decode

func Decode(data []byte, v any, opt ...Option) (rest []byte, err error)

func Dynamic

func Dynamic() func(*[]flag, *Context)

func Encode

func Encode(out io.Writer, v any, opt ...Option) error

func Enums

func Enums(er *EnumRegistry) func(*[]flag, *Context)

func ListVariants

func ListVariants[T any]() []T

func Optional

func Optional() func(*[]flag, *Context)

func RegisterEnum

func RegisterEnum[T any](enum *Enum[T])

RegisterEnum registers enum type in the global registry

func RegisterType

func RegisterType[T any](decoder func([]byte, *Context) (T, []byte, error))

RegisterType registers user interface type in the global registry

func Types

func Types(tr *TypeRegistry) func(*[]flag, *Context)

Types

type Context

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

func NewContext

func NewContext() *Context

func (*Context) Enums

func (ctx *Context) Enums(er *EnumRegistry)

func (*Context) Get

func (ctx *Context) Get(key any) any

func (*Context) Set

func (ctx *Context) Set(key any, val any) *Context

func (*Context) Types

func (ctx *Context) Types(tr *TypeRegistry)

type Decoder

type Decoder interface {
	DecodeTZ(data []byte, ctx *Context) (rest []byte, err error)
}

type Encoder

type Encoder interface {
	EncodeTZ(ctx *Context) ([]byte, error)
}

type Enum

type Enum[T any] struct {
	Variants Variants[T]
	Default  T
}

type EnumRegistry

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

EnumRegistry stores variant types

func NewEnumRegistry

func NewEnumRegistry() *EnumRegistry

NewEnumRegistry returns new empty EnumRegistry

func (*EnumRegistry) ListVariants

func (e *EnumRegistry) ListVariants(typ any) []any

func (*EnumRegistry) RegisterEnum

func (v *EnumRegistry) RegisterEnum(variants, def any)

type ErrBuffer

type ErrBuffer int

func (ErrBuffer) Error

func (err ErrBuffer) Error() string

type Error

type Error struct {
	Path ErrorPath
	Err  error
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorPath

type ErrorPath []PathSeg

func (ErrorPath) String

func (e ErrorPath) String() string

type FieldSelector

type FieldSelector reflect.StructField

func (FieldSelector) SegSelector

func (FieldSelector) SegSelector()

func (*FieldSelector) String

func (f *FieldSelector) String() string

type IndexSelector

type IndexSelector int

func (IndexSelector) SegSelector

func (IndexSelector) SegSelector()

func (IndexSelector) String

func (i IndexSelector) String() string

type Option

type Option func(fl *[]flag, opt *Context)

type PathSeg

type PathSeg interface {
	SegSelector()
	fmt.Stringer
}

type TypeRegistry

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

TypeRegistry stores uses interface type constructors (decoders)

func NewTypeRegistry

func NewTypeRegistry() *TypeRegistry

NewTypeRegistry returns new empty TypeRegistry

func (*TypeRegistry) RegisterType

func (r *TypeRegistry) RegisterType(fn any)

type TypeSelector

type TypeSelector struct {
	reflect.Type
}

func (TypeSelector) SegSelector

func (TypeSelector) SegSelector()

func (TypeSelector) String

func (t TypeSelector) String() string

type Variants

type Variants[T any] map[uint8]T

Jump to

Keyboard shortcuts

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