Documentation
¶
Overview ¶
go-ipld-prime is a series of go interfaces for manipulating IPLD data.
See https://ipld.io/ for more information about the basics of "What is IPLD?".
Here in the godoc, the first couple of types to look at should be:
- Node
- NodeBuilder and NodeAssembler
- NodePrototype.
These types provide a generic description of the data model.
A Node is a piece of IPLD data which can be inspected. A NodeAssembler is used to create Nodes. (A NodeBuilder is just like a NodeAssembler, but allocates memory (whereas a NodeAssembler just fills up memory; using these carefully allows construction of very efficient code.)
Different NodePrototypes can be used to describe Nodes which follow certain logical rules (e.g., we use these as part of implementing Schemas), and can also be used so that programs can use different memory layouts for different data (which can be useful for constructing efficient programs when data has known shape for which we can use specific or compacted memory layouts).
If working with linked data (data which is split into multiple trees of Nodes, loaded separately, and connected by some kind of "link" reference), the next types you should look at are:
- LinkSystem
- ... and its fields.
The most typical use of LinkSystem is to use the linking/cid package to get a LinkSystem that works with CIDs:
lsys := cidlink.DefaultLinkSystem()
... and then assign the StorageWriteOpener and StorageReadOpener fields in order to control where data is stored to and read from. Methods on the LinkSystem then provide the functions typically used to get data in and out of Nodes so you can work with it.
This root package gathers some of the most important ease-of-use functions all in one place, but is mostly aliases out to features originally found in other more specific sub-packages. (If you're interested in keeping your binary sizes small, and don't use some of the features of this library, you'll probably want to look into using the relevant sub-packages directly.)
Particularly interesting subpackages include:
- datamodel -- the most essential interfaces for describing data live here, describing Node, NodePrototype, NodeBuilder, Link, and Path.
- node/* -- various Node + NodeBuilder implementations.
- node/basicnode -- the first Node implementation you should try.
- codec/* -- functions for serializing and deserializing Nodes.
- linking -- the LinkSystem, which is a facade to all data loading and storing and hashing.
- linking/* -- ways to bind concrete Link implementations (namely, the linking/cidlink package, which connects the go-cid library to our datamodel.Link interface).
- traversal -- functions for walking Node graphs (including automatic link loading) and visiting them programmatically.
- traversal/selector -- functions for working with IPLD Selectors, which are a language-agnostic declarative format for describing graph walks.
- fluent/* -- various options for making datamodel Node and NodeBuilder easier to work with.
- schema -- interfaces for working with IPLD Schemas, which can bring constraints and validation systems to otherwise schemaless and unstructured IPLD data.
- adl/* -- examples of creating and using Advanced Data Layouts (in short, custom Node implementations) to do complex data structures transparently within the IPLD Data Model.
Example (CreateDataAndMarshal) ¶
Example_createDataAndMarshal shows how you can feed data into a NodeBuilder, and also how to then hand that to an Encoder.
Often you'll encoding implicitly through a LinkSystem.Store call instead, but you can do it directly, too.
package main
import (
"os"
"github.com/ipld/go-ipld-prime/codec/dagjson"
"github.com/ipld/go-ipld-prime/node/basicnode"
)
func main() {
np := basicnode.Prototype.Any // Pick a prototype: this is how we decide what implementation will store the in-memory data.
nb := np.NewBuilder() // Create a builder.
ma, _ := nb.BeginMap(2) // Begin assembling a map.
ma.AssembleKey().AssignString("hey")
ma.AssembleValue().AssignString("it works!")
ma.AssembleKey().AssignString("yes")
ma.AssembleValue().AssignBool(true)
ma.Finish() // Call 'Finish' on the map assembly to let it know no more data is coming.
n := nb.Build() // Call 'Build' to get the resulting Node. (It's immutable!)
dagjson.Encode(n, os.Stdout)
}
Output: {"hey":"it works!","yes":true}
Example (UnmarshalData) ¶
Example_unmarshalData shows how you can use a Decoder and a NodeBuilder (or NodePrototype) together to do unmarshalling.
Often you'll do this implicitly through a LinkSystem.Load call instead, but you can do it directly, too.
package main
import (
"fmt"
"strings"
"github.com/ipld/go-ipld-prime/codec/dagjson"
"github.com/ipld/go-ipld-prime/node/basicnode"
)
func main() {
serial := strings.NewReader(`{"hey":"it works!","yes": true}`)
np := basicnode.Prototype.Any // Pick a stle for the in-memory data.
nb := np.NewBuilder() // Create a builder.
dagjson.Decode(nb, serial) // Hand the builder to decoding -- decoding will fill it in!
n := nb.Build() // Call 'Build' to get the resulting Node. (It's immutable!)
fmt.Printf("the data decoded was a %s kind\n", n.Kind())
fmt.Printf("the length of the node is %d\n", n.Length())
}
Output: the data decoded was a map kind the length of the node is 2
Index ¶
- Constants
- Variables
- func DeepEqual(x, y Node) bool
- type ADL
- type BlockReadOpener
- type BlockWriteCommitter
- type BlockWriteOpener
- type Decoder
- type Encoder
- type ErrHashMismatch
- type ErrInvalidKey
- type ErrInvalidSegmentForList
- type ErrIteratorOverread
- type ErrMissingRequiredField
- type ErrNotExists
- type ErrRepeatedMapKey
- type ErrWrongKind
- type Kind
- type Link
- type LinkContext
- type LinkPrototype
- type LinkSystem
- type ListAssembler
- type ListIterator
- type MapAssembler
- type MapIterator
- type Node
- type NodeAssembler
- type NodeBuilder
- type NodePrototype
- type NodeReifier
- type Path
- type PathSegment
Examples ¶
Constants ¶
const ( Kind_Invalid = datamodel.Kind_Invalid Kind_Map = datamodel.Kind_Map Kind_List = datamodel.Kind_List Kind_Null = datamodel.Kind_Null Kind_Bool = datamodel.Kind_Bool Kind_Int = datamodel.Kind_Int Kind_Float = datamodel.Kind_Float Kind_String = datamodel.Kind_String Kind_Bytes = datamodel.Kind_Bytes Kind_Link = datamodel.Kind_Link )
Variables ¶
var ( Null = datamodel.Null Absent = datamodel.Absent )
var ( KindSet_Recursive = datamodel.KindSet_Recursive KindSet_Scalar = datamodel.KindSet_Scalar KindSet_JustMap = datamodel.KindSet_JustMap KindSet_JustList = datamodel.KindSet_JustList KindSet_JustNull = datamodel.KindSet_JustNull KindSet_JustBool = datamodel.KindSet_JustBool KindSet_JustInt = datamodel.KindSet_JustInt KindSet_JustFloat = datamodel.KindSet_JustFloat KindSet_JustString = datamodel.KindSet_JustString KindSet_JustBytes = datamodel.KindSet_JustBytes KindSet_JustLink = datamodel.KindSet_JustLink )
Future: These aliases for the `KindSet_*` values may be dropped someday. I don't think they're very important to have cluttering up namespace here. They're included for a brief transitional period, largely for the sake of codegen things which have referred to them, but may disappear in the future.
Functions ¶
Types ¶
type BlockReadOpener ¶ added in v0.9.0
type BlockReadOpener = linking.BlockReadOpener
type BlockWriteCommitter ¶ added in v0.9.0
type BlockWriteCommitter = linking.BlockWriteCommitter
type BlockWriteOpener ¶ added in v0.9.0
type BlockWriteOpener = linking.BlockWriteOpener
type ErrHashMismatch ¶ added in v0.9.0
type ErrHashMismatch = linking.ErrHashMismatch
Future: These error type aliases may be dropped someday. Being able to see them as having more than one package name is not helpful to clarity. They are left here for now for a brief transitional period, because it was relatively easy to do so.
type ErrInvalidKey ¶ added in v0.0.2
type ErrInvalidKey = schema.ErrInvalidKey
Future: These error type aliases may be dropped someday. Being able to see them as having more than one package name is not helpful to clarity. They are left here for now for a brief transitional period, because it was relatively easy to do so.
type ErrInvalidSegmentForList ¶ added in v0.4.0
type ErrInvalidSegmentForList = datamodel.ErrInvalidSegmentForList
Future: These error type aliases may be dropped someday. Being able to see them as having more than one package name is not helpful to clarity. They are left here for now for a brief transitional period, because it was relatively easy to do so.
type ErrIteratorOverread ¶
type ErrIteratorOverread = datamodel.ErrIteratorOverread
Future: These error type aliases may be dropped someday. Being able to see them as having more than one package name is not helpful to clarity. They are left here for now for a brief transitional period, because it was relatively easy to do so.
type ErrMissingRequiredField ¶ added in v0.0.3
type ErrMissingRequiredField = schema.ErrMissingRequiredField
Future: These error type aliases may be dropped someday. Being able to see them as having more than one package name is not helpful to clarity. They are left here for now for a brief transitional period, because it was relatively easy to do so.
type ErrNotExists ¶
type ErrNotExists = datamodel.ErrNotExists
Future: These error type aliases may be dropped someday. Being able to see them as having more than one package name is not helpful to clarity. They are left here for now for a brief transitional period, because it was relatively easy to do so.
type ErrRepeatedMapKey ¶ added in v0.0.3
type ErrRepeatedMapKey = datamodel.ErrRepeatedMapKey
Future: These error type aliases may be dropped someday. Being able to see them as having more than one package name is not helpful to clarity. They are left here for now for a brief transitional period, because it was relatively easy to do so.
type ErrWrongKind ¶
type ErrWrongKind = datamodel.ErrWrongKind
Future: These error type aliases may be dropped someday. Being able to see them as having more than one package name is not helpful to clarity. They are left here for now for a brief transitional period, because it was relatively easy to do so.
type LinkContext ¶
type LinkContext = linking.LinkContext
type LinkPrototype ¶ added in v0.9.0
type LinkPrototype = datamodel.LinkPrototype
type LinkSystem ¶ added in v0.9.0
type LinkSystem = linking.LinkSystem
type ListAssembler ¶ added in v0.0.3
type ListAssembler = datamodel.ListAssembler
type ListIterator ¶
type ListIterator = datamodel.ListIterator
type MapAssembler ¶ added in v0.0.3
type MapAssembler = datamodel.MapAssembler
type MapIterator ¶
type MapIterator = datamodel.MapIterator
type NodeAssembler ¶ added in v0.0.3
type NodeAssembler = datamodel.NodeAssembler
type NodeBuilder ¶
type NodeBuilder = datamodel.NodeBuilder
type NodePrototype ¶ added in v0.5.0
type NodePrototype = datamodel.NodePrototype
type NodeReifier ¶ added in v0.10.0
type NodeReifier = linking.NodeReifier
type Path ¶
func NewPath ¶ added in v0.0.2
func NewPath(segments []PathSegment) Path
NewPath is an alias for datamodel.NewPath.
Pathing is a concept defined in the data model layer of IPLD.
type PathSegment ¶ added in v0.0.2
type PathSegment = datamodel.PathSegment
func ParsePathSegment ¶ added in v0.0.2
func ParsePathSegment(s string) PathSegment
ParsePathSegment is an alias for datamodel.ParsePathSegment.
Pathing is a concept defined in the data model layer of IPLD.
func PathSegmentOfInt ¶ added in v0.0.2
func PathSegmentOfInt(i int64) PathSegment
PathSegmentOfInt is an alias for datamodel.PathSegmentOfInt.
Pathing is a concept defined in the data model layer of IPLD.
func PathSegmentOfString ¶ added in v0.0.2
func PathSegmentOfString(s string) PathSegment
PathSegmentOfString is an alias for datamodel.PathSegmentOfString.
Pathing is a concept defined in the data model layer of IPLD.
Directories
¶
| Path | Synopsis |
|---|---|
|
rot13adl
rot13adl is a demo ADL -- its purpose is to show what an ADL and its public interface can look like.
|
rot13adl is a demo ADL -- its purpose is to show what an ADL and its public interface can look like. |
|
dagcbor
The dagcbor package provides a DAG-CBOR codec implementation.
|
The dagcbor package provides a DAG-CBOR codec implementation. |
|
dagjson2
Several groups of exported symbols are available at different levels of abstraction: - You might just want the multicodec registration! Then never deal with this package directly again.
|
Several groups of exported symbols are available at different levels of abstraction: - You might just want the multicodec registration! Then never deal with this package directly again. |
|
jst
"jst" -- JSON Table -- is a format that's parsable as JSON, while sprucing up the display to humans using the non-significant whitespace cleverly.
|
"jst" -- JSON Table -- is a format that's parsable as JSON, while sprucing up the display to humans using the non-significant whitespace cleverly. |
|
jst/demo
command
|
|
|
raw
Package raw implements IPLD's raw codec, which simply writes and reads a Node which can be represented as bytes.
|
Package raw implements IPLD's raw codec, which simply writes and reads a Node which can be represented as bytes. |
|
The datamodel package defines the most essential interfaces for describing IPLD Data -- such as Node, NodePrototype, NodeBuilder, Link, and Path.
|
The datamodel package defines the most essential interfaces for describing IPLD Data -- such as Node, NodePrototype, NodeBuilder, Link, and Path. |
|
The fluent package offers helper utilities for using NodeAssembler more tersely by providing an interface that handles all errors for you, and allows use of closures for any recursive assembly so that creating trees of data results in indentation for legibility.
|
The fluent package offers helper utilities for using NodeAssembler more tersely by providing an interface that handles all errors for you, and allows use of closures for any recursive assembly so that creating trees of data results in indentation for legibility. |
|
qp
qp helps to quickly build IPLD nodes.
|
qp helps to quickly build IPLD nodes. |
|
Package 'must' provides another alternative to the 'fluent' package, providing many helpful functions for wrapping methods with multiple returns into a single return (converting errors into panics).
|
Package 'must' provides another alternative to the 'fluent' package, providing many helpful functions for wrapping methods with multiple returns into a single return (converting errors into panics). |
|
The 'node' package gathers various general purpose Node implementations; the first one you should jump to is 'node/basicnode'.
|
The 'node' package gathers various general purpose Node implementations; the first one you should jump to is 'node/basicnode'. |
|
basic
This is a transitional package: please move your references to `node/basicnode`.
|
This is a transitional package: please move your references to `node/basicnode`. |
|
bindnode
Package bindnode provides an datamodel.Node implementation via Go reflection.
|
Package bindnode provides an datamodel.Node implementation via Go reflection. |
|
tests/corpus
The corpus package exports some values useful for building tests and benchmarks.
|
The corpus package exports some values useful for building tests and benchmarks. |
|
Storage contains some simple implementations for the ipld.BlockReadOpener and ipld.BlockWriteOpener interfaces, which are typically used by composition in a LinkSystem.
|
Storage contains some simple implementations for the ipld.BlockReadOpener and ipld.BlockWriteOpener interfaces, which are typically used by composition in a LinkSystem. |
|
bsadapter
module
|
|
|
bsrvadapter
module
|
|
|
dsadapter
module
|
|
|
This package provides functional utilities for traversing and transforming IPLD nodes.
|
This package provides functional utilities for traversing and transforming IPLD nodes. |
|
selector/parse
selectorparse package contains some helpful functions for parsing the serial form of Selectors.
|
selectorparse package contains some helpful functions for parsing the serial form of Selectors. |