block

package
v0.0.0-...-3078d79 Latest Latest
Warning

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

Go to latest
Published: May 17, 2020 License: GPL-3.0 Imports: 14 Imported by: 3

Documentation

Index

Constants

View Source
const (
	CodecISCN         = 0x0264
	CodecRights       = 0x0265
	CodecStakeholders = 0x0266
	CodecContent      = 0x0267
	CodecEntity       = 0x0268

	// Internal Codec
	CodecRight       = 0x02BD
	CodecStakeholder = 0x02D1
	CodecTimePeriod  = 0x033F
)

IPLD Codecs for ISCN See the authoritative document: https://github.com/multiformats/multicodec/blob/master/table.csv

View Source
const (
	// ContextKey is the key of context of ISCN object
	ContextKey = "context"
)
View Source
const (
	// TimestampPattern is the regexp for specific ISO 8601 datetime string
	TimestampPattern = `^[0-9]{4}` + `-` +
		`(?:1[0-2]|0[1-9])` + `-` +
		`(?:3[01]|0[1-9]|[12][0-9])` + `T` +
		`(?:2[0-3]|[01][0-9])` + `:` +
		`(?:[0-5][0-9])` + `:` +
		`(?:[0-5][0-9])` +
		`(?:Z|[+-](?:2[0-3]|[01][0-9]):(?:[0-5][0-9]))$`
)

Variables

This section is empty.

Functions

func DecodeBlock

func DecodeBlock(block blocks.Block) (node.Node, error)

DecodeBlock decodes the raw IPLD data back to data object

func IsIscnObject

func IsIscnObject(codec uint64) bool

IsIscnObject checks the codec whether belongs an ISCN object

func RegisterIscnObjectFactory

func RegisterIscnObjectFactory(codec uint64, schemaName string, factories []CodecFactoryFunc)

RegisterIscnObjectFactory registers an array of ISCN object factory functions

func ValidateParent

func ValidateParent(version *Number, parent *Cid) error

ValidateParent between version and parent CID

Types

type Base

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

Base is the basic block of all kind of ISCN objects

func NewBase

func NewBase(codec uint64, name string, version uint64, schema []Data) (*Base, error)

NewBase creates the basic block of an ISCN object

func (*Base) Cid

func (b *Base) Cid() cid.Cid

Cid returns the CID of the block header

func (*Base) Copy

func (*Base) Copy() node.Node

Copy will go away. It is here to comply with the Node interface.

func (*Base) Decode

func (b *Base) Decode(data map[string]interface{}) error

Decode the data back to ISCN object

func (*Base) Encode

func (b *Base) Encode() (map[string]interface{}, error)

Encode the ISCN object to CBOR serialized data

func (*Base) GetArray

func (b *Base) GetArray(key string) ([]interface{}, error)

GetArray returns the value of 'key' as array

func (*Base) GetBytes

func (b *Base) GetBytes(key string) ([]byte, error)

GetBytes returns the value of 'key' as byte slice

func (*Base) GetCid

func (b *Base) GetCid(key string) (cid.Cid, error)

GetCid returns the value of 'key' as Cid

func (*Base) GetCustom

func (b *Base) GetCustom() map[string]interface{}

GetCustom returns the custom data

func (*Base) GetData

func (b *Base) GetData() map[string]interface{}

GetData returns the block data as map[string]interface{}

func (*Base) GetInt32

func (b *Base) GetInt32(key string) (int32, error)

GetInt32 returns the value of 'key' as int32

func (*Base) GetInt64

func (b *Base) GetInt64(key string) (int64, error)

GetInt64 returns the value of 'key' as int64

func (b *Base) GetLink(key string) (cid.Cid, string, error)

GetLink returns the value of 'key' as link, a link can be a Cid or a URL

func (*Base) GetName

func (b *Base) GetName() string

GetName returns the name of the the ISCN object

func (*Base) GetObject

func (b *Base) GetObject(key string) (interface{}, error)

GetObject returns the value of 'key' as object

func (*Base) GetString

func (b *Base) GetString(key string) (string, error)

GetString returns the value of 'key' as string

func (*Base) GetUint32

func (b *Base) GetUint32(key string) (uint32, error)

GetUint32 returns the value of 'key' as int32

func (*Base) GetUint64

func (b *Base) GetUint64(key string) (uint64, error)

GetUint64 returns the value of 'key' as int64

func (*Base) GetVersion

func (b *Base) GetVersion() uint64

GetVersion returns the schema version of the ISCN object

func (b *Base) Links() []*node.Link

Links is a helper function that returns all links within this object HINT: Use `ipfs refs <cid>`

func (*Base) Loggable

func (b *Base) Loggable() map[string]interface{}

Loggable returns a map the type of IPLD Link

func (*Base) MarkNested

func (b *Base) MarkNested()

MarkNested marks the block as a nested block

func (*Base) MarshalJSON

func (b *Base) MarshalJSON() ([]byte, error)

MarshalJSON convert the block to JSON format

func (*Base) RawData

func (b *Base) RawData() []byte

RawData returns the binary of the CBOR encode of the block header

func (*Base) Resolve

func (b *Base) Resolve(path []string) (interface{}, []string, error)

Resolve resolves a path through this node, stopping at any link boundary and returning the object found as well as the remaining path to traverse

func (b *Base) ResolveLink(path []string) (*node.Link, []string, error)

ResolveLink is a helper function that allows easier traversal of links through blocks

func (*Base) SetData

func (b *Base) SetData(data map[string]interface{}) error

SetData sets and validates the data

func (*Base) SetValidator

func (b *Base) SetValidator(validator Validator)

SetValidator sets the validator function

func (*Base) Size

func (*Base) Size() (uint64, error)

Size will go away. It is here to comply with the Node interface.

func (*Base) Stat

func (*Base) Stat() (*node.NodeStat, error)

Stat will go away. It is here to comply with the Node interface.

func (*Base) String

func (b *Base) String() string

String is a helper for output

func (*Base) Tree

func (*Base) Tree(path string, depth int) []string

Tree lists all paths within the object under 'path', and up to the given depth. To list the entire object (similar to `find .`) pass "" and -1

type Cid

type Cid struct {
	*DataBase
	// contains filtered or unexported fields
}

Cid is a data handler for IPFS CID

func NewCid

func NewCid(key string, isRequired bool, codec uint64) *Cid

NewCid creates a IPFS CID data handler

func (*Cid) Decode

func (d *Cid) Decode(data interface{}, m *map[string]interface{}) error

Decode Cid

func (*Cid) Encode

func (d *Cid) Encode(m *map[string]interface{}) error

Encode Cid

func (d *Cid) Link() (*node.Link, error)

Link returns a link object for IPLD

func (*Cid) Prototype

func (d *Cid) Prototype() Data

Prototype creates a prototype Cid

func (*Cid) Resolve

func (d *Cid) Resolve(path []string) (interface{}, []string, error)

Resolve resolves the link

func (*Cid) Set

func (d *Cid) Set(data interface{}) error

Set the value of IPFS CID

func (*Cid) ToJSON

func (d *Cid) ToJSON(om *ordered.OrderedMap) error

ToJSON prepares the data for MarshalJSON

type Codec

type Codec interface {
	IscnObject

	MarkNested()

	GetData() map[string]interface{}
	SetData(map[string]interface{}) error

	Encode() (map[string]interface{}, error)
	Decode(map[string]interface{}) error
}

Codec is the interface for the CODEC of ISCN object

type CodecFactoryFunc

type CodecFactoryFunc func() (Codec, error)

CodecFactoryFunc returns a factory function to create ISCN object

type Context

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

Context is a data handler for the context of ISCN object

func NewContext

func NewContext(schema string) *Context

NewContext creates a context of ISCN object with schema name

func (*Context) Decode

func (d *Context) Decode(data interface{}, m *map[string]interface{}) error

Decode Context

func (*Context) Encode

func (d *Context) Encode(m *map[string]interface{}) error

Encode Context

func (*Context) Prototype

func (d *Context) Prototype() Data

Prototype creates a prototype Context

func (*Context) Resolve

func (d *Context) Resolve(path []string) (interface{}, []string, error)

Resolve resolves the value

func (*Context) Set

func (d *Context) Set(data interface{}) error

Set the value of Context

func (*Context) ToJSON

func (d *Context) ToJSON(om *ordered.OrderedMap) error

ToJSON prepares the data for MarshalJSON

type Data

type Data interface {
	Prototype() Data

	IsRequired() bool
	IsDefined() bool

	Set(interface{}) error
	GetKey() string

	Encode(*map[string]interface{}) error
	Decode(interface{}, *map[string]interface{}) error
	ToJSON(*ordered.OrderedMap) error

	Resolve(path []string) (interface{}, []string, error)
}

Data is the interface for the data property handler

type DataArray

type DataArray struct {
	*DataBase
	// contains filtered or unexported fields
}

DataArray is an array of data handler

func NewDataArray

func NewDataArray(key string, isRequired bool, prototype Data) *DataArray

NewDataArray creates an array of data handler

func (*DataArray) Decode

func (d *DataArray) Decode(data interface{}, m *map[string]interface{}) error

Decode DataArray

func (*DataArray) Encode

func (d *DataArray) Encode(m *map[string]interface{}) error

Encode DataArray

func (*DataArray) Prototype

func (d *DataArray) Prototype() Data

Prototype creates a prototype DataArray

func (*DataArray) Resolve

func (d *DataArray) Resolve(path []string) (interface{}, []string, error)

Resolve resolves the value

func (*DataArray) Set

func (d *DataArray) Set(data interface{}) error

Set the value of data handler array

func (*DataArray) ToJSON

func (d *DataArray) ToJSON(om *ordered.OrderedMap) error

ToJSON prepares the data for MarshalJSON

type DataBase

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

DataBase is the base struct for handling data property

func NewDataBase

func NewDataBase(key string, isRequired bool) *DataBase

NewDataBase creates a base struct for handling data property

func (*DataBase) Decode

func (b *DataBase) Decode(interface{}, *map[string]interface{}) error

Decode the data

func (*DataBase) GetKey

func (b *DataBase) GetKey() string

GetKey returns the key of the data property

func (*DataBase) IsDefined

func (b *DataBase) IsDefined() bool

IsDefined checks whether the data is well defined

func (*DataBase) IsRequired

func (b *DataBase) IsRequired() bool

IsRequired checks whether the data handler is required

func (*DataBase) Prototype

func (b *DataBase) Prototype() *DataBase

Prototype creates a prototype DataBase

func (*DataBase) Set

func (b *DataBase) Set(interface{}) error

Set the value of data

type IscnObject

type IscnObject interface {
	node.Node

	GetName() string
	GetVersion() uint64
	GetCustom() map[string]interface{}

	GetArray(string) ([]interface{}, error)
	GetObject(string) (interface{}, error)
	GetBytes(string) ([]byte, error)
	GetInt32(string) (int32, error)
	GetUint32(string) (uint32, error)
	GetInt64(string) (int64, error)
	GetUint64(string) (uint64, error)
	GetString(string) (string, error)
	GetCid(string) (cid.Cid, error)
	GetLink(string) (cid.Cid, string, error)

	MarshalJSON() ([]byte, error)
}

IscnObject is the interface for the data object of ISCN object

func Decode

func Decode(rawData []byte, c cid.Cid) (IscnObject, error)

Decode decodes the raw IPLD data back to data object

func Encode

func Encode(
	codec uint64,
	version uint64,
	data map[string]interface{},
) (IscnObject, error)

Encode the data to specific ISCN object and version

type Number

type Number struct {
	*DataBase
	// contains filtered or unexported fields
}

Number is a data handler for the number

func NewNumber

func NewNumber(key string, isRequired bool, ty NumberType) *Number

NewNumber creates a number data handler

func (*Number) Decode

func (d *Number) Decode(data interface{}, m *map[string]interface{}) error

Decode Number

func (*Number) Encode

func (d *Number) Encode(m *map[string]interface{}) error

Encode Number

func (*Number) GetInt32

func (d *Number) GetInt32() (int32, error)

GetInt32 returns an int32 value

func (*Number) GetInt64

func (d *Number) GetInt64() (int64, error)

GetInt64 returns an int64 value

func (*Number) GetType

func (d *Number) GetType() NumberType

GetType returns the type of the number

func (*Number) GetUint32

func (d *Number) GetUint32() (uint32, error)

GetUint32 returns an uint32 value

func (*Number) GetUint64

func (d *Number) GetUint64() (uint64, error)

GetUint64 returns an uint64 value

func (*Number) Prototype

func (d *Number) Prototype() Data

Prototype creates a prototype Number

func (*Number) Resolve

func (d *Number) Resolve(path []string) (interface{}, []string, error)

Resolve resolves the value

func (*Number) Set

func (d *Number) Set(data interface{}) error

Set the value of number

func (*Number) ToJSON

func (d *Number) ToJSON(om *ordered.OrderedMap) error

ToJSON prepares the data for MarshalJSON

type NumberType

type NumberType int

NumberType is a enum type for the type of a number

const (
	// Int32T represents int32
	Int32T NumberType = iota

	// Uint32T represents uint32
	Uint32T

	// Int64T represents int64
	Int64T

	// Uint64T represents uint64
	Uint64T
)

type Object

type Object struct {
	*DataBase
	// contains filtered or unexported fields
}

Object is a data handler of a nested ISCN object

func NewObject

func NewObject(key string, isRequired bool, prototypeFunc ObjectPrototypeFunc) *Object

NewObject creates a nested ISCN object data handler

func (*Object) Decode

func (d *Object) Decode(data interface{}, m *map[string]interface{}) error

Decode Object

func (*Object) Encode

func (d *Object) Encode(m *map[string]interface{}) error

Encode Object

func (*Object) Prototype

func (d *Object) Prototype() Data

Prototype creates a prototype Object

func (*Object) Resolve

func (d *Object) Resolve(path []string) (interface{}, []string, error)

Resolve resolves the value

func (*Object) Set

func (d *Object) Set(data interface{}) error

Set the value of Object

func (*Object) ToJSON

func (d *Object) ToJSON(om *ordered.OrderedMap) error

ToJSON prepares the data for MarshalJSON

type ObjectPrototypeFunc

type ObjectPrototypeFunc func() Codec

ObjectPrototypeFunc returns a factory function to create ISCN object prototype

type String

type String struct {
	*DataBase
	// contains filtered or unexported fields
}

String is a data handler for the string

func NewString

func NewString(key string, isRequired bool) *String

NewString creates a string data handler

func NewStringWithFilter

func NewStringWithFilter(key string, isRequired bool, filter []string) *String

NewStringWithFilter creates a string data handler with filter

func (*String) Decode

func (d *String) Decode(data interface{}, m *map[string]interface{}) error

Decode String

func (*String) Encode

func (d *String) Encode(m *map[string]interface{}) error

Encode String

func (*String) Get

func (d *String) Get() string

Get returns the string value

func (*String) Prototype

func (d *String) Prototype() Data

Prototype creates a prototype String

func (*String) Resolve

func (d *String) Resolve(path []string) (interface{}, []string, error)

Resolve resolves the value

func (*String) Set

func (d *String) Set(data interface{}) error

Set the value of String

func (*String) ToJSON

func (d *String) ToJSON(om *ordered.OrderedMap) error

ToJSON prepares the data for MarshalJSON

type Timestamp

type Timestamp struct {
	*DataBase
	// contains filtered or unexported fields
}

Timestamp is a data handler for a ISO 8601 timestamp string

func NewTimestamp

func NewTimestamp(key string, isRequired bool) *Timestamp

NewTimestamp creates a ISO 8601 timestamp string handler

func (*Timestamp) Decode

func (d *Timestamp) Decode(data interface{}, m *map[string]interface{}) error

Decode Timestamp

func (*Timestamp) Encode

func (d *Timestamp) Encode(m *map[string]interface{}) error

Encode Timestamp

func (*Timestamp) Prototype

func (d *Timestamp) Prototype() Data

Prototype creates a prototype Timestamp

func (*Timestamp) Resolve

func (d *Timestamp) Resolve(path []string) (interface{}, []string, error)

Resolve resolves the value

func (*Timestamp) Set

func (d *Timestamp) Set(data interface{}) error

Set the value of timestamp string

func (*Timestamp) ToJSON

func (d *Timestamp) ToJSON(om *ordered.OrderedMap) error

ToJSON prepares the data for MarshalJSON

type Validator

type Validator func() error

Validator is a validate function for post validation after set data in block

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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