ProtoRune.CID (proto_rune v0.5.1)

Copy Markdown

CID (Content Identifier) values as they appear in the ATProto event stream.

Only CIDv1 is supported, which covers every CID produced by modern ATProto relays and PDSes. The string representation uses the standard base32 multibase encoding (b prefix), so CIDs can be compared directly against the CID strings returned by XRPC endpoints:

to_string(op.cid) == record["cid"]

Summary

Types

t()

A parsed CIDv1.

Functions

Parses a binary CID from the head of the given binary.

Decodes a DAG-CBOR CID link ({:tag, 42, bytes}) into a CID.

Re-encodes the CID to its binary form.

Encodes the CID in its base32 multibase string form (b prefix).

Types

t()

@type t() :: %ProtoRune.CID{codec: non_neg_integer(), multihash: binary(), version: 1}

A parsed CIDv1.

  • :version - always 1.
  • :codec - the multicodec code of the referenced data (0x71 for DAG-CBOR, 0x55 for raw bytes).
  • :multihash - the raw multihash bytes (function code varint, digest size varint and digest).

Functions

from_binary(arg)

@spec from_binary(binary()) :: {:ok, t(), binary()} | {:error, atom() | tuple()}

Parses a binary CID from the head of the given binary.

Returns the parsed CID along with the unconsumed rest of the input, which allows reading the CID-prefixed block entries of a CAR file.

from_link(arg1)

@spec from_link(term()) :: {:ok, t()} | {:error, atom() | tuple()}

Decodes a DAG-CBOR CID link ({:tag, 42, bytes}) into a CID.

DAG-CBOR prefixes the binary CID with a single 0x00 byte for historical multibase reasons.

to_binary(cid)

@spec to_binary(t()) :: binary()

Re-encodes the CID to its binary form.

to_string(cid)

@spec to_string(t()) :: String.t()

Encodes the CID in its base32 multibase string form (b prefix).