dagpb

package module
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: Apache-2.0, MIT Imports: 11 Imported by: 91

README

go-dagpb

An implementation of the IPLD DAG-PB spec for go-ipld-prime

Use Decode(ipld.NodeAssembler, io.Reader) and Encode(ipld.Node, io.Writer) directly, or import this package to have this codec registered into the go-ipld-prime CID link loader.

Nodes encoded with this codec must conform to the DAG-PB spec. Specifically, they should have the non-optional fields shown in the DAG-PB schema:

type PBNode struct {
  Links [PBLink]
  Data optional Bytes
}

type PBLink struct {
  Hash Link
  Name optional String
  Tsize optional Int
}

Use dagpb.Type.PBNode and friends directly for strictness guarantees. Basic ipld.Nodes will need to have the appropraite fields (and no others) to successfully encode using this codec.

Copyright © 2020 Protocol Labs

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Documentation

Overview

Package dagpb provides an implementation of the IPLD DAG-PB spec (https://github.com/ipld/specs/blob/master/block-layer/codecs/dag-pb.md) for go-ipld-prime (https://github.com/ipld/go-ipld-prime/).

Use Decode() and Encode() directly, or import this package to have this codec registered into the go-ipld-prime multicodec registry and available from the cidlink.DefaultLinkSystem.

Nodes encoded with this codec _must_ conform to the DAG-PB spec. Specifically, they should have the non-optional fields shown in the DAG-PB schema:

type PBNode struct {
	Links [PBLink]
	Data optional Bytes
}

type PBLink struct {
	Hash Link
	Name optional String
	Tsize optional Int
}

Use dagpb.Type.PBNode and friends directly for strictness guarantees. Basic ipld.Node's will need to have the appropriate fields (and no others) to successfully encode using this codec.

Index

Constants

This section is empty.

Variables

View Source
var ErrIntOverflow = fmt.Errorf("protobuf: varint overflow")

ErrIntOverflow is returned a varint overflows during decode, it indicates malformed data

View Source
var Type typeSlab

Type is a struct embeding a NodePrototype/Type for every Node implementation in this package. One of its major uses is to start the construction of a value. You can use it like this:

dagpb.Type.YourTypeName.NewBuilder().BeginMap() //...

and:

dagpb.Type.OtherTypeName.NewBuilder().AssignString("x") // ...

Functions

func AddSupportToChooser added in v1.2.0

AddSupportToChooser takes an existing node prototype chooser and subs in PBNode for the dag-pb multicodec code.

func AppendEncode added in v1.3.0

func AppendEncode(enc []byte, inNode ipld.Node) ([]byte, error)

AppendEncode is like Encode, but it uses a destination buffer directly. This means less copying of bytes, and if the destination has enough capacity, fewer allocations.

func Decode added in v1.1.0

func Decode(na ipld.NodeAssembler, in io.Reader) error

Decode provides an IPLD codec decode interface for DAG-PB data. Provide a compatible NodeAssembler and a byte source to unmarshal a DAG-PB IPLD Node. Use the NodeAssembler from the PBNode type for safest construction (Type.PBNode.NewBuilder()). A Map assembler will also work. This function is registered via the go-ipld-prime link loader for multicodec code 0x70 when this package is invoked via init.

func DecodeBytes added in v1.3.0

func DecodeBytes(na ipld.NodeAssembler, src []byte) error

DecodeBytes is like Decode, but it uses an input buffer directly. Decode will grab or read all the bytes from an io.Reader anyway, so this can save having to copy the bytes or create a bytes.Buffer.

func Decoder deprecated

func Decoder(na ipld.NodeAssembler, r io.Reader) error

Deprecated: use Decode instead.

func Encode added in v1.1.0

func Encode(node ipld.Node, w io.Writer) error

Encode provides an IPLD codec encode interface for DAG-PB data. Provide a conforming Node and a destination for bytes to marshal a DAG-PB IPLD Node. The Node must strictly conform to the DAG-PB schema (https://github.com/ipld/specs/blob/master/block-layer/codecs/dag-pb.md). For safest use, build Nodes using the Type.PBNode type. This function is registered via the go-ipld-prime link loader for multicodec code 0x70 when this package is invoked via init.

func Encoder deprecated

func Encoder(inNode ipld.Node, w io.Writer) error

Deprecated: use Encode instead.

func Marshal deprecated

func Marshal(inNode ipld.Node, w io.Writer) error

Deprecated: use Encode instead.

func Unmarshal deprecated

func Unmarshal(na ipld.NodeAssembler, r io.Reader) error

Deprecated: use Decode instead.

Types

type Bytes

type Bytes = *_Bytes

Bytes matches the IPLD Schema type "Bytes". It has bytes kind.

func (Bytes) AsBool

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

func (Bytes) AsBytes

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

func (Bytes) AsFloat

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

func (Bytes) AsInt

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

func (Bytes) AsString

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

func (Bytes) Bytes

func (n Bytes) Bytes() []byte

func (Bytes) IsAbsent

func (Bytes) IsAbsent() bool

func (Bytes) IsNull

func (Bytes) IsNull() bool

func (Bytes) Kind

func (Bytes) Kind() ipld.Kind

func (Bytes) Length

func (Bytes) Length() int64

func (Bytes) ListIterator

func (Bytes) ListIterator() ipld.ListIterator

func (Bytes) LookupByIndex

func (Bytes) LookupByIndex(idx int64) (ipld.Node, error)

func (Bytes) LookupByNode

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

func (Bytes) LookupBySegment

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

func (Bytes) LookupByString

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

func (Bytes) MapIterator

func (Bytes) MapIterator() ipld.MapIterator

func (Bytes) Prototype

func (Bytes) Prototype() ipld.NodePrototype

func (Bytes) Representation

func (n Bytes) Representation() ipld.Node

func (Bytes) Type

func (Bytes) Type() schema.Type

type Int

type Int = *_Int

Int matches the IPLD Schema type "Int". It has int kind.

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 (n Int) AsInt() (int64, error)
func (Int) AsLink() (ipld.Link, error)

func (Int) AsString

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

func (Int) Int

func (n Int) Int() int64

func (Int) IsAbsent

func (Int) IsAbsent() bool

func (Int) IsNull

func (Int) IsNull() bool

func (Int) Kind

func (Int) Kind() ipld.Kind

func (Int) Length

func (Int) Length() int64

func (Int) ListIterator

func (Int) ListIterator() ipld.ListIterator

func (Int) LookupByIndex

func (Int) LookupByIndex(idx int64) (ipld.Node, error)

func (Int) LookupByNode

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

func (Int) LookupBySegment

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

func (Int) LookupByString

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

func (Int) MapIterator

func (Int) MapIterator() ipld.MapIterator

func (Int) Prototype

func (Int) Prototype() ipld.NodePrototype

func (Int) Representation

func (n Int) Representation() ipld.Node

func (Int) Type

func (Int) Type() schema.Type
type Link = *_Link

Link matches the IPLD Schema type "Link". It has link kind.

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() (int64, error)
func (n Link) AsLink() (ipld.Link, error)

func (Link) AsString

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

func (Link) IsAbsent

func (Link) IsAbsent() bool

func (Link) IsNull

func (Link) IsNull() bool

func (Link) Kind

func (Link) Kind() ipld.Kind

func (Link) Length

func (Link) Length() int64
func (n Link) Link() ipld.Link

func (Link) ListIterator

func (Link) ListIterator() ipld.ListIterator

func (Link) LookupByIndex

func (Link) LookupByIndex(idx int64) (ipld.Node, error)

func (Link) LookupByNode

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

func (Link) LookupBySegment

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

func (Link) LookupByString

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

func (Link) MapIterator

func (Link) MapIterator() ipld.MapIterator

func (Link) Prototype

func (Link) Prototype() ipld.NodePrototype

func (Link) Representation

func (n Link) Representation() ipld.Node

func (Link) Type

func (Link) Type() schema.Type

type MaybeBytes

type MaybeBytes = *_Bytes__Maybe

func (MaybeBytes) AsNode

func (m MaybeBytes) AsNode() ipld.Node

func (MaybeBytes) Exists

func (m MaybeBytes) Exists() bool

func (MaybeBytes) IsAbsent

func (m MaybeBytes) IsAbsent() bool

func (MaybeBytes) IsNull

func (m MaybeBytes) IsNull() bool

func (MaybeBytes) Must

func (m MaybeBytes) Must() Bytes

type MaybeInt

type MaybeInt = *_Int__Maybe

func (MaybeInt) AsNode

func (m MaybeInt) AsNode() ipld.Node

func (MaybeInt) Exists

func (m MaybeInt) Exists() bool

func (MaybeInt) IsAbsent

func (m MaybeInt) IsAbsent() bool

func (MaybeInt) IsNull

func (m MaybeInt) IsNull() bool

func (MaybeInt) Must

func (m MaybeInt) Must() Int
type MaybeLink = *_Link__Maybe

func (MaybeLink) AsNode

func (m MaybeLink) AsNode() ipld.Node

func (MaybeLink) Exists

func (m MaybeLink) Exists() bool

func (MaybeLink) IsAbsent

func (m MaybeLink) IsAbsent() bool

func (MaybeLink) IsNull

func (m MaybeLink) IsNull() bool

func (MaybeLink) Must

func (m MaybeLink) Must() Link
type MaybePBLink = *_PBLink__Maybe

func (MaybePBLink) AsNode

func (m MaybePBLink) AsNode() ipld.Node

func (MaybePBLink) Exists

func (m MaybePBLink) Exists() bool

func (MaybePBLink) IsAbsent

func (m MaybePBLink) IsAbsent() bool

func (MaybePBLink) IsNull

func (m MaybePBLink) IsNull() bool

func (MaybePBLink) Must

func (m MaybePBLink) Must() PBLink
type MaybePBLinks = *_PBLinks__Maybe

func (MaybePBLinks) AsNode

func (m MaybePBLinks) AsNode() ipld.Node

func (MaybePBLinks) Exists

func (m MaybePBLinks) Exists() bool

func (MaybePBLinks) IsAbsent

func (m MaybePBLinks) IsAbsent() bool

func (MaybePBLinks) IsNull

func (m MaybePBLinks) IsNull() bool

func (MaybePBLinks) Must

func (m MaybePBLinks) Must() PBLinks

type MaybePBNode

type MaybePBNode = *_PBNode__Maybe

func (MaybePBNode) AsNode

func (m MaybePBNode) AsNode() ipld.Node

func (MaybePBNode) Exists

func (m MaybePBNode) Exists() bool

func (MaybePBNode) IsAbsent

func (m MaybePBNode) IsAbsent() bool

func (MaybePBNode) IsNull

func (m MaybePBNode) IsNull() bool

func (MaybePBNode) Must

func (m MaybePBNode) Must() PBNode

type MaybeString

type MaybeString = *_String__Maybe

func (MaybeString) AsNode

func (m MaybeString) AsNode() ipld.Node

func (MaybeString) Exists

func (m MaybeString) Exists() bool

func (MaybeString) IsAbsent

func (m MaybeString) IsAbsent() bool

func (MaybeString) IsNull

func (m MaybeString) IsNull() bool

func (MaybeString) Must

func (m MaybeString) Must() String
type PBLink = *_PBLink

PBLink matches the IPLD Schema type "PBLink". It has Struct type-kind, and may be interrogated like map kind.

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() (int64, error)
func (PBLink) AsLink() (ipld.Link, error)

func (PBLink) AsString

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

func (PBLink) IsAbsent

func (PBLink) IsAbsent() bool

func (PBLink) IsNull

func (PBLink) IsNull() bool

func (PBLink) Kind

func (PBLink) Kind() ipld.Kind

func (PBLink) Length

func (PBLink) Length() int64

func (PBLink) ListIterator

func (PBLink) ListIterator() ipld.ListIterator

func (PBLink) LookupByIndex

func (PBLink) LookupByIndex(idx int64) (ipld.Node, error)

func (PBLink) LookupByNode

func (n PBLink) LookupByNode(key ipld.Node) (ipld.Node, error)

func (PBLink) LookupBySegment

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

func (PBLink) LookupByString

func (n PBLink) LookupByString(key string) (ipld.Node, error)

func (PBLink) MapIterator

func (n PBLink) MapIterator() ipld.MapIterator

func (PBLink) Prototype

func (PBLink) Prototype() ipld.NodePrototype

func (PBLink) Representation

func (n PBLink) Representation() ipld.Node

func (PBLink) Type

func (PBLink) Type() schema.Type
type PBLinks = *_PBLinks

PBLinks matches the IPLD Schema type "PBLinks". It has list kind.

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() (int64, error)
func (PBLinks) AsLink() (ipld.Link, error)

func (PBLinks) AsString

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

func (PBLinks) IsAbsent

func (PBLinks) IsAbsent() bool

func (PBLinks) IsNull

func (PBLinks) IsNull() bool

func (PBLinks) Iterator

func (n PBLinks) Iterator() *PBLinks__Itr

func (PBLinks) Kind

func (PBLinks) Kind() ipld.Kind

func (PBLinks) Length

func (n PBLinks) Length() int64

func (PBLinks) ListIterator

func (n PBLinks) ListIterator() ipld.ListIterator

func (PBLinks) LookupByIndex

func (n PBLinks) LookupByIndex(idx int64) (ipld.Node, error)

func (PBLinks) LookupByNode

func (n PBLinks) LookupByNode(k ipld.Node) (ipld.Node, error)

func (PBLinks) LookupBySegment

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

func (PBLinks) LookupByString

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

func (PBLinks) MapIterator

func (PBLinks) MapIterator() ipld.MapIterator

func (PBLinks) Prototype

func (PBLinks) Prototype() ipld.NodePrototype

func (PBLinks) Representation

func (n PBLinks) Representation() ipld.Node

func (PBLinks) Type

func (PBLinks) Type() schema.Type
type PBLinks__Itr struct {
	// contains filtered or unexported fields
}
func (itr *PBLinks__Itr) Done() bool
func (itr *PBLinks__Itr) Next() (idx int64, v PBLink)

type PBNode

type PBNode = *_PBNode

PBNode matches the IPLD Schema type "PBNode". It has Struct type-kind, and may be interrogated like map kind.

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() (int64, error)
func (PBNode) AsLink() (ipld.Link, error)

func (PBNode) AsString

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

func (PBNode) IsAbsent

func (PBNode) IsAbsent() bool

func (PBNode) IsNull

func (PBNode) IsNull() bool

func (PBNode) Kind

func (PBNode) Kind() ipld.Kind

func (PBNode) Length

func (PBNode) Length() int64

func (PBNode) ListIterator

func (PBNode) ListIterator() ipld.ListIterator

func (PBNode) LookupByIndex

func (PBNode) LookupByIndex(idx int64) (ipld.Node, error)

func (PBNode) LookupByNode

func (n PBNode) LookupByNode(key ipld.Node) (ipld.Node, error)

func (PBNode) LookupBySegment

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

func (PBNode) LookupByString

func (n PBNode) LookupByString(key string) (ipld.Node, error)

func (PBNode) MapIterator

func (n PBNode) MapIterator() ipld.MapIterator

func (PBNode) Prototype

func (PBNode) Prototype() ipld.NodePrototype

func (PBNode) Representation

func (n PBNode) Representation() ipld.Node

func (PBNode) Type

func (PBNode) Type() schema.Type

type String

type String = *_String

String matches the IPLD Schema type "String". It has string kind.

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() (int64, error)
func (String) AsLink() (ipld.Link, error)

func (String) AsString

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

func (String) IsAbsent

func (String) IsAbsent() bool

func (String) IsNull

func (String) IsNull() bool

func (String) Kind

func (String) Kind() ipld.Kind

func (String) Length

func (String) Length() int64

func (String) ListIterator

func (String) ListIterator() ipld.ListIterator

func (String) LookupByIndex

func (String) LookupByIndex(idx int64) (ipld.Node, error)

func (String) LookupByNode

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

func (String) LookupBySegment

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

func (String) LookupByString

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

func (String) MapIterator

func (String) MapIterator() ipld.MapIterator

func (String) Prototype

func (String) Prototype() ipld.NodePrototype

func (String) Representation

func (n String) Representation() ipld.Node

func (String) String

func (n String) String() string

func (String) Type

func (String) Type() schema.Type

Jump to

Keyboard shortcuts

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