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 29, 2021 License: Apache-2.0, MIT Imports: 12 Imported by: 2

README

go-dagpb

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

Use Decode(ld.NodeAssembler, io.Reader) and Encode(ld.Node, io.Writer) directly, or import this package to have this codec registered into the go-ld-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 ld.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 LD DAG-PB spec (https://gitlab.dms3.io/ld/specs/blob/master/block-layer/codecs/dag-pb.md) for go-ld-prime (https://gitlab.dms3.io/ld/go-ld-prime/).

Use Decode() and Encode() directly, or import this package to have this codec registered into the go-ld-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 ld.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

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

func AppendEncode

func AppendEncode(enc []byte, inNode ld.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

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

Decode provides an LD codec decode interface for DAG-PB data. Provide a compatible NodeAssembler and a byte source to unmarshal a DAG-PB LD 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-ld-prime link loader for multicodec code 0x70 when this package is invoked via init.

func DecodeBytes

func DecodeBytes(na ld.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 ld.NodeAssembler, r io.Reader) error

Deprecated: use Decode instead.

func Encode

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

Encode provides an LD codec encode interface for DAG-PB data. Provide a conforming Node and a destination for bytes to marshal a DAG-PB LD Node. The Node must strictly conform to the DAG-PB schema (https://gitlab.dms3.io/ld/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-ld-prime link loader for multicodec code 0x70 when this package is invoked via init.

func Encoder deprecated

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

Deprecated: use Encode instead.

func Marshal deprecated

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

Deprecated: use Encode instead.

func Unmarshal deprecated

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

Deprecated: use Decode instead.

Types

type Bytes

type Bytes = *_Bytes

Bytes matches the LD 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() (ld.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() ld.Kind

func (Bytes) Length

func (Bytes) Length() int64

func (Bytes) ListIterator

func (Bytes) ListIterator() ld.ListIterator

func (Bytes) LookupByIndex

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

func (Bytes) LookupByNode

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

func (Bytes) LookupBySegment

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

func (Bytes) LookupByString

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

func (Bytes) MapIterator

func (Bytes) MapIterator() ld.MapIterator

func (Bytes) Prototype

func (Bytes) Prototype() ld.NodePrototype

func (Bytes) Representation

func (n Bytes) Representation() ld.Node

func (Bytes) Type

func (Bytes) Type() schema.Type

type Int

type Int = *_Int

Int matches the LD 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() (ld.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() ld.Kind

func (Int) Length

func (Int) Length() int64

func (Int) ListIterator

func (Int) ListIterator() ld.ListIterator

func (Int) LookupByIndex

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

func (Int) LookupByNode

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

func (Int) LookupBySegment

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

func (Int) LookupByString

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

func (Int) MapIterator

func (Int) MapIterator() ld.MapIterator

func (Int) Prototype

func (Int) Prototype() ld.NodePrototype

func (Int) Representation

func (n Int) Representation() ld.Node

func (Int) Type

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

Link matches the LD 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() (ld.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() ld.Kind

func (Link) Length

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

func (Link) ListIterator

func (Link) ListIterator() ld.ListIterator

func (Link) LookupByIndex

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

func (Link) LookupByNode

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

func (Link) LookupBySegment

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

func (Link) LookupByString

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

func (Link) MapIterator

func (Link) MapIterator() ld.MapIterator

func (Link) Prototype

func (Link) Prototype() ld.NodePrototype

func (Link) Representation

func (n Link) Representation() ld.Node

func (Link) Type

func (Link) Type() schema.Type

type MaybeBytes

type MaybeBytes = *_Bytes__Maybe

func (MaybeBytes) AsNode

func (m MaybeBytes) AsNode() ld.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() ld.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() ld.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() ld.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() ld.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() ld.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() ld.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 LD 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() (ld.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() ld.Kind

func (PBLink) Length

func (PBLink) Length() int64

func (PBLink) ListIterator

func (PBLink) ListIterator() ld.ListIterator

func (PBLink) LookupByIndex

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

func (PBLink) LookupByNode

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

func (PBLink) LookupBySegment

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

func (PBLink) LookupByString

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

func (PBLink) MapIterator

func (n PBLink) MapIterator() ld.MapIterator

func (PBLink) Prototype

func (PBLink) Prototype() ld.NodePrototype

func (PBLink) Representation

func (n PBLink) Representation() ld.Node

func (PBLink) Type

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

PBLinks matches the LD 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() (ld.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() ld.Kind

func (PBLinks) Length

func (n PBLinks) Length() int64

func (PBLinks) ListIterator

func (n PBLinks) ListIterator() ld.ListIterator

func (PBLinks) LookupByIndex

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

func (PBLinks) LookupByNode

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

func (PBLinks) LookupBySegment

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

func (PBLinks) LookupByString

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

func (PBLinks) MapIterator

func (PBLinks) MapIterator() ld.MapIterator

func (PBLinks) Prototype

func (PBLinks) Prototype() ld.NodePrototype

func (PBLinks) Representation

func (n PBLinks) Representation() ld.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 LD 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() (ld.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() ld.Kind

func (PBNode) Length

func (PBNode) Length() int64

func (PBNode) ListIterator

func (PBNode) ListIterator() ld.ListIterator

func (PBNode) LookupByIndex

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

func (PBNode) LookupByNode

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

func (PBNode) LookupBySegment

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

func (PBNode) LookupByString

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

func (PBNode) MapIterator

func (n PBNode) MapIterator() ld.MapIterator

func (PBNode) Prototype

func (PBNode) Prototype() ld.NodePrototype

func (PBNode) Representation

func (n PBNode) Representation() ld.Node

func (PBNode) Type

func (PBNode) Type() schema.Type

type String

type String = *_String

String matches the LD 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() (ld.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() ld.Kind

func (String) Length

func (String) Length() int64

func (String) ListIterator

func (String) ListIterator() ld.ListIterator

func (String) LookupByIndex

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

func (String) LookupByNode

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

func (String) LookupBySegment

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

func (String) LookupByString

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

func (String) MapIterator

func (String) MapIterator() ld.MapIterator

func (String) Prototype

func (String) Prototype() ld.NodePrototype

func (String) Representation

func (n String) Representation() ld.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