format

package module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2017 License: MIT Imports: 5 Imported by: 0

README

go-ipld-format

Coverage Status Travis CI

go-ipld-format is a set of interfaces that a type needs to implement in order to be a part of the ipld merkle-forest.

Table of Contents

Install

make install

Contribute

PRs are welcome!

Small note: If editing the Readme, please conform to the standard-readme specification.

License

MIT © Jeromy Johnson

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register added in v0.5.0

func Register(codec uint64, decoder DecodeBlockFunc)

Register registers block decoders with the default BlockDecoder.

Types

type BlockDecoder added in v0.4.8

type BlockDecoder interface {
	Register(codec uint64, decoder DecodeBlockFunc)
	Decode(blocks.Block) (Node, error)
}
var DefaultBlockDecoder BlockDecoder = &safeBlockDecoder{decoders: make(map[uint64]DecodeBlockFunc)}

type DecodeBlockFunc added in v0.4.8

type DecodeBlockFunc func(block blocks.Block) (Node, error)

DecodeBlockFunc functions decode blocks into nodes.

type Link struct {
	// utf string name. should be unique per object
	Name string // utf8

	// cumulative size of target object
	Size uint64

	// multihash of the target object
	Cid *cid.Cid
}

Link represents an IPFS Merkle DAG Link between Nodes.

func MakeLink(n Node) (*Link, error)

MakeLink creates a link to the given node

func (*Link) GetNode

func (l *Link) GetNode(ctx context.Context, serv NodeGetter) (Node, error)

GetNode returns the MDAG Node that this link points to

type Node

type Node interface {
	blocks.Block
	Resolver

	// ResolveLink is a helper function that calls resolve and asserts the
	// output is a link
	ResolveLink(path []string) (*Link, []string, error)

	// Copy returns a deep copy of this node
	Copy() Node

	// Links is a helper function that returns all links within this object
	Links() []*Link

	// TODO: not sure if stat deserves to stay
	Stat() (*NodeStat, error)

	// Size returns the size in bytes of the serialized object
	Size() (uint64, error)
}

func Decode added in v0.4.8

func Decode(block blocks.Block) (Node, error)

Decode decodes the given block using the default BlockDecoder.

type NodeGetter

type NodeGetter interface {
	Get(context.Context, *cid.Cid) (Node, error)
}

type NodeStat

type NodeStat struct {
	Hash           string
	NumLinks       int // number of links in link table
	BlockSize      int // size of the raw, encoded data
	LinksSize      int // size of the links segment
	DataSize       int // size of the data segment
	CumulativeSize int // cumulative size of object and its references
}

NodeStat is a statistics object for a Node. Mostly sizes.

func (NodeStat) String

func (ns NodeStat) String() string

type Resolver added in v0.4.6

type Resolver interface {
	// 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
	Resolve(path []string) (interface{}, []string, error)

	// 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
	Tree(path string, depth int) []string
}

Jump to

Keyboard shortcuts

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