Wirepas SDK
cborinternal_p.h File Reference

Go to the source code of this file.

Functions

static unsigned short encode_half (double val)
 
static double decode_half (unsigned short half)
 
CborError _cbor_value_extract_number (const uint8_t **ptr, const uint8_t *end, uint64_t *len)
 
CborError _cbor_value_prepare_string_iteration (CborValue *it)
 
CborError _cbor_value_get_string_chunk (const CborValue *value, const void **bufferptr, size_t *len, CborValue *next)
 

Enumerations

enum  CborMajorTypes {
  UnsignedIntegerType = 0U , NegativeIntegerType = 1U , ByteStringType = 2U , TextStringType = 3U ,
  ArrayType = 4U , MapType = 5U , TagType = 6U , SimpleTypesType = 7U
}
 
enum  CborSimpleTypes {
  FalseValue = 20 , TrueValue = 21 , NullValue = 22 , UndefinedValue = 23 ,
  SimpleTypeInNextByte = 24 , HalfPrecisionFloat = 25 , SinglePrecisionFloat = 26 , DoublePrecisionFloat = 27 ,
  Break = 31
}
 
enum  {
  SmallValueBitLength = 5U , SmallValueMask = (1U << SmallValueBitLength) - 1 , Value8Bit = 24U , Value16Bit = 25U ,
  Value32Bit = 26U , Value64Bit = 27U , IndefiniteLength = 31U , MajorTypeShift = SmallValueBitLength ,
  MajorTypeMask = (int) (~0U << MajorTypeShift) , BreakByte = (unsigned)Break | (SimpleTypesType << MajorTypeShift)
}
 

Macros

#define CBOR_INTERNAL_API
 
#define CBOR_PARSER_MAX_RECURSIONS   1024
 

Function Documentation

◆ _cbor_value_extract_number()

CborError _cbor_value_extract_number ( const uint8_t **  ptr,
const uint8_t *  end,
uint64_t *  len 
)

◆ _cbor_value_get_string_chunk()

CborError _cbor_value_get_string_chunk ( const CborValue value,
const void **  bufferptr,
size_t *  len,
CborValue next 
)

◆ _cbor_value_prepare_string_iteration()

CborError _cbor_value_prepare_string_iteration ( CborValue it)

◆ decode_half()

static double decode_half ( unsigned short  half)
static

Definition at line 86 of file cborinternal_p.h.

87{
88 int exp = (half >> 10) & 0x1f;
89 int mant = half & 0x3ff;
90 double val;
91 if (exp == 0) val = ldexp(mant, -24);
92 else if (exp != 31) val = ldexp(mant + 1024, exp - 25);
93 else val = mant == 0 ? INFINITY : NAN;
94 return half & 0x8000 ? -val : val;
95}

◆ encode_half()

static unsigned short encode_half ( double  val)
static

Definition at line 52 of file cborinternal_p.h.

53{
54 uint64_t v;
55 int sign, exp, mant;
56 memcpy(&v, &val, sizeof(v));
57 sign = v >> 63 << 15;
58 exp = (v >> 52) & 0x7ff;
59 mant = v << 12 >> 12 >> (53-11); /* keep only the 11 most significant bits of the mantissa */
60 exp -= 1023;
61 if (exp == 1024) {
62 /* infinity or NaN */
63 exp = 16;
64 mant >>= 1;
65 } else if (exp >= 16) {
66 /* overflow, as largest number */
67 exp = 15;
68 mant = 1023;
69 } else if (exp >= -14) {
70 /* regular normal */
71 } else if (exp >= -24) {
72 /* subnormal */
73 mant |= 1024;
74 mant >>= -(exp + 14);
75 exp = -15;
76 } else {
77 /* underflow, make zero */
78 return 0;
79 }
80
81 /* safe cast here as bit operations above guarantee not to overflow */
82 return (unsigned short)(sign | ((exp + 15) << 10) | mant);
83}

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SmallValueBitLength 
SmallValueMask 
Value8Bit 
Value16Bit 
Value32Bit 
Value64Bit 
IndefiniteLength 
MajorTypeShift 
MajorTypeMask 
BreakByte 

Definition at line 140 of file cborinternal_p.h.

140 {
142 SmallValueMask = (1U << SmallValueBitLength) - 1, /* 31 */
143 Value8Bit = 24U,
144 Value16Bit = 25U,
145 Value32Bit = 26U,
146 Value64Bit = 27U,
147 IndefiniteLength = 31U,
148
150 MajorTypeMask = (int) (~0U << MajorTypeShift),
151
153};
@ IndefiniteLength
@ SmallValueBitLength
@ Value64Bit
@ Value32Bit
@ Value8Bit
@ BreakByte
@ MajorTypeShift
@ SmallValueMask
@ MajorTypeMask
@ Value16Bit
@ SimpleTypesType
@ Break

◆ CborMajorTypes

Enumerator
UnsignedIntegerType 
NegativeIntegerType 
ByteStringType 
TextStringType 
ArrayType 
MapType 
TagType 
SimpleTypesType 

Definition at line 112 of file cborinternal_p.h.

112 {
115 ByteStringType = 2U,
116 TextStringType = 3U,
117 ArrayType = 4U,
118 MapType = 5U, /* a.k.a. object */
119 TagType = 6U,
120 SimpleTypesType = 7U
CborMajorTypes
@ ArrayType
@ UnsignedIntegerType
@ MapType
@ ByteStringType
@ NegativeIntegerType
@ TextStringType
@ TagType

◆ CborSimpleTypes

Enumerator
FalseValue 
TrueValue 
NullValue 
UndefinedValue 
SimpleTypeInNextByte 
HalfPrecisionFloat 
SinglePrecisionFloat 
DoublePrecisionFloat 
Break 

Definition at line 128 of file cborinternal_p.h.

128 {
129 FalseValue = 20,
130 TrueValue = 21,
131 NullValue = 22,
132 UndefinedValue = 23,
133 SimpleTypeInNextByte = 24, /* not really a simple type */
134 HalfPrecisionFloat = 25, /* ditto */
135 SinglePrecisionFloat = 26, /* ditto */
136 DoublePrecisionFloat = 27, /* ditto */
137 Break = 31
CborSimpleTypes
@ SinglePrecisionFloat
@ HalfPrecisionFloat
@ UndefinedValue
@ SimpleTypeInNextByte
@ NullValue
@ TrueValue
@ DoublePrecisionFloat
@ FalseValue

Macro Definition Documentation

◆ CBOR_INTERNAL_API

#define CBOR_INTERNAL_API

Definition at line 100 of file cborinternal_p.h.

◆ CBOR_PARSER_MAX_RECURSIONS

#define CBOR_PARSER_MAX_RECURSIONS   1024

Definition at line 104 of file cborinternal_p.h.