Types of items¶
Every cbor_item_t
has a cbor_type
associated with it - these constants correspond to the types specified by the CBOR standard:
-
enum
cbor_type
¶ Specifies the Major type of cbor_item_t.
Values:
-
CBOR_TYPE_UINT
¶ 0 - positive integers
-
CBOR_TYPE_NEGINT
¶ 1 - negative integers
-
CBOR_TYPE_BYTESTRING
¶ 2 - byte strings
-
CBOR_TYPE_STRING
¶ 3 - strings
-
CBOR_TYPE_ARRAY
¶ 4 - arrays
-
CBOR_TYPE_MAP
¶ 5 - maps
-
CBOR_TYPE_TAG
¶ 6 - tags
-
CBOR_TYPE_FLOAT_CTRL
¶ 7 - decimals and special values (true, false, nil, ...)
-
To find out the type of an item, one can use
-
cbor_type
cbor_typeof
(const cbor_item_t *item)¶ Get the type of the item.
- Return
- The type
- Parameters
item[borrow]
-
Please note the distinction between functions like cbor_isa_uint()
and cbor_is_int()
. The following functions work solely with the major type value.
Binary queries¶
Alternatively, there are functions to query each particular type.
Warning
Passing an invalid cbor_item_t
reference to any of these functions results in undefined behavior.
-
bool
cbor_isa_uint
(const cbor_item_t *item)¶ Does the item have the appropriate major type?
- Return
- Is the item an CBOR_TYPE_UINT?
- Parameters
item[borrow]
-the item
-
bool
cbor_isa_negint
(const cbor_item_t *item)¶ Does the item have the appropriate major type?
- Return
- Is the item a CBOR_TYPE_NEGINT?
- Parameters
item[borrow]
-the item
-
bool
cbor_isa_bytestring
(const cbor_item_t *item)¶ Does the item have the appropriate major type?
- Return
- Is the item a CBOR_TYPE_BYTESTRING?
- Parameters
item[borrow]
-the item
-
bool
cbor_isa_string
(const cbor_item_t *item)¶ Does the item have the appropriate major type?
- Return
- Is the item a CBOR_TYPE_STRING?
- Parameters
item[borrow]
-the item
-
bool
cbor_isa_array
(const cbor_item_t *item)¶ Does the item have the appropriate major type?
- Return
- Is the item an CBOR_TYPE_ARRAY?
- Parameters
item[borrow]
-the item
-
bool
cbor_isa_map
(const cbor_item_t *item)¶ Does the item have the appropriate major type?
- Return
- Is the item a CBOR_TYPE_MAP?
- Parameters
item[borrow]
-the item
-
bool
cbor_isa_tag
(const cbor_item_t *item)¶ Does the item have the appropriate major type?
- Return
- Is the item a CBOR_TYPE_TAG?
- Parameters
item[borrow]
-the item
-
bool
cbor_isa_float_ctrl
(const cbor_item_t *item)¶ Does the item have the appropriate major type?
- Return
- Is the item a CBOR_TYPE_FLOAT_CTRL?
- Parameters
item[borrow]
-the item
Logical queries¶
These functions provide information about the item type from a more high-level perspective
-
bool
cbor_is_int
(const cbor_item_t *item)¶ Is the item an integer, either positive or negative?
- Return
- Is the item an integer, either positive or negative?
- Parameters
item[borrow]
-the item
-
bool
cbor_is_float
(const cbor_item_t *item)¶ Is the item an a floating point number?
- Return
- Is the item a floating point number?
- Parameters
item[borrow]
-the item
-
bool
cbor_is_bool
(const cbor_item_t *item)¶ Is the item an a boolean?
- Return
- Is the item a boolean?
- Parameters
item[borrow]
-the item
-
bool
cbor_is_null
(const cbor_item_t *item)¶ Does this item represent
null
Warning
This is in no way related to the value of the pointer. Passing a null pointer will most likely result in a crash.
- Return
- Is the item (CBOR logical) null?
- Parameters
item[borrow]
-the item
-
bool
cbor_is_undef
(const cbor_item_t *item)¶ Does this item represent
undefined
Warning
Care must be taken to distinguish nulls and undefined values in C.
- Return
- Is the item (CBOR logical) undefined?
- Parameters
item[borrow]
-the item