cbornode

package module
v1.2.13 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2018 License: MIT Imports: 13 Imported by: 0

README

go-ipld-cbor

Coverage Status Travis CI

An implementation of a cbor encoded merkledag object.

Table of Contents

Install

make install

Usage

TODO: Right now this package isn't the easiest to use, it will be getting better rapidly, soon.

// Make an object
obj := map[interface{}]interface{}{
	"foo": "bar",
	"baz": &Link{
		Target: myCid,
	},
}

// Parse it into an ipldcbor node
nd, err := WrapMap(obj)

fmt.Println(nd.Links())

Contribute

PRs are welcome!

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

License

MIT © Jeromy Johnson

Documentation

Index

Constants

View Source
const CBORTagLink = 42

Variables

View Source
var ErrNoSuchLink = errors.New("no such link found")

Functions

func DecodeBlock added in v1.2.3

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

Decode a CBOR encoded Block into an IPLD Node.

This method *does not* canonicalize and *will* preserve the CID. As a matter of fact, it will assume that `block.Cid()` returns the correct CID and will make no effort to validate this assumption.

In general, you should not be calling this method directly. Instead, you should be calling the `Decode` method from the `go-ipld-format` package. That method will pick the right decoder based on the Block's CID.

Note: This function keeps a reference to `block` and assumes that it is immutable.

func DecodeInto

func DecodeInto(b []byte, v interface{}) error

DecodeInto decodes a serialized ipld cbor object into the given object.

func DumpObject added in v0.5.0

func DumpObject(obj interface{}) ([]byte, error)

func EncoderFilter added in v0.5.0

func EncoderFilter(i interface{}) interface{}

Types

type IpldLinkDecoder added in v0.5.0

type IpldLinkDecoder struct{}

func (*IpldLinkDecoder) DecodeTarget added in v0.5.0

func (d *IpldLinkDecoder) DecodeTarget() interface{}

func (*IpldLinkDecoder) GetTag added in v0.5.0

func (d *IpldLinkDecoder) GetTag() uint64

func (*IpldLinkDecoder) PostDecode added in v0.5.0

func (d *IpldLinkDecoder) PostDecode(i interface{}) (interface{}, error)

type Node

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

func Decode

func Decode(b []byte, mhType uint64, mhLen int) (*Node, error)

Decode a CBOR object into an IPLD Node.

If passed a non-canonical CBOR node, this function will canonicalize it. Therefore, `bytes.Equal(b, Decode(b).RawData())` may not hold. If you already have a CID for this data and want to ensure that it doesn't change, you should use `DecodeBlock`. mhType is multihash code to use for hashing, for example mh.SHA2_256

Note: This function does not hold onto `b`. You may reuse it.

func FromJson added in v0.3.0

func FromJson(r io.Reader, mhType uint64, mhLen int) (*Node, error)

func WrapObject added in v1.0.0

func WrapObject(m interface{}, mhType uint64, mhLen int) (*Node, error)

func (*Node) Cid

func (n *Node) Cid() *cid.Cid

func (*Node) Copy added in v0.4.0

func (n *Node) Copy() node.Node
func (n *Node) Links() []*node.Link

func (*Node) Loggable

func (n *Node) Loggable() map[string]interface{}

func (*Node) MarshalJSON

func (n *Node) MarshalJSON() ([]byte, error)

func (*Node) RawData

func (n *Node) RawData() []byte

func (*Node) Resolve

func (n *Node) Resolve(path []string) (interface{}, []string, error)
func (n *Node) ResolveLink(path []string) (*node.Link, []string, error)

func (*Node) Size

func (n *Node) Size() (uint64, error)

func (*Node) Stat

func (n *Node) Stat() (*node.NodeStat, error)

func (*Node) String

func (n *Node) String() string

func (*Node) Tree

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

Jump to

Keyboard shortcuts

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