rlpstruct

package
v0.0.0-...-e9b893c Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package rlpstruct implements struct processing for RLP encoding/decoding.

In particular, this package handles all rules around field filtering, struct tags and nil value determination.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProcessFields

func ProcessFields(allFields []Field) ([]Field, []Tags, error)

ProcessFields filters the given struct fields, returning only fields that should be considered for encoding/decoding.

Types

type Field

type Field struct {
	Name     string
	Index    int
	Exported bool
	Type     Type
	Tag      string
}

Field represents a struct field.

type NilKind

type NilKind uint8

NilKind is the RLP value encoded in place of nil pointers.

const (
	NilKindString NilKind = 0x80
	NilKindList   NilKind = 0xC0
)

type TagError

type TagError struct {
	StructType string

	// These are set by this package.
	Field string
	Tag   string
	Err   string
}

TagError is raised for invalid struct tags.

func (TagError) Error

func (e TagError) Error() string

type Tags

type Tags struct {
	// rlp:"nil" controls whether empty input results in a nil pointer.
	// nilKind is the kind of empty value allowed for the field.
	NilKind NilKind
	NilOK   bool

	// rlp:"optional" allows for a field to be missing in the input list.
	// If this is set, all subsequent fields must also be optional.
	Optional bool

	// rlp:"tail" controls whether this field swallows additional list elements. It can
	// only be set for the last field, which must be of slice type.
	Tail bool

	// rlp:"-" ignores fields.
	Ignored bool
}

Tags represents struct tags.

type Type

type Type struct {
	Name      string
	Kind      reflect.Kind
	IsEncoder bool  // whether type implements rlp.Encoder
	IsDecoder bool  // whether type implements rlp.Decoder
	Elem      *Type // non-nil for Kind values of Ptr, Slice, Array
}

Type represents the attributes of a Go type.

func (Type) DefaultNilValue

func (t Type) DefaultNilValue() NilKind

DefaultNilValue determines whether a nil pointer to t encodes/decodes as an empty string or empty list.

Jump to

Keyboard shortcuts

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