CBOR.Tag
(cbor v2.0.0-rc1)
View Source
Wraps a value with a CBOR tag number, or marks one of the non-numeric
tag-like shapes (:bytes, :float, :simple) the encoder/decoder
treat specially.
Examples
# Raw byte string (CBOR major type 2):
CBOR.encode(%CBOR.Tag{tag: :bytes, value: <<1, 2, 3>>})
# IEEE 754 special floats — Elixir has no native representation:
CBOR.encode(%CBOR.Tag{tag: :float, value: :inf})
CBOR.encode(%CBOR.Tag{tag: :float, value: :"-inf"})
CBOR.encode(%CBOR.Tag{tag: :float, value: :nan})
# CBOR simple value:
CBOR.encode(%CBOR.Tag{tag: :simple, value: 16})
# Arbitrary CBOR tag number (RFC 8949 §3.4):
CBOR.encode(%CBOR.Tag{tag: 1234, value: "payload"})The decoder produces this struct for CBOR values that don't have a built-in Elixir representation — unrecognized tags, simple values, ±infinity, and NaN.
Summary
Types
Non-numeric tag-like markers the encoder/decoder treat specially:
:bytes (CBOR major type 2), :float (NaN/±Inf), :simple (CBOR
simple value).
RFC 8949 §3.4 tag number — uint64 on the wire.
Types
@type t() :: %CBOR.Tag{tag: tag_marker() | tag_number(), value: term()}
@type tag_marker() :: :bytes | :float | :simple
Non-numeric tag-like markers the encoder/decoder treat specially:
:bytes (CBOR major type 2), :float (NaN/±Inf), :simple (CBOR
simple value).
@type tag_number() :: non_neg_integer()
RFC 8949 §3.4 tag number — uint64 on the wire.