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  {
141  SmallValueBitLength = 5U,
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 
152  BreakByte = (unsigned)Break | (SimpleTypesType << MajorTypeShift)
153 };

◆ CborMajorTypes

Enumerator
UnsignedIntegerType 
NegativeIntegerType 
ByteStringType 
TextStringType 
ArrayType 
MapType 
TagType 
SimpleTypesType 

Definition at line 112 of file cborinternal_p.h.

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

◆ 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

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.

Value32Bit
@ Value32Bit
Definition: cborinternal_p.h:145
ArrayType
@ ArrayType
Definition: cborinternal_p.h:117
UndefinedValue
@ UndefinedValue
Definition: cborinternal_p.h:132
SmallValueBitLength
@ SmallValueBitLength
Definition: cborinternal_p.h:141
HalfPrecisionFloat
@ HalfPrecisionFloat
Definition: cborinternal_p.h:134
TagType
@ TagType
Definition: cborinternal_p.h:119
MapType
@ MapType
Definition: cborinternal_p.h:118
SinglePrecisionFloat
@ SinglePrecisionFloat
Definition: cborinternal_p.h:135
SimpleTypesType
@ SimpleTypesType
Definition: cborinternal_p.h:120
TextStringType
@ TextStringType
Definition: cborinternal_p.h:116
Value64Bit
@ Value64Bit
Definition: cborinternal_p.h:146
NegativeIntegerType
@ NegativeIntegerType
Definition: cborinternal_p.h:114
ByteStringType
@ ByteStringType
Definition: cborinternal_p.h:115
DoublePrecisionFloat
@ DoublePrecisionFloat
Definition: cborinternal_p.h:136
NullValue
@ NullValue
Definition: cborinternal_p.h:131
TrueValue
@ TrueValue
Definition: cborinternal_p.h:130
MajorTypeShift
@ MajorTypeShift
Definition: cborinternal_p.h:149
Value8Bit
@ Value8Bit
Definition: cborinternal_p.h:143
MajorTypeMask
@ MajorTypeMask
Definition: cborinternal_p.h:150
Break
@ Break
Definition: cborinternal_p.h:137
UnsignedIntegerType
@ UnsignedIntegerType
Definition: cborinternal_p.h:113
Value16Bit
@ Value16Bit
Definition: cborinternal_p.h:144
CborSimpleTypes
CborSimpleTypes
Definition: cborinternal_p.h:128
CborMajorTypes
CborMajorTypes
Definition: cborinternal_p.h:112
SmallValueMask
@ SmallValueMask
Definition: cborinternal_p.h:142
IndefiniteLength
@ IndefiniteLength
Definition: cborinternal_p.h:147
FalseValue
@ FalseValue
Definition: cborinternal_p.h:129
BreakByte
@ BreakByte
Definition: cborinternal_p.h:152
SimpleTypeInNextByte
@ SimpleTypeInNextByte
Definition: cborinternal_p.h:133