elm-cardano/cbor/1.0.0

Cbor

CBOR (Concise Binary Object Representation) data model and diagnostic notation.

This module defines CborItem, a lossless representation of any well-formed CBOR encoding per RFC 8949.

= CborInt52 IntWidth Int
| CborInt64 Sign Bytes
| CborByteString Bytes
| CborByteStringChunked (List Bytes)
| CborString String
| CborStringChunked (List String)
| CborArray Length (List CborItem)
| CborMap
(List
{ key : CborItem
, value : CborItem
}
)
| CborTag Tag CborItem
| CborBool Bool
| CborFloat FloatWidth Float
| CborNull
| CborUndefined
| CborSimple SimpleWidth Int

A lossless representation of a CBOR data item.

Round-tripping (decode → re-encode) preserves the exact original bytes. Encoding details (integer width, float precision, definite vs indefinite length) are captured for faithful diagnostic output.

The primary user-facing API is the combinator layer in Cbor.Encode and Cbor.Decode. Use CborItem as an escape hatch for generic CBOR handling, diagnostics, and protocol debugging.

= IW0
| IW8
| IW16
| IW32
| IW64

How an integer value was encoded on the wire.

  • IW0 — inline in the additional info (values 0–23, 0 extra bytes)
  • IW8 — 1-byte uint8 argument
  • IW16 — 2-byte uint16 argument
  • IW32 — 4-byte uint32 argument
  • IW64 — 8-byte uint64 argument
= FW16
| FW32
| FW64

How a float was encoded on the wire.

  • FW16 — IEEE 754 half-precision (2 bytes)
  • FW32 — IEEE 754 single-precision (4 bytes)
  • FW64 — IEEE 754 double-precision (8 bytes)
= SW0
| SW8

How a simple value was encoded on the wire.

  • SW0 — inline in the additional info (values 0–19, 0 extra bytes)
  • SW8 — 1-byte argument (values 32–255)
type Length
= Definite
| Indefinite

Whether an array or map used definite or indefinite length encoding.

type Sign
= Positive
| Negative

The sign of a CBOR integer, corresponding to the major type.

  • Positive — CBOR major type 0 (unsigned integer)
  • Negative — CBOR major type 1 (negative integer, value = −1 − argument)
type Tag
= StandardDateTime
| EpochDateTime
| PositiveBigNum
| NegativeBigNum
| DecimalFraction
| BigFloat
| Base64UrlConversion
| Base64Conversion
| Base16Conversion
| Cbor
| Uri
| Base64Url
| Base64
| Regex
| Mime
| IsCbor
| Unknown Int

CBOR semantic tags from the IANA registry.

Named variants for well-known tags. Unknown Int as the catch-all for unrecognized tag numbers.

tagToInt : Tag -> Int

Convert a tag to its IANA-registered integer number.

intToTag : Int -> Tag

Convert an integer to its Tag representation.

Returns the named variant for well-known tag numbers, Unknown n otherwise.

type Error context
= InContext
{ label : context
, start : Int
}
(Error context)
| OutOfBounds
{ at : Int
, bytes : Int
}
| DecodingError { at : Int } DecodeError
| BadOneOf { at : Int } (List (Error context))

Structured error returned by Cbor.Decode.decode.

  • InContext — a nested error with a context label and byte offset.
  • OutOfBounds — the decoder ran past the end of the input.
  • DecodingError — a CBOR-specific error at a byte offset.
  • BadOneOf — all branches of a oneOf failed.
= WrongMajorType
{ expected : Int
, got : Int
}
| WrongInitialByte { got : Int }
| WrongTag
{ expected : Int
, got : Int
}
| ReservedAdditionalInfo Int
| IntegerOverflow
| MissingKey String
| KeyMismatch
{ expected : String
, got : String
}
| TooFewElements
(Maybe
{ expected : Int
, got : Int
}
)
| TooManyElements
(Maybe
{ expected : Int
, got : Int
}
)
| FailedToFinalizeRecord
| NonConsumingDecoder String
| UnknownMajorType Int

CBOR-specific decoding error.

diagnose : CborItem -> String

Produce CBOR diagnostic notation (RFC 8949 Section 8) for a CborItem.

Encoding indicators are appended as suffixes (e.g., 1_0, 1.5_1). Indefinite-length containers use the [_ ...] and {_ ...} notation.