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:

enumerator CBOR_TYPE_UINT

0 - positive integers

enumerator CBOR_TYPE_NEGINT

1 - negative integers

enumerator CBOR_TYPE_BYTESTRING

2 - byte strings

enumerator CBOR_TYPE_STRING

3 - strings

enumerator CBOR_TYPE_ARRAY

4 - arrays

enumerator CBOR_TYPE_MAP

5 - maps

enumerator CBOR_TYPE_TAG

6 - tags

enumerator 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.

param item:

return:

The type

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?

param item:

the item

return:

Is the item an CBOR_TYPE_UINT?

bool cbor_isa_negint(const cbor_item_t *item)

Does the item have the appropriate major type?

param item:

the item

return:

Is the item a CBOR_TYPE_NEGINT?

bool cbor_isa_bytestring(const cbor_item_t *item)

Does the item have the appropriate major type?

param item:

the item

return:

Is the item a CBOR_TYPE_BYTESTRING?

bool cbor_isa_string(const cbor_item_t *item)

Does the item have the appropriate major type?

param item:

the item

return:

Is the item a CBOR_TYPE_STRING?

bool cbor_isa_array(const cbor_item_t *item)

Does the item have the appropriate major type?

param item:

the item

return:

Is the item an CBOR_TYPE_ARRAY?

bool cbor_isa_map(const cbor_item_t *item)

Does the item have the appropriate major type?

param item:

the item

return:

Is the item a CBOR_TYPE_MAP?

bool cbor_isa_tag(const cbor_item_t *item)

Does the item have the appropriate major type?

param item:

the item

return:

Is the item a CBOR_TYPE_TAG?

bool cbor_isa_float_ctrl(const cbor_item_t *item)

Does the item have the appropriate major type?

param item:

the item

return:

Is the item a CBOR_TYPE_FLOAT_CTRL?

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?

param item:

the item

return:

Is the item an integer, either positive or negative?

bool cbor_is_float(const cbor_item_t *item)

Is the item an a floating point number?

param item:

the item

return:

Is the item a floating point number?

bool cbor_is_bool(const cbor_item_t *item)

Is the item an a boolean?

param item:

the item

return:

Is the item a boolean?

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.

param item:

the item

return:

Is the item (CBOR logical) null?

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.

param item:

the item

return:

Is the item (CBOR logical) undefined?