block

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package block encodes and decodes OrbitDB's dag-cbor blocks.

It plays the role multiformats/block plays in @orbitdb/core: values are encoded as canonical dag-cbor and addressed by a CIDv1 (dag-cbor codec, sha2-256) rendered in base58btc, e.g. "zdpu...".

Values are plain Go values. Encoding accepts nil, bool, integers, floats, string, []byte, cid.Cid, slices, arrays, maps with string keys and datamodel.Node; other types (structs, pointers) are converted through encoding/json first. Decoding produces nil, bool, int64, float64, string, []byte, cid.Cid, []any and map[string]any.

Numbers follow JavaScript semantics so blocks re-encode identically on both sides: a float with an integral value in the safe-integer range is encoded as an integer, exactly as @ipld/dag-cbor encodes a JS number.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CID

func CID(data []byte) (cid.Cid, error)

CID returns the CIDv1 (dag-cbor, sha2-256) of data.

func Decode

func Decode(data []byte) (any, error)

Decode decodes a dag-cbor block into a Go value.

func Encode

func Encode(v any) (hash string, data []byte, err error)

Encode encodes v as dag-cbor and returns its hash and bytes.

func FromNode

func FromNode(n datamodel.Node) (any, error)

FromNode converts an IPLD data model node to a Go value.

func Hash

func Hash(data []byte) (string, error)

Hash returns the base58btc string of the CID of data, the form OrbitDB uses for entry, identity and manifest hashes.

func Int

func Int(m map[string]any, key string) (int64, error)

Int returns m[key] as an int64.

func Map

func Map(v any) (map[string]any, error)

Map asserts that v is a map, as a decoded block's root usually is.

func String

func String(m map[string]any, key string) (string, error)

String returns m[key] as a string.

func Strings

func Strings(m map[string]any, key string) ([]string, error)

Strings returns m[key] as a []string.

func ToNode

func ToNode(v any) (datamodel.Node, error)

ToNode converts a Go value to an IPLD data model node.

Types

This section is empty.

Jump to

Keyboard shortcuts

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