persistence

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

README

Event based Marshalling and Unmarshalling framework

This package implements a framework for marshalling and unmarshalling hierarchical data via events.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array []interface{}

func NewArray

func NewArray() Array

func (Array) Finalize

func (a Array) Finalize(
	path []string,
	key string,
	node Unmarshaller,
) error

func (Array) Unmarshal

func (a Array) Unmarshal(
	path []string,
	key string,
	elemType ElementType,
	value interface{},
) (
	Unmarshaller,
	Unmarshaller,
	error,
)

type ElementType

type ElementType int
const (
	EtUnknown ElementType = iota
	EtObject
	EtArray
	EtKey
	EtValue
	EtArrayValue
)

type JSONStreamParser

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

func NewJSONStreamParser

func NewJSONStreamParser(u Unmarshaller) *JSONStreamParser

func (*JSONStreamParser) Parse

func (p *JSONStreamParser) Parse(input io.Reader) (Unmarshaller, error)

type Map

type Map map[string]interface{}

func NewMap

func NewMap() Map

func (Map) Finalize

func (m Map) Finalize(
	path []string,
	key string,
	node Unmarshaller,
) error

func (Map) Unmarshal

func (m Map) Unmarshal(
	path []string,
	key string,
	elemType ElementType,
	value interface{},
) (
	Unmarshaller,
	Unmarshaller,
	error,
)

type Unmarshaller

type Unmarshaller interface {

	// unmarshall callback function to handle parsed elements.
	//
	// in: path     - the absolute parent path of the child element being handled
	// in: key      - the key of the stream element being handled
	// in: elemType - the type of the stream element. this can be one of Object, Array
	//                or Value. if it is an Object or Array then the returned
	//                Unmarshaller can be specific for that instance
	// in: value    - the value to be handled. if the key type is an Object
	//                or Array this will be nil
	//
	// out: Unmarshaller - the unmarshaller for current node
	// out: Unmarshaller - the unmarshaller for the next node
	// out: error        - if an error occurs while handling the data
	Unmarshal(
		path []string,
		key string,
		elemType ElementType,
		value interface{},
	) (Unmarshaller, Unmarshaller, error)

	// finalizes the a stream object or array once it has been completely parsed
	//
	// in: path - the absolute parent path of the child element being handled
	// in: key  - the key of the stream element being handled
	// in: node - the node to be finalized
	//
	// out: error - if an error occurs while handling the data
	Finalize(
		path []string,
		key string,
		node Unmarshaller,
	) error
}

Jump to

Keyboard shortcuts

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