serial

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Copyright 2017-2018 OneLedger

We want encapsulated conversions for the three different pathways:

  • transactions sent from Tendermint (is this a mix between wire and JSON?)
  • data stored in LevelDB
  • queries coming in from http

Basic stack implementation

TODO: Currently reversed, which is probably not good for performance.

Copyright 2017-2018 OneLedger

Index

Constants

View Source
const (
	UNKNOWN = iota
	PRIMITIVE
	STRUCT
	MAP
	SLICE
	ARRAY
)

Variables

This section is empty.

Functions

func Alloc

func Alloc(dataType string, size int) interface{}

Alloc a new variable of any type

func CheckValue

func CheckValue(element reflect.Value) bool

func CleanValue

func CleanValue(action *Action, input interface{}) interface{}

func Clone

func Clone(base interface{}) interface{}

Make a deep copy of the data

func CloneNode

func CloneNode(action *Action, input interface{}) interface{}

Clone each element

func Contract

func Contract(base interface{}) interface{}

Remove any SerialWrappers

func ContractNode

func ContractNode(action *Action, input interface{}) interface{}

Replace any incoming SerialWrappers with the correct structure

func ConvertMap

func ConvertMap(container interface{}) (map[string]interface{}, int)

ConvertMap takes a structure and return a map of its elements

func ConvertNumber

func ConvertNumber(fieldType reflect.Type, value reflect.Value) reflect.Value

ConvertNumber handles JSON numbers as they are float64 from the parser

func ConvertValue

func ConvertValue(value interface{}, fieldType reflect.Type) reflect.Value

Convert any value to an arbitrary type

func Deserialize

func Deserialize(input []byte, output interface{}, medium Format) (msg interface{}, err error)

Given a serialized slice, put it back into the original struct format

func Extend

func Extend(base interface{}) interface{}

Clone and add in SerialWrapper

func ExtendNode

func ExtendNode(action *Action, input interface{}) interface{}

Extend the input by replacing all structures with a wrapper

func GetBaseType

func GetBaseType(base interface{}) reflect.Type

GetBaseType returns the underlying value, even if it is a pointer

func GetBaseTypeString

func GetBaseTypeString(base interface{}) string

Find the type string that matches this variable

func GetBaseValue

func GetBaseValue(base interface{}) reflect.Value

GetBaseValue returns the underlying value, even if it is a pointer

func GetInt

func GetInt(value string, defaultValue int) int

TODO: This should be in the convert packahe, but it shares data with this one

func GetString

func GetString(value reflect.Value) string

func IgnoreType

func IgnoreType(dataType reflect.Type) bool

func IgnoreVariable

func IgnoreVariable(value interface{}) bool

func IsContainer

func IsContainer(input interface{}) bool

Container data types

func IsDifficult

func IsDifficult(input interface{}) bool

Difficult data types

func IsInterface

func IsInterface(input interface{}) bool

func IsNilValue

func IsNilValue(input interface{}) bool

See if the underlying Value is nil

func IsPointer

func IsPointer(input interface{}) bool

func IsPrimitive

func IsPrimitive(input interface{}) bool

Language primitives

func IsPrimitiveArray

func IsPrimitiveArray(input interface{}) bool

func IsPrimitiveContainer

func IsPrimitiveContainer(input interface{}) bool

An array or slice that is based around primtives, like []byte

func IsPrimitiveSlice

func IsPrimitiveSlice(input interface{}) bool

func IsSerialWrapper

func IsSerialWrapper(input interface{}) bool

Test to see if this a SerialWrapper struct

func IsSerialWrapperMap

func IsSerialWrapperMap(input interface{}) bool

Can identify a map created from a SerialWrapper, explicitly depends on the SerialWrapper type

func IsSpecial

func IsSpecial(input interface{}) bool

Special datatypes, not to be handled yet.

func IsStructure

func IsStructure(input interface{}) bool

func Iterate

func Iterate(input interface{}, action *Action) interface{}

Iterate the variables in memory, executing functions at each node in the traversal

func Print

func Print(base interface{})

Print is a post order traversal (not that useful, should be pre-order)

func PrintNode

func PrintNode(action *Action, input interface{}) interface{}

PrintNode is called for each node

func Register

func Register(base interface{})

Register a structure by its name

func RegisterForce

func RegisterForce(name string, category Category, dataType reflect.Type, keyType *TypeEntry, valueType *TypeEntry)

Force an entry into the table

func RegisterIgnore

func RegisterIgnore(base interface{})

func Serialize

func Serialize(input interface{}, medium Format) (buffer []byte, err error)

Given any type of input (except Maps), convert it into wire format

func Set

func Set(parent interface{}, fieldName string, child interface{}) (status bool)

Set a structure with a given value, convert as necessary

func SetArray

func SetArray(parent interface{}, index int, child interface{}) bool

SetSlice takes a pointer to a structure and sets it.

func SetMap

func SetMap(parent interface{}, fieldName string, child interface{}) bool

SetMap takes a pointer to a structure and sets it.

func SetProcessed

func SetProcessed(action *Action, parent string, name string, input interface{})

Set the as a processed result, and handle pointers nicely.

func SetSlice

func SetSlice(parent interface{}, index int, child interface{}) bool

SetSlice takes a pointer to a structure and sets it.

func SetStruct

func SetStruct(parent interface{}, fieldName string, child interface{}) bool

SetStructure takes a pointer to a structure and sets it.

func UnderlyingType

func UnderlyingType(input interface{}) reflect.Type

func Value2String

func Value2String(key reflect.Value) string

Types

type Action

type Action struct {
	// Config Items
	IgnorePrimitives bool

	// Current Values
	Path      Stack
	Name      string
	Index     int
	IsPointer bool

	// Processing Function
	ProcessField func(*Action, interface{}) interface{}

	// Kids that have already been processed
	Processed map[string]Parameters
}

Action is the context for the iteration, each ProcessField function gets an updated pointer

type Category

type Category int

type Child

type Child struct {
	Kind   reflect.Kind
	Number int
	Name   string
	Value  interface{}
}

Extract this info once, even though it is used in multiple levels of the recursion

func GetChildren

func GetChildren(input interface{}) []Child

Get the Fields from a structure, and return them into a field array

func GetChildrenArray

func GetChildrenArray(input interface{}) []Child

Get children from an array

func GetChildrenMap

func GetChildrenMap(input interface{}) []Child

Get Children from a Map

func GetChildrenSlice

func GetChildrenSlice(input interface{}) []Child

Get Children from a slice

func GetChildrenStruct

func GetChildrenStruct(input interface{}) []Child

Get Children from a structure

type Format

type Format int
const (
	PERSISTENT Format = iota
	NETWORK
	CLIENT
	JSON
)

type Message

type Message = []byte

type Parameters

type Parameters struct {
	Children map[string]interface{}
}

type SerialWrapper

type SerialWrapper struct {
	Type   string
	Fields map[string]interface{}
	Size   int
}

type Stack

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

func NewStack

func NewStack() *Stack

func (Stack) Len

func (stack Stack) Len() int

func (Stack) Peek

func (stack Stack) Peek() interface{}

func (Stack) PeekN

func (stack Stack) PeekN(index int) interface{}

func (*Stack) Pop

func (stack *Stack) Pop() interface{}

func (Stack) Print

func (stack Stack) Print()

func (*Stack) Push

func (stack *Stack) Push(element interface{})

func (*Stack) Shift

func (stack *Stack) Shift()

func (Stack) StringPeekN

func (stack Stack) StringPeekN(index int) string

type TypeEntry

type TypeEntry struct {
	Name      string
	Category  Category
	RootType  reflect.Type
	DataType  reflect.Type
	KeyType   *TypeEntry
	ValueType *TypeEntry
}

func GetTypeEntry

func GetTypeEntry(name string, size int) TypeEntry

func NewPrimitiveEntry

func NewPrimitiveEntry(name string, category Category, root reflect.Type) *TypeEntry

func ParseType

func ParseType(name string, count int) TypeEntry

Given a data type string, break it down into reflect.Type entries

func (TypeEntry) String

func (entry TypeEntry) String() string

Jump to

Keyboard shortcuts

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