/* errors in converting to JSON */
CborErrorJsonObjectKeyIsAggregate,
CborErrorJsonObjectKeyNotString,
+ CborErrorJsonNotImplemented,
CborErrorOutOfMemory = ~0U / 2 + 1,
CborErrorInternalError = ~0U
CBOR_API CborError cbor_encoder_close_container(CborEncoder *encoder, const CborEncoder *containerEncoder);
CBOR_API CborError cbor_encoder_close_container_checked(CborEncoder *encoder, const CborEncoder *containerEncoder);
+CBOR_INLINE_API size_t cbor_encoder_get_buffer_size(const CborEncoder *encoder, const uint8_t *buffer)
+{
+ return (size_t)(encoder->ptr - buffer);
+}
+
+CBOR_INLINE_API size_t cbor_encoder_get_extra_bytes_needed(const CborEncoder *encoder)
+{
+ return encoder->end ? 0 : (size_t)encoder->bytes_needed;
+}
+
/* Parser API */
enum CborParserIteratorFlags
CBOR_INLINE_API bool cbor_value_at_end(const CborValue *it)
{ return it->remaining == 0; }
+CBOR_INLINE_API const uint8_t *cbor_value_get_next_byte(const CborValue *it)
+{ return it->ptr; }
CBOR_API CborError cbor_value_advance_fixed(CborValue *it);
CBOR_API CborError cbor_value_advance(CborValue *it);
CBOR_INLINE_API bool cbor_value_is_container(const CborValue *it)
{ return (CborType)value->type; }
/* Null & undefined type */
-CBOR_INLINE_API bool cbor_type_is_null(const CborValue *value)
+CBOR_INLINE_API bool cbor_value_is_null(const CborValue *value)
{ return value->type == CborNullType; }
-CBOR_INLINE_API bool cbor_type_is_undefined(const CborValue *value)
+CBOR_INLINE_API bool cbor_value_is_undefined(const CborValue *value)
{ return value->type == CborUndefinedType; }
/* Booleans */
if (!cbor_value_is_length_known(value))
return CborErrorUnknownLength;
uint64_t v = _cbor_value_extract_int64_helper(value);
- *length = v;
+ *length = (size_t)v;
if (*length != v)
return CborErrorDataTooLarge;
return CborNoError;
if (!cbor_value_is_length_known(value))
return CborErrorUnknownLength;
uint64_t v = _cbor_value_extract_int64_helper(value);
- *length = v;
+ *length = (size_t)v;
if (*length != v)
return CborErrorDataTooLarge;
return CborNoError;
if (!cbor_value_is_length_known(value))
return CborErrorUnknownLength;
uint64_t v = _cbor_value_extract_int64_helper(value);
- *length = v;
+ *length = (size_t)v;
if (*length != v)
return CborErrorDataTooLarge;
return CborNoError;
CBOR_API CborError cbor_value_map_find_value(const CborValue *map, const char *string, CborValue *element);
/* Floating point */
+CBOR_INLINE_API bool cbor_value_is_half_float(const CborValue *value)
+{ return value->type == CborHalfFloatType; }
CBOR_API CborError cbor_value_get_half_float(const CborValue *value, void *result);
+
+CBOR_INLINE_API bool cbor_value_is_float(const CborValue *value)
+{ return value->type == CborFloatType; }
CBOR_INLINE_API CborError cbor_value_get_float(const CborValue *value, float *result)
{
- assert(value->type == CborFloatType);
+ assert(cbor_value_is_float(value));
assert(value->flags & CborIteratorFlag_IntegerValueTooLarge);
uint32_t data = (uint32_t)_cbor_value_decode_int64_internal(value);
memcpy(result, &data, sizeof(*result));
return CborNoError;
}
+CBOR_INLINE_API bool cbor_value_is_double(const CborValue *value)
+{ return value->type == CborDoubleType; }
CBOR_INLINE_API CborError cbor_value_get_double(const CborValue *value, double *result)
{
- assert(value->type == CborDoubleType);
+ assert(cbor_value_is_double(value));
assert(value->flags & CborIteratorFlag_IntegerValueTooLarge);
uint64_t data = _cbor_value_decode_int64_internal(value);
memcpy(result, &data, sizeof(*result));
}
#endif
-#endif // CBOR_H
+#endif /* CBOR_H */