dagpb

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2020 License: Apache-2.0, MIT Imports: 11 Imported by: 0

README

go-ipld-prime-proto

Coverage Status Travis CI

An implementation of the DAG Protobuf for the go-ipld-prime library

Table of Contents

Background

The package adds Dag Protobuf support to go-ipld-prime. It is designed primarily as an adjunct to go-ipld-prime to enable using selectors and Graphsync, features which are unique to go-ipld-prime, with UnixFS v1 files encoded in protobuf.

go-ipld-prime-proto is primarily used to run selectors against Dag Protobuf encoded IPLD Graphs. It does not include robust facilities to support actual creation of DAG protobuf nodes, and none of the actual features for working with files contained in UnixFS. However, it can read, traverse and copy UnixFS data, which is what you need to run selectors and graphsync against existing UnixFS data.

Install

go-ipld-prime-proto requires Go >= 1.13 and can be installed using Go modules

Usage

To run a selector traversal against a graph encoded in Dag-Protobuf, you need to configure it with a custom NodeBuilderChooser. The simplest way to create such a node builder chooser is to take an existing function and pass it to AddDagPBSupportToChooser. This will add support for Dag Protobuf and Raw node encodings, the two types required by UnixFS.

Example:


var existing traversal.NodeBuilderChooser = func(ipld.Link, ipld.LinkContext) ipld.NodeBuilder {
	return ipldfree.NodeBuilder()
}
  
var pbChooser traversal.NodeBuilderChooser = 
dagpb.AddDagPBSupportToChooser(existing)

var selector selector.Selector
var loader ipld.Loader
var unixfsCid cid.Cid

// Load the first node
unixFSRootNode, err := cidlink.Link{Cid: unixfsCid}.Load(ipld.LinkContext{}, dagpb.PBNode__NodeBuilder(), loader)

// execute the traversal
err = traversal.Progress{
  Cfg: &traversal.Config{
    LinkLoader:             loader,
    LinkNodeBuilderChooser: pbChooser,
  },
}.WalkAdv(unixFSRootNode, allSelector, func(pg traversal.Progress, nd ipld.Node, r traversal.VisitReason) error {
  // do something with your traversed nodes here
}

All so checkout unixfs_test.go for good example of a complete setup with UnixFS files.

Contribute

PRs are welcome!

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

License

This library is dual-licensed under Apache 2.0 and MIT terms.

Copyright 2019. Protocol Labs, Inc.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoAutomaticDecoding means the NodeBuilder must provide a fast path decoding method on its own
	ErrNoAutomaticDecoding = errors.New("No automatic decoding for this type, node builder must provide fast path")
	// ErrNoAutomaticEncoding means the Node must provide a fast path encoding method on its own
	ErrNoAutomaticEncoding = errors.New("No automatic encoding for this type, node must provide fast path")
)

Functions

func AddDagPBSupportToChooser

func AddDagPBSupportToChooser(existing traversal.NodeBuilderChooser) traversal.NodeBuilderChooser

AddDagPBSupportToChooser takes an existing NodeBuilderChooser and subs in Protobuf and Raw node builders where neccesary

func Bytes__NodeBuilder

func Bytes__NodeBuilder() ipld.NodeBuilder

func Int__NodeBuilder

func Int__NodeBuilder() ipld.NodeBuilder
func Link__NodeBuilder() ipld.NodeBuilder

func PBDecoder

func PBDecoder(nb ipld.NodeBuilder, r io.Reader) (ipld.Node, error)

PBDecoder is a decoder function for Dag Protobuf nodes

func PBEncoder

func PBEncoder(n ipld.Node, w io.Writer) error

PBEncoder is a encoder function that encodes to Dag Protobuf

func PBLink__NodeBuilder() ipld.NodeBuilder
func PBLink__ReprBuilder() ipld.NodeBuilder
func PBLinks__NodeBuilder() ipld.NodeBuilder

func PBNode__NodeBuilder

func PBNode__NodeBuilder() ipld.NodeBuilder

func PBNode__ReprBuilder

func PBNode__ReprBuilder() ipld.NodeBuilder

func RawDecoder

func RawDecoder(nb ipld.NodeBuilder, r io.Reader) (ipld.Node, error)

RawDecoder is a decoder function for raw coded nodes

func RawEncoder

func RawEncoder(n ipld.Node, w io.Writer) error

RawEncoder encodes a node to a raw block structure

func RawNode__NodeBuilder

func RawNode__NodeBuilder() ipld.NodeBuilder

func String__NodeBuilder

func String__NodeBuilder() ipld.NodeBuilder

Types

type Bytes

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

func (Bytes) AsBool

func (Bytes) AsBool() (bool, error)

func (Bytes) AsBytes

func (x Bytes) AsBytes() ([]byte, error)

func (Bytes) AsFloat

func (Bytes) AsFloat() (float64, error)

func (Bytes) AsInt

func (Bytes) AsInt() (int, error)
func (Bytes) AsLink() (ipld.Link, error)

func (Bytes) AsString

func (Bytes) AsString() (string, error)

func (Bytes) FieldData

func (x Bytes) FieldData() Bytes

func (Bytes) IsNull

func (Bytes) IsNull() bool

func (Bytes) IsUndefined

func (Bytes) IsUndefined() bool

func (Bytes) Length

func (Bytes) Length() int

func (Bytes) ListIterator

func (Bytes) ListIterator() ipld.ListIterator

func (Bytes) Lookup

func (Bytes) Lookup(ipld.Node) (ipld.Node, error)

func (Bytes) LookupIndex

func (Bytes) LookupIndex(idx int) (ipld.Node, error)

func (Bytes) LookupSegment

func (Bytes) LookupSegment(seg ipld.PathSegment) (ipld.Node, error)

func (Bytes) LookupString

func (Bytes) LookupString(string) (ipld.Node, error)

func (Bytes) MapIterator

func (Bytes) MapIterator() ipld.MapIterator

func (Bytes) NodeBuilder

func (Bytes) NodeBuilder() ipld.NodeBuilder

func (Bytes) ReprKind

func (Bytes) ReprKind() ipld.ReprKind

func (Bytes) Representation

func (Bytes) Representation() ipld.Node

func (Bytes) Type

func (Bytes) Type() schema.Type

type Int

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

func (Int) AsBool

func (Int) AsBool() (bool, error)

func (Int) AsBytes

func (Int) AsBytes() ([]byte, error)

func (Int) AsFloat

func (Int) AsFloat() (float64, error)

func (Int) AsInt

func (x Int) AsInt() (int, error)
func (Int) AsLink() (ipld.Link, error)

func (Int) AsString

func (Int) AsString() (string, error)

func (Int) FieldTsize

func (x Int) FieldTsize() Int

func (Int) Int

func (x Int) Int() int

func (Int) IsNull

func (Int) IsNull() bool

func (Int) IsUndefined

func (Int) IsUndefined() bool

func (Int) Length

func (Int) Length() int

func (Int) ListIterator

func (Int) ListIterator() ipld.ListIterator

func (Int) Lookup

func (Int) Lookup(ipld.Node) (ipld.Node, error)

func (Int) LookupIndex

func (Int) LookupIndex(idx int) (ipld.Node, error)

func (Int) LookupSegment

func (Int) LookupSegment(seg ipld.PathSegment) (ipld.Node, error)

func (Int) LookupString

func (Int) LookupString(string) (ipld.Node, error)

func (Int) MapIterator

func (Int) MapIterator() ipld.MapIterator

func (Int) NodeBuilder

func (Int) NodeBuilder() ipld.NodeBuilder

func (Int) ReprKind

func (Int) ReprKind() ipld.ReprKind

func (Int) Representation

func (Int) Representation() ipld.Node

func (Int) Type

func (Int) Type() schema.Type
type Link struct {
	// contains filtered or unexported fields
}

func (Link) AsBool

func (Link) AsBool() (bool, error)

func (Link) AsBytes

func (Link) AsBytes() ([]byte, error)

func (Link) AsFloat

func (Link) AsFloat() (float64, error)

func (Link) AsInt

func (Link) AsInt() (int, error)
func (x Link) AsLink() (ipld.Link, error)

func (Link) AsString

func (Link) AsString() (string, error)

func (Link) FieldHash

func (x Link) FieldHash() Link

func (Link) IsNull

func (Link) IsNull() bool

func (Link) IsUndefined

func (Link) IsUndefined() bool

func (Link) Length

func (Link) Length() int

func (Link) ListIterator

func (Link) ListIterator() ipld.ListIterator

func (Link) Lookup

func (Link) Lookup(ipld.Node) (ipld.Node, error)

func (Link) LookupIndex

func (Link) LookupIndex(idx int) (ipld.Node, error)

func (Link) LookupSegment

func (Link) LookupSegment(seg ipld.PathSegment) (ipld.Node, error)

func (Link) LookupString

func (Link) LookupString(string) (ipld.Node, error)

func (Link) MapIterator

func (Link) MapIterator() ipld.MapIterator

func (Link) NodeBuilder

func (Link) NodeBuilder() ipld.NodeBuilder

func (Link) ReprKind

func (Link) ReprKind() ipld.ReprKind

func (Link) Representation

func (Link) Representation() ipld.Node

func (Link) Type

func (Link) Type() schema.Type

type MaybeBytes

type MaybeBytes struct {
	Maybe typed.Maybe
	Value Bytes
}

TODO generateKindBytes.EmitNativeAccessors TODO generateKindBytes.EmitNativeBuilder

func (MaybeBytes) Must

func (m MaybeBytes) Must() Bytes

type MaybeInt

type MaybeInt struct {
	Maybe typed.Maybe
	Value Int
}

TODO generateKindInt.EmitNativeBuilder

func (MaybeInt) Must

func (m MaybeInt) Must() Int
type MaybeLink struct {
	Maybe typed.Maybe
	Value Link
}

TODO generateKindLink.EmitNativeAccessors TODO generateKindLink.EmitNativeBuilder

func (MaybeLink) Must

func (m MaybeLink) Must() Link
type MaybePBLink struct {
	Maybe typed.Maybe
	Value PBLink
}

func (MaybePBLink) Must

func (m MaybePBLink) Must() PBLink
type MaybePBLinks struct {
	Maybe typed.Maybe
	Value PBLinks
}

TODO generateKindList.EmitNativeAccessors TODO generateKindList.EmitNativeBuilder

func (MaybePBLinks) Must

func (m MaybePBLinks) Must() PBLinks

type MaybePBNode

type MaybePBNode struct {
	Maybe typed.Maybe
	Value PBNode
}

func (MaybePBNode) Must

func (m MaybePBNode) Must() PBNode

type MaybeRawNode

type MaybeRawNode struct {
	Maybe typed.Maybe
	Value RawNode
}

TODO generateKindBytes.EmitNativeAccessors TODO generateKindBytes.EmitNativeBuilder

func (MaybeRawNode) Must

func (m MaybeRawNode) Must() RawNode

type MaybeString

type MaybeString struct {
	Maybe typed.Maybe
	Value String
}

func (MaybeString) Must

func (m MaybeString) Must() String
type PBLink struct {
	Hash  *Link
	Name  *String
	Tsize *Int
}

func (PBLink) AsBool

func (PBLink) AsBool() (bool, error)

func (PBLink) AsBytes

func (PBLink) AsBytes() ([]byte, error)

func (PBLink) AsFloat

func (PBLink) AsFloat() (float64, error)

func (PBLink) AsInt

func (PBLink) AsInt() (int, error)
func (PBLink) AsLink() (ipld.Link, error)

func (PBLink) AsString

func (PBLink) AsString() (string, error)

func (PBLink) IsNull

func (PBLink) IsNull() bool

func (PBLink) IsUndefined

func (PBLink) IsUndefined() bool

func (PBLink) Length

func (PBLink) Length() int

func (PBLink) ListIterator

func (PBLink) ListIterator() ipld.ListIterator

func (PBLink) Lookup

func (x PBLink) Lookup(key ipld.Node) (ipld.Node, error)

func (PBLink) LookupIndex

func (PBLink) LookupIndex(idx int) (ipld.Node, error)

func (PBLink) LookupSegment

func (n PBLink) LookupSegment(seg ipld.PathSegment) (ipld.Node, error)

func (PBLink) LookupString

func (x PBLink) LookupString(key string) (ipld.Node, error)

func (PBLink) MapIterator

func (x PBLink) MapIterator() ipld.MapIterator

func (PBLink) NodeBuilder

func (PBLink) NodeBuilder() ipld.NodeBuilder

func (PBLink) ReprKind

func (PBLink) ReprKind() ipld.ReprKind

func (PBLink) Representation

func (n PBLink) Representation() ipld.Node

func (PBLink) Type

func (PBLink) Type() schema.Type
type PBLink__Content struct {
}
func (b PBLink__Content) Build() (PBLink, error)
func (b PBLink__Content) MustBuild() PBLink
type PBLinks struct {
	// contains filtered or unexported fields
}

func (PBLinks) AsBool

func (PBLinks) AsBool() (bool, error)

func (PBLinks) AsBytes

func (PBLinks) AsBytes() ([]byte, error)

func (PBLinks) AsFloat

func (PBLinks) AsFloat() (float64, error)

func (PBLinks) AsInt

func (PBLinks) AsInt() (int, error)
func (PBLinks) AsLink() (ipld.Link, error)

func (PBLinks) AsString

func (PBLinks) AsString() (string, error)
func (x PBLinks) FieldLinks() PBLinks

func (PBLinks) IsNull

func (PBLinks) IsNull() bool

func (PBLinks) IsUndefined

func (PBLinks) IsUndefined() bool

func (PBLinks) Length

func (x PBLinks) Length() int

func (PBLinks) ListIterator

func (x PBLinks) ListIterator() ipld.ListIterator

func (PBLinks) Lookup

func (x PBLinks) Lookup(key ipld.Node) (ipld.Node, error)

func (PBLinks) LookupIndex

func (x PBLinks) LookupIndex(index int) (ipld.Node, error)

func (PBLinks) LookupSegment

func (n PBLinks) LookupSegment(seg ipld.PathSegment) (ipld.Node, error)

func (PBLinks) LookupString

func (PBLinks) LookupString(string) (ipld.Node, error)

func (PBLinks) MapIterator

func (PBLinks) MapIterator() ipld.MapIterator

func (PBLinks) NodeBuilder

func (PBLinks) NodeBuilder() ipld.NodeBuilder

func (PBLinks) ReprKind

func (PBLinks) ReprKind() ipld.ReprKind

func (PBLinks) Representation

func (n PBLinks) Representation() ipld.Node

func (PBLinks) Type

func (PBLinks) Type() schema.Type

type PBNode

type PBNode struct {
	Links PBLinks
	Data  Bytes
}

func (PBNode) AsBool

func (PBNode) AsBool() (bool, error)

func (PBNode) AsBytes

func (PBNode) AsBytes() ([]byte, error)

func (PBNode) AsFloat

func (PBNode) AsFloat() (float64, error)

func (PBNode) AsInt

func (PBNode) AsInt() (int, error)
func (PBNode) AsLink() (ipld.Link, error)

func (PBNode) AsString

func (PBNode) AsString() (string, error)

func (PBNode) EncodeDagProto

func (nd PBNode) EncodeDagProto(w io.Writer) error

EncodeDagProto is a fast path encoding to protobuf for PBNode types

func (PBNode) IsNull

func (PBNode) IsNull() bool

func (PBNode) IsUndefined

func (PBNode) IsUndefined() bool

func (PBNode) Length

func (PBNode) Length() int

func (PBNode) ListIterator

func (PBNode) ListIterator() ipld.ListIterator

func (PBNode) Lookup

func (x PBNode) Lookup(key ipld.Node) (ipld.Node, error)

func (PBNode) LookupIndex

func (PBNode) LookupIndex(idx int) (ipld.Node, error)

func (PBNode) LookupSegment

func (n PBNode) LookupSegment(seg ipld.PathSegment) (ipld.Node, error)

func (PBNode) LookupString

func (x PBNode) LookupString(key string) (ipld.Node, error)

func (PBNode) MapIterator

func (x PBNode) MapIterator() ipld.MapIterator

func (PBNode) NodeBuilder

func (PBNode) NodeBuilder() ipld.NodeBuilder

func (PBNode) ReprKind

func (PBNode) ReprKind() ipld.ReprKind

func (PBNode) Representation

func (n PBNode) Representation() ipld.Node

func (PBNode) Type

func (PBNode) Type() schema.Type

type PBNode__Content

type PBNode__Content struct {
}

func (PBNode__Content) Build

func (b PBNode__Content) Build() (PBNode, error)

func (PBNode__Content) MustBuild

func (b PBNode__Content) MustBuild() PBNode

type RawNode

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

func (RawNode) AsBool

func (RawNode) AsBool() (bool, error)

func (RawNode) AsBytes

func (x RawNode) AsBytes() ([]byte, error)

func (RawNode) AsFloat

func (RawNode) AsFloat() (float64, error)

func (RawNode) AsInt

func (RawNode) AsInt() (int, error)
func (RawNode) AsLink() (ipld.Link, error)

func (RawNode) AsString

func (RawNode) AsString() (string, error)

func (RawNode) EncodeDagRaw

func (nd RawNode) EncodeDagRaw(w io.Writer) error

EncodeDagRaw is a fast path encoding to protobuf for RawNode types

func (RawNode) IsNull

func (RawNode) IsNull() bool

func (RawNode) IsUndefined

func (RawNode) IsUndefined() bool

func (RawNode) Length

func (RawNode) Length() int

func (RawNode) ListIterator

func (RawNode) ListIterator() ipld.ListIterator

func (RawNode) Lookup

func (RawNode) Lookup(ipld.Node) (ipld.Node, error)

func (RawNode) LookupIndex

func (RawNode) LookupIndex(idx int) (ipld.Node, error)

func (RawNode) LookupSegment

func (RawNode) LookupSegment(seg ipld.PathSegment) (ipld.Node, error)

func (RawNode) LookupString

func (RawNode) LookupString(string) (ipld.Node, error)

func (RawNode) MapIterator

func (RawNode) MapIterator() ipld.MapIterator

func (RawNode) NodeBuilder

func (RawNode) NodeBuilder() ipld.NodeBuilder

func (RawNode) ReprKind

func (RawNode) ReprKind() ipld.ReprKind

func (RawNode) Representation

func (RawNode) Representation() ipld.Node

func (RawNode) Type

func (RawNode) Type() schema.Type

type String

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

func (String) AsBool

func (String) AsBool() (bool, error)

func (String) AsBytes

func (String) AsBytes() ([]byte, error)

func (String) AsFloat

func (String) AsFloat() (float64, error)

func (String) AsInt

func (String) AsInt() (int, error)
func (String) AsLink() (ipld.Link, error)

func (String) AsString

func (x String) AsString() (string, error)

func (String) FieldName

func (x String) FieldName() String

func (String) IsNull

func (String) IsNull() bool

func (String) IsUndefined

func (String) IsUndefined() bool

func (String) Length

func (String) Length() int

func (String) ListIterator

func (String) ListIterator() ipld.ListIterator

func (String) Lookup

func (String) Lookup(ipld.Node) (ipld.Node, error)

func (String) LookupIndex

func (String) LookupIndex(idx int) (ipld.Node, error)

func (String) LookupSegment

func (String) LookupSegment(seg ipld.PathSegment) (ipld.Node, error)

func (String) LookupString

func (String) LookupString(string) (ipld.Node, error)

func (String) MapIterator

func (String) MapIterator() ipld.MapIterator

func (String) NodeBuilder

func (String) NodeBuilder() ipld.NodeBuilder

func (String) ReprKind

func (String) ReprKind() ipld.ReprKind

func (String) Representation

func (String) Representation() ipld.Node

func (String) String

func (x String) String() string

func (String) Type

func (String) Type() schema.Type

type String__Content

type String__Content struct {
	Value string
}

func (String__Content) Build

func (b String__Content) Build() (String, error)

func (String__Content) MustBuild

func (b String__Content) MustBuild() String

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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