Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeBlock(block blocks.Block) (node.Node, error)
- func DecodeInto(b []byte, v interface{}) error
- func DecodeReader(r io.Reader, v interface{}) error
- func DumpObject(obj interface{}) (out []byte, err error)
- func Encode(obj interface{}) (out []byte, err error)
- func EncodeWriter(obj interface{}, w io.Writer) error
- func HumanReadable(blob []byte) (string, error)
- func NewSerializationError(err error) error
- func RegisterCborType(i interface{})
- type BasicIpldStore
- type IpldBlockstore
- type IpldBlockstoreViewer
- type IpldStore
- type Node
- func (n *Node) Cid() cid.Cid
- func (n *Node) Copy() node.Node
- func (n *Node) Links() []*node.Link
- func (n *Node) Loggable() map[string]interface{}
- func (n *Node) MarshalJSON() ([]byte, error)
- func (n *Node) RawData() []byte
- func (n *Node) Resolve(path []string) (interface{}, []string, error)
- func (n *Node) ResolveLink(path []string) (*node.Link, []string, error)
- func (n *Node) Size() (uint64, error)
- func (n *Node) Stat() (*node.NodeStat, error)
- func (n *Node) String() string
- func (n *Node) Tree(path string, depth int) []string
- type SerializationError
Constants ¶
const CBORTagLink = 42
CBORTagLink is the integer used to represent tags in CBOR.
const DefaultMultihash = uint64(mh.BLAKE2B_MIN + 31)
Variables ¶
var ( // ErrNoSuchLink is returned when no link with the given name was found. ErrNoSuchLink = errors.New("no such link found") ErrNonLink = errors.New("non-link found at given path") ErrInvalidLink = errors.New("link value should have been bytes") ErrInvalidKeys = errors.New("map keys must be strings") ErrArrayOutOfRange = errors.New("array index out of range") ErrNoLinks = errors.New("tried to resolve through object that had no links") ErrEmptyLink = errors.New("link value was empty") ErrInvalidMultibase = errors.New("invalid multibase on IPLD link") ErrNonStringLink = errors.New("link should have been a string") )
var BigIntAtlasEntry = atlas.BuildEntry(big.Int{}).Transform(). TransformMarshal(atlas.MakeMarshalTransformFunc( func(i big.Int) ([]byte, error) { return i.Bytes(), nil })). TransformUnmarshal(atlas.MakeUnmarshalTransformFunc( func(x []byte) (big.Int, error) { return *big.NewInt(0).SetBytes(x), nil })). Complete()
BigIntAtlasEntry gives a reasonable default encoding for big.Int. It is not included in the entries by default.
var CborAtlas atlas.Atlas
CborAtlas is the refmt.Atlas used by the CBOR IPLD decoder/encoder.
Functions ¶
func DecodeBlock ¶
DecodeBlock decodes a CBOR encoded Block into an IPLD Node.
This method *does not* canonicalize and *will* preserve the CID. As a matter of fact, it will assume that `block.Cid()` returns the correct CID and will make no effort to validate this assumption.
In general, you should not be calling this method directly. Instead, you should be calling the `Decode` method from the `go-ipld-format` package. That method will pick the right decoder based on the Block's CID.
Note: This function keeps a reference to `block` and assumes that it is immutable.
func DecodeInto ¶
DecodeInto decodes a serialized IPLD cbor object into the given object.
func DecodeReader ¶ added in v0.0.3
DecodeReader reads from the given reader and decodes a serialized IPLD cbor object into the given object.
func DumpObject ¶
DumpObject marshals any object into its CBOR serialized byte representation Deprecated: use Encode instead.
func Encode ¶ added in v0.2.0
Encode marshals any object into its CBOR serialized byte representation
func EncodeWriter ¶ added in v0.2.0
EncodeWriter marshals into the writer any object as its CBOR serialized byte representation.
func HumanReadable ¶
HumanReadable returns a string representation of a CBOR blob
func NewSerializationError ¶ added in v0.0.4
func RegisterCborType ¶
func RegisterCborType(i interface{})
RegisterCborType allows to register a custom cbor type
Types ¶
type BasicIpldStore ¶ added in v0.0.4
type BasicIpldStore struct { Blocks IpldBlockstore Viewer IpldBlockstoreViewer Atlas *atlas.Atlas DefaultMultihash uint64 }
BasicIpldStore wraps and IpldBlockstore and implements the IpldStore interface.
func NewCborStore ¶ added in v0.0.4
func NewCborStore(bs IpldBlockstore) *BasicIpldStore
NewCborStore returns an IpldStore implementation backed by the provided IpldBlockstore.
type IpldBlockstore ¶ added in v0.0.4
type IpldBlockstore interface { Get(context.Context, cid.Cid) (block.Block, error) Put(context.Context, block.Block) error }
IpldBlockstore defines a subset of the go-ipfs-blockstore Blockstore interface providing methods for storing and retrieving block-centered data.
type IpldBlockstoreViewer ¶ added in v0.0.5
type IpldBlockstoreViewer interface { // View provides zero-copy access to blocks in a blockstore. The callback // function will be invoked with the value for the key. The user MUST not // modify the byte array, as it could be memory-mapped. View(cid.Cid, func([]byte) error) error }
IpldBlockstoreViewer is a trait that enables zero-copy access to blocks in a blockstore.
type IpldStore ¶ added in v0.0.4
type IpldStore interface { Get(ctx context.Context, c cid.Cid, out interface{}) error Put(ctx context.Context, v interface{}) (cid.Cid, error) }
IpldStore wraps a Blockstore and provides an interface for storing and retrieving CBOR encoded data.
func NewMemCborStore ¶ added in v0.0.5
func NewMemCborStore() IpldStore
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node represents an IPLD node.
func Decode ¶
Decode decodes a CBOR object into an IPLD Node.
If passed a non-canonical CBOR node, this function will canonicalize it. Therefore, `bytes.Equal(b, Decode(b).RawData())` may not hold. If you already have a CID for this data and want to ensure that it doesn't change, you should use `DecodeBlock`. mhType is multihash code to use for hashing, for example mh.SHA2_256
Note: This function does not hold onto `b`. You may reuse it.
func WrapObject ¶
WrapObject converts an arbitrary object into a Node.
func (*Node) MarshalJSON ¶
MarshalJSON converts the Node into its JSON representation.
func (*Node) Resolve ¶
Resolve resolves a given path, and returns the object found at the end, as well as the possible tail of the path that was not resolved.
func (*Node) ResolveLink ¶
ResolveLink resolves a path and returns the raw Link at the end, as well as the possible tail of the path that was not resolved.
type SerializationError ¶ added in v0.0.4
type SerializationError struct {
// contains filtered or unexported fields
}
func (SerializationError) Error ¶ added in v0.0.4
func (se SerializationError) Error() string
func (SerializationError) Is ¶ added in v0.0.4
func (se SerializationError) Is(o error) bool
func (SerializationError) Unwrap ¶ added in v0.0.4
func (se SerializationError) Unwrap() error