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 ¶
- Variables
- func AddSupportToChooser(existing traversal.LinkTargetNodePrototypeChooser) traversal.LinkTargetNodePrototypeChooser
- func AppendEncode(enc []byte, inNode ld.Node) ([]byte, error)
- func Decode(na ld.NodeAssembler, in io.Reader) error
- func DecodeBytes(na ld.NodeAssembler, src []byte) error
- func Decoder(na ld.NodeAssembler, r io.Reader) errordeprecated
- func Encode(node ld.Node, w io.Writer) error
- func Encoder(inNode ld.Node, w io.Writer) errordeprecated
- func Marshal(inNode ld.Node, w io.Writer) errordeprecated
- func Unmarshal(na ld.NodeAssembler, r io.Reader) errordeprecated
- type Bytes
- func (Bytes) AsBool() (bool, error)
- func (n Bytes) AsBytes() ([]byte, error)
- func (Bytes) AsFloat() (float64, error)
- func (Bytes) AsInt() (int64, error)
- func (Bytes) AsLink() (ld.Link, error)
- func (Bytes) AsString() (string, error)
- func (n Bytes) Bytes() []byte
- func (Bytes) IsAbsent() bool
- func (Bytes) IsNull() bool
- func (Bytes) Kind() ld.Kind
- func (Bytes) Length() int64
- func (Bytes) ListIterator() ld.ListIterator
- func (Bytes) LookupByIndex(idx int64) (ld.Node, error)
- func (Bytes) LookupByNode(ld.Node) (ld.Node, error)
- func (Bytes) LookupBySegment(seg ld.PathSegment) (ld.Node, error)
- func (Bytes) LookupByString(string) (ld.Node, error)
- func (Bytes) MapIterator() ld.MapIterator
- func (Bytes) Prototype() ld.NodePrototype
- func (n Bytes) Representation() ld.Node
- func (Bytes) Type() schema.Type
- type Int
- func (Int) AsBool() (bool, error)
- func (Int) AsBytes() ([]byte, error)
- func (Int) AsFloat() (float64, error)
- func (n Int) AsInt() (int64, error)
- func (Int) AsLink() (ld.Link, error)
- func (Int) AsString() (string, error)
- func (n Int) Int() int64
- func (Int) IsAbsent() bool
- func (Int) IsNull() bool
- func (Int) Kind() ld.Kind
- func (Int) Length() int64
- func (Int) ListIterator() ld.ListIterator
- func (Int) LookupByIndex(idx int64) (ld.Node, error)
- func (Int) LookupByNode(ld.Node) (ld.Node, error)
- func (Int) LookupBySegment(seg ld.PathSegment) (ld.Node, error)
- func (Int) LookupByString(string) (ld.Node, error)
- func (Int) MapIterator() ld.MapIterator
- func (Int) Prototype() ld.NodePrototype
- func (n Int) Representation() ld.Node
- func (Int) Type() schema.Type
- type Link
- func (Link) AsBool() (bool, error)
- func (Link) AsBytes() ([]byte, error)
- func (Link) AsFloat() (float64, error)
- func (Link) AsInt() (int64, error)
- func (n Link) AsLink() (ld.Link, error)
- func (Link) AsString() (string, error)
- func (Link) IsAbsent() bool
- func (Link) IsNull() bool
- func (Link) Kind() ld.Kind
- func (Link) Length() int64
- func (n Link) Link() ld.Link
- func (Link) ListIterator() ld.ListIterator
- func (Link) LookupByIndex(idx int64) (ld.Node, error)
- func (Link) LookupByNode(ld.Node) (ld.Node, error)
- func (Link) LookupBySegment(seg ld.PathSegment) (ld.Node, error)
- func (Link) LookupByString(string) (ld.Node, error)
- func (Link) MapIterator() ld.MapIterator
- func (Link) Prototype() ld.NodePrototype
- func (n Link) Representation() ld.Node
- func (Link) Type() schema.Type
- type MaybeBytes
- type MaybeInt
- type MaybeLink
- type MaybePBLink
- type MaybePBLinks
- type MaybePBNode
- type MaybeString
- type PBLink
- func (PBLink) AsBool() (bool, error)
- func (PBLink) AsBytes() ([]byte, error)
- func (PBLink) AsFloat() (float64, error)
- func (PBLink) AsInt() (int64, error)
- func (PBLink) AsLink() (ld.Link, error)
- func (PBLink) AsString() (string, error)
- func (PBLink) IsAbsent() bool
- func (PBLink) IsNull() bool
- func (PBLink) Kind() ld.Kind
- func (PBLink) Length() int64
- func (PBLink) ListIterator() ld.ListIterator
- func (PBLink) LookupByIndex(idx int64) (ld.Node, error)
- func (n PBLink) LookupByNode(key ld.Node) (ld.Node, error)
- func (n PBLink) LookupBySegment(seg ld.PathSegment) (ld.Node, error)
- func (n PBLink) LookupByString(key string) (ld.Node, error)
- func (n PBLink) MapIterator() ld.MapIterator
- func (PBLink) Prototype() ld.NodePrototype
- func (n PBLink) Representation() ld.Node
- func (PBLink) Type() schema.Type
- type PBLinks
- func (PBLinks) AsBool() (bool, error)
- func (PBLinks) AsBytes() ([]byte, error)
- func (PBLinks) AsFloat() (float64, error)
- func (PBLinks) AsInt() (int64, error)
- func (PBLinks) AsLink() (ld.Link, error)
- func (PBLinks) AsString() (string, error)
- func (PBLinks) IsAbsent() bool
- func (PBLinks) IsNull() bool
- func (n PBLinks) Iterator() *PBLinks__Itr
- func (PBLinks) Kind() ld.Kind
- func (n PBLinks) Length() int64
- func (n PBLinks) ListIterator() ld.ListIterator
- func (n PBLinks) LookupByIndex(idx int64) (ld.Node, error)
- func (n PBLinks) LookupByNode(k ld.Node) (ld.Node, error)
- func (n PBLinks) LookupBySegment(seg ld.PathSegment) (ld.Node, error)
- func (PBLinks) LookupByString(string) (ld.Node, error)
- func (PBLinks) MapIterator() ld.MapIterator
- func (PBLinks) Prototype() ld.NodePrototype
- func (n PBLinks) Representation() ld.Node
- func (PBLinks) Type() schema.Type
- type PBLinks__Itr
- type PBNode
- func (PBNode) AsBool() (bool, error)
- func (PBNode) AsBytes() ([]byte, error)
- func (PBNode) AsFloat() (float64, error)
- func (PBNode) AsInt() (int64, error)
- func (PBNode) AsLink() (ld.Link, error)
- func (PBNode) AsString() (string, error)
- func (PBNode) IsAbsent() bool
- func (PBNode) IsNull() bool
- func (PBNode) Kind() ld.Kind
- func (PBNode) Length() int64
- func (PBNode) ListIterator() ld.ListIterator
- func (PBNode) LookupByIndex(idx int64) (ld.Node, error)
- func (n PBNode) LookupByNode(key ld.Node) (ld.Node, error)
- func (n PBNode) LookupBySegment(seg ld.PathSegment) (ld.Node, error)
- func (n PBNode) LookupByString(key string) (ld.Node, error)
- func (n PBNode) MapIterator() ld.MapIterator
- func (PBNode) Prototype() ld.NodePrototype
- func (n PBNode) Representation() ld.Node
- func (PBNode) Type() schema.Type
- type String
- func (String) AsBool() (bool, error)
- func (String) AsBytes() ([]byte, error)
- func (String) AsFloat() (float64, error)
- func (String) AsInt() (int64, error)
- func (String) AsLink() (ld.Link, error)
- func (n String) AsString() (string, error)
- func (String) IsAbsent() bool
- func (String) IsNull() bool
- func (String) Kind() ld.Kind
- func (String) Length() int64
- func (String) ListIterator() ld.ListIterator
- func (String) LookupByIndex(idx int64) (ld.Node, error)
- func (String) LookupByNode(ld.Node) (ld.Node, error)
- func (String) LookupBySegment(seg ld.PathSegment) (ld.Node, error)
- func (String) LookupByString(string) (ld.Node, error)
- func (String) MapIterator() ld.MapIterator
- func (String) Prototype() ld.NodePrototype
- func (n String) Representation() ld.Node
- func (n String) String() string
- func (String) Type() schema.Type
Constants ¶
This section is empty.
Variables ¶
var ErrIntOverflow = fmt.Errorf("protobuf: varint overflow")
ErrIntOverflow is returned a varint overflows during decode, it indicates malformed data
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 ¶
func AddSupportToChooser(existing traversal.LinkTargetNodePrototypeChooser) traversal.LinkTargetNodePrototypeChooser
AddSupportToChooser takes an existing node prototype chooser and subs in PBNode for the dag-pb multicodec code.
func AppendEncode ¶
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 Encode ¶
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.
Types ¶
type Bytes ¶
type Bytes = *_Bytes
Bytes matches the LD Schema type "Bytes". It has bytes kind.
func (Bytes) ListIterator ¶
func (Bytes) ListIterator() ld.ListIterator
func (Bytes) LookupBySegment ¶
func (Bytes) MapIterator ¶
func (Bytes) MapIterator() ld.MapIterator
func (Bytes) Prototype ¶
func (Bytes) Prototype() ld.NodePrototype
func (Bytes) Representation ¶
type Int ¶
type Int = *_Int
Int matches the LD Schema type "Int". It has int kind.
func (Int) ListIterator ¶
func (Int) ListIterator() ld.ListIterator
func (Int) LookupBySegment ¶
func (Int) MapIterator ¶
func (Int) MapIterator() ld.MapIterator
func (Int) Prototype ¶
func (Int) Prototype() ld.NodePrototype
func (Int) Representation ¶
type Link ¶
type Link = *_Link
Link matches the LD Schema type "Link". It has link kind.
func (Link) ListIterator ¶
func (Link) ListIterator() ld.ListIterator
func (Link) LookupBySegment ¶
func (Link) MapIterator ¶
func (Link) MapIterator() ld.MapIterator
func (Link) Prototype ¶
func (Link) Prototype() ld.NodePrototype
func (Link) Representation ¶
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 MaybePBLink ¶
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 ¶
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 ¶
type PBLink = *_PBLink
PBLink matches the LD Schema type "PBLink". It has Struct type-kind, and may be interrogated like map kind.
func (PBLink) ListIterator ¶
func (PBLink) ListIterator() ld.ListIterator
func (PBLink) LookupBySegment ¶
func (PBLink) MapIterator ¶
func (n PBLink) MapIterator() ld.MapIterator
func (PBLink) Prototype ¶
func (PBLink) Prototype() ld.NodePrototype
func (PBLink) Representation ¶
type PBLinks ¶
type PBLinks = *_PBLinks
PBLinks matches the LD Schema type "PBLinks". It has list kind.
func (PBLinks) Iterator ¶
func (n PBLinks) Iterator() *PBLinks__Itr
func (PBLinks) ListIterator ¶
func (n PBLinks) ListIterator() ld.ListIterator
func (PBLinks) LookupBySegment ¶
func (PBLinks) MapIterator ¶
func (PBLinks) MapIterator() ld.MapIterator
func (PBLinks) Prototype ¶
func (PBLinks) Prototype() ld.NodePrototype
func (PBLinks) Representation ¶
type PBLinks__Itr ¶
type PBLinks__Itr struct {
// contains filtered or unexported fields
}
func (*PBLinks__Itr) Done ¶
func (itr *PBLinks__Itr) Done() bool
func (*PBLinks__Itr) Next ¶
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) ListIterator ¶
func (PBNode) ListIterator() ld.ListIterator
func (PBNode) LookupBySegment ¶
func (PBNode) MapIterator ¶
func (n PBNode) MapIterator() ld.MapIterator
func (PBNode) Prototype ¶
func (PBNode) Prototype() ld.NodePrototype
func (PBNode) Representation ¶
type String ¶
type String = *_String
String matches the LD Schema type "String". It has string kind.
func (String) ListIterator ¶
func (String) ListIterator() ld.ListIterator
func (String) LookupBySegment ¶
func (String) MapIterator ¶
func (String) MapIterator() ld.MapIterator
func (String) Prototype ¶
func (String) Prototype() ld.NodePrototype