atproto_repo/dag_cbor

The atproto subset of DAG-CBOR: no floats, no undefined, definite lengths only, minimal integer heads, text-only map keys in canonical order, and tag 42 as the one tag (a CID link).

Integers are limited to the range exactly representable on the JavaScript target, -2^53 to 2^53 - 1, so both targets accept and reject the same bytes.

Types

pub type DecodeError {
  UnexpectedEnd
  TrailingBytes(Int)
  NonMinimalHead
  IndefiniteLength
  ReservedAdditionalInfo(Int)
  UnsupportedFloat
  UnsupportedSimple(Int)
  UnsupportedTag(Int)
  MalformedLink
  InvalidLink(cid.CidError)
  InvalidUtf8
  NonTextMapKey
  MapKeysNotCanonical(key: String)
  IntegerOutOfRange
  NestingTooDeep
}

Constructors

  • UnexpectedEnd
  • TrailingBytes(Int)
  • NonMinimalHead
  • IndefiniteLength
  • ReservedAdditionalInfo(Int)
  • UnsupportedFloat
  • UnsupportedSimple(Int)
  • UnsupportedTag(Int)
  • MalformedLink
  • InvalidLink(cid.CidError)
  • InvalidUtf8
  • NonTextMapKey
  • MapKeysNotCanonical(key: String)
  • IntegerOutOfRange
  • NestingTooDeep
pub type EncodeError {
  EncodeIntegerOutOfRange(Int)
}

Constructors

  • EncodeIntegerOutOfRange(Int)
pub type Value {
  Null
  Boolean(Bool)
  Integer(Int)
  Text(String)
  Bytes(BitArray)
  Array(List(Value))
  Map(dict.Dict(String, Value))
  Link(cid.Cid)
}

Constructors

Values

pub fn decode(input: BitArray) -> Result(Value, DecodeError)

Decodes exactly one value; trailing bytes are an error.

pub fn encode(value: Value) -> Result(BitArray, EncodeError)

Canonical DAG-CBOR bytes: map keys sorted by encoded length, then bytewise; every head in its shortest form.

✨ Search Document