KNX IoT
KNX IoT Point API stack implementation
oc_rep.h
Go to the documentation of this file.
1 /*
2 // Copyright (c) 2016-2019 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 
21 #ifndef OC_REP_H
22 #define OC_REP_H
23 
24 #include "deps/tinycbor/src/cbor.h"
25 #include "oc_helpers.h"
26 #include "util/oc_memb.h"
27 #include <oc_config.h>
28 #include <stdbool.h>
29 #include <stdint.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 extern CborEncoder g_encoder, root_map, links_array;
36 extern int g_err;
37 
38 /*
39  The macros are based on stringizing operator (also known as Stringify)
40  https://docs.microsoft.com/en-us/cpp/preprocessor/stringizing-operator-hash?view=msvc-160
41 */
42 
51 void oc_rep_new(uint8_t *payload, int size);
52 
66 
78 const uint8_t *oc_rep_get_encoder_buf(void);
79 
88 void oc_rep_encode_raw(const uint8_t *data, size_t len);
89 
98 void oc_rep_encode_raw_encoder(CborEncoder *encoder, const uint8_t *data,
99  size_t len);
100 
108 int oc_rep_add_line_to_buffer(const char *line);
109 
118 int oc_rep_add_line_size_to_buffer(const char *line, int len);
119 
125 #define oc_rep_object(name) &name##_map
126 
132 #define oc_rep_array(name) &name##_array
133 
151 #define oc_rep_set_double(object, key, value) \
152  do { \
153  g_err |= cbor_encode_text_string(&object##_map, #key, strlen(#key)); \
154  g_err |= cbor_encode_double(&object##_map, value); \
155  } while (0)
156 
176 #define oc_rep_i_set_double(object, key, value) \
177  do { \
178  g_err |= cbor_encode_int(&object##_map, (int64_t)(key)); \
179  g_err |= cbor_encode_double(&object##_map, value); \
180  } while (0)
181 
199 #define oc_rep_set_float(object, key, value) \
200  do { \
201  g_err |= cbor_encode_text_string(&object##_map, #key, strlen(#key)); \
202  g_err |= cbor_encode_float(&object##_map, value); \
203  } while (0)
204 
224 #define oc_rep_i_set_float(object, key, value) \
225  do { \
226  g_err |= cbor_encode_int(&object##_map, (int64_t)(key)); \
227  g_err |= cbor_encode_float(&object##_map, value); \
228  } while (0)
229 
249 #define oc_rep_set_int(object, key, value) \
250  do { \
251  g_err |= cbor_encode_text_string(&object##_map, #key, strlen(#key)); \
252  g_err |= cbor_encode_int(&object##_map, value); \
253  } while (0)
254 
274 #define oc_rep_i_set_int(object, key, value) \
275  do { \
276  g_err |= cbor_encode_int(&object##_map, (int64_t)(key)); \
277  g_err |= cbor_encode_int(&object##_map, value); \
278  } while (0)
279 
301 #define oc_rep_set_uint(object, key, value) \
302  do { \
303  g_err |= cbor_encode_text_string(&object##_map, #key, strlen(#key)); \
304  g_err |= cbor_encode_uint(&object##_map, value); \
305  } while (0)
306 
328 #define oc_rep_i_set_uint(object, key, value) \
329  do { \
330  g_err |= cbor_encode_int(&object##_map, (int64_t)(key)); \
331  g_err |= cbor_encode_uint(&object##_map, value); \
332  } while (0)
333 
353 #define oc_rep_set_boolean(object, key, value) \
354  do { \
355  g_err |= cbor_encode_text_string(&object##_map, #key, strlen(#key)); \
356  g_err |= cbor_encode_boolean(&object##_map, value); \
357  } while (0)
358 
378 #define oc_rep_i_set_boolean(object, key, value) \
379  do { \
380  g_err |= cbor_encode_int(&object##_map, (int64_t)(key)); \
381  g_err |= cbor_encode_boolean(&object##_map, value); \
382  } while (0)
383 
401 #define oc_rep_set_text_string(object, key, value) \
402  do { \
403  g_err |= cbor_encode_text_string(&object##_map, #key, strlen(#key)); \
404  if ((const char *)(value) != NULL) { \
405  g_err |= cbor_encode_text_string(&object##_map, value, strlen(value)); \
406  } else { \
407  g_err |= cbor_encode_text_string(&object##_map, "", 0); \
408  } \
409  } while (0)
410 
428 #define oc_rep_i_set_text_string(object, key, value) \
429  do { \
430  g_err |= cbor_encode_int(&object##_map, (int64_t)(key)); \
431  if ((const char *)(value) != NULL) { \
432  g_err |= cbor_encode_text_string(&object##_map, value, strlen(value)); \
433  } else { \
434  g_err |= cbor_encode_text_string(&object##_map, "", 0); \
435  } \
436  } while (0)
437 
455 #define oc_rep_set_text_string_no_tag(object, value) \
456  do { \
457  if ((const char *)(value) != NULL) { \
458  g_err |= cbor_encode_text_string(&object##_map, value, strlen(value)); \
459  } else { \
460  g_err |= cbor_encode_text_string(&object##_map, "", 0); \
461  } \
462  } while (0)
463 
485 #define oc_rep_set_byte_string(object, key, value, length) \
486  do { \
487  g_err |= cbor_encode_text_string(&object##_map, #key, strlen(#key)); \
488  g_err |= cbor_encode_byte_string(&object##_map, value, length); \
489  } while (0)
490 
512 #define oc_rep_i_set_byte_string(object, key, value, length) \
513  do { \
514  g_err |= cbor_encode_int(&object##_map, (int64_t)(key)); \
515  g_err |= cbor_encode_byte_string(&object##_map, value, length); \
516  } while (0)
517 
526 #define oc_rep_start_array(parent, name) oc_rep_begin_array(parent, name)
527 
573 #define oc_rep_begin_array(parent, name) \
574  do { \
575  CborEncoder name##_array; \
576  g_err |= \
577  cbor_encoder_create_array(parent, &name##_array, CborIndefiniteLength)
578 
587 #define oc_rep_end_array(parent, name) \
588  g_err |= cbor_encoder_close_container(parent, &name##_array); \
589  } \
590  while (0)
591 
592 #define oc_rep_start_links_array() oc_rep_begin_links_array()
593 
594 #define oc_rep_begin_links_array() \
595  g_err |= \
596  cbor_encoder_create_array(&g_encoder, &links_array, CborIndefiniteLength)
597 
598 #define oc_rep_end_links_array() \
599  g_err |= cbor_encoder_close_container(&g_encoder, &links_array)
600 
607 #define oc_rep_begin_root_object() \
608  g_err |= cbor_encoder_create_map(&g_encoder, &root_map, CborIndefiniteLength)
609 
616 #define oc_rep_begin_root() \
617  g_err |= cbor_encoder_create_map(&g_encoder, &root_map, CborIndefiniteLength)
618 
624 #define oc_rep_end_root_object() \
625  g_err |= cbor_encoder_close_container(&g_encoder, &root_map)
626 
660 #define oc_rep_add_byte_string(parent, value, value_len) \
661  g_err |= cbor_encode_byte_string(&parent##_array, value, value_len)
662 
663 #define oc_rep_set_value_byte_string(parent, value, value_len) \
664  g_err |= cbor_encode_byte_string(&parent##_map, value, value_len)
665 
707 #define oc_rep_add_text_string(parent, value) \
708  do { \
709  if ((const char *)(value) != NULL) { \
710  g_err |= cbor_encode_text_string(&parent##_array, value, strlen(value)); \
711  } else { \
712  g_err |= cbor_encode_text_string(&parent##_array, "", 0); \
713  } \
714  } while (0)
715 
716 /* map */
717 #define oc_rep_set_value_text_string(parent, value) \
718  do { \
719  if ((const char *)(value) != NULL) { \
720  g_err |= cbor_encode_text_string(&parent##_map, value, strlen(value)); \
721  } else { \
722  g_err |= cbor_encode_text_string(&parent##_map, "", 0); \
723  } \
724  } while (0)
725 
760 #define oc_rep_add_float(parent, value) \
761  g_err |= cbor_encode_float(&parent##_array, value)
762 
763 #define oc_rep_set_value_float(parent, value) \
764  g_err |= cbor_encode_float(&parent##_map, value)
765 
800 #define oc_rep_add_double(parent, value) \
801  g_err |= cbor_encode_double(&parent##_array, value)
802 
803 #define oc_rep_set_value_double(parent, value) \
804  g_err |= cbor_encode_double(&parent##_map, value)
805 
838 #define oc_rep_add_int(parent, value) \
839  g_err |= cbor_encode_int(&parent##_array, value)
840 
841 #define oc_rep_set_value_int(parent, value) \
842  g_err |= cbor_encode_int(&parent##_map, value)
843 
876 #define oc_rep_add_boolean(parent, value) \
877  g_err |= cbor_encode_boolean(&parent##_array, value)
878 #define oc_rep_set_value_boolean(parent, value) \
879  g_err |= cbor_encode_boolean(&parent##_map, value)
880 
894 #define oc_rep_set_key(parent, key) \
895  if ((const char *)(key) != NULL) \
896  g_err |= cbor_encode_text_string(parent, key, strlen(key))
897 
911 #define oc_rep_i_set_key(parent, key) \
912  if ((uint64_t)(key) != 0) \
913  g_err |= cbor_encode_int(parent, (int64_t)(key));
914 
921 #define oc_rep_set_array(object, key) oc_rep_open_array(object, key)
922 
936 #define oc_rep_open_array(parent, key) \
937  g_err |= cbor_encode_text_string(&parent##_map, #key, strlen(#key)); \
938  oc_rep_begin_array(&parent##_map, key)
939 
946 #define oc_rep_close_array(parent, key) oc_rep_end_array(&parent##_map, key)
947 
954 #define oc_rep_start_object(parent, key) oc_rep_begin_object(parent, key)
955 
956 #define oc_rep_begin_object(parent, key) \
957  do { \
958  CborEncoder key##_map; \
959  g_err |= cbor_encoder_create_map(parent, &key##_map, CborIndefiniteLength)
960 
967 #define oc_rep_end_object(parent, key) \
968  g_err |= cbor_encoder_close_container(parent, &key##_map); \
969  } \
970  while (0)
971 
978 #define oc_rep_object_array_start_item(key) oc_rep_object_array_begin_item(key)
979 
1022 #define oc_rep_object_array_begin_item(key) \
1023  oc_rep_begin_object(&key##_array, key)
1024 
1028 #define oc_rep_object_array_end_item(key) oc_rep_end_object(&key##_array, key)
1029 
1036 #define oc_rep_set_object(object, key) oc_rep_open_object(object, key)
1037 
1067 #define oc_rep_open_object(parent, key) \
1068  g_err |= cbor_encode_text_string(&parent##_map, #key, strlen(#key)); \
1069  oc_rep_begin_object(&parent##_map, key)
1070 
1077 #define oc_rep_close_object(parent, key) oc_rep_end_object(&parent##_map, key)
1078 
1103 #define oc_rep_set_int_array(object, key, values, length) \
1104  do { \
1105  g_err |= cbor_encode_text_string(&object##_map, #key, strlen(#key)); \
1106  CborEncoder key##_value_array; \
1107  g_err |= \
1108  cbor_encoder_create_array(&object##_map, &key##_value_array, length); \
1109  int i; \
1110  for (i = 0; i < (length); i++) { \
1111  g_err |= cbor_encode_int(&key##_value_array, (values)[i]); \
1112  } \
1113  g_err |= cbor_encoder_close_container(&object##_map, &key##_value_array); \
1114  } while (0)
1115 
1140 #define oc_rep_i_set_int_array(object, key, values, length) \
1141  do { \
1142  g_err |= cbor_encode_int(&object##_map, (int64_t)(key)); \
1143  CborEncoder x_key##_value_array; \
1144  g_err |= \
1145  cbor_encoder_create_array(&object##_map, &x_key##_value_array, length); \
1146  int i; \
1147  for (i = 0; i < (length); i++) { \
1148  g_err |= cbor_encode_int(&x_key##_value_array, (values)[i]); \
1149  } \
1150  g_err |= \
1151  cbor_encoder_close_container(&object##_map, &x_key##_value_array); \
1152  } while (0)
1153 
1178 #define oc_rep_set_bool_array(object, key, values, length) \
1179  do { \
1180  g_err |= cbor_encode_text_string(&object##_map, #key, strlen(#key)); \
1181  CborEncoder key##_value_array; \
1182  g_err |= \
1183  cbor_encoder_create_array(&object##_map, &key##_value_array, length); \
1184  int i; \
1185  for (i = 0; i < (length); i++) { \
1186  g_err |= cbor_encode_boolean(&key##_value_array, (values)[i]); \
1187  } \
1188  g_err |= cbor_encoder_close_container(&object##_map, &key##_value_array); \
1189  } while (0)
1190 
1215 #define oc_rep_i_set_bool_array(object, key, values, length) \
1216  do { \
1217  g_err |= cbor_encode_int(&object##_map, (int64_t)(key)); \
1218  CborEncoder x_key##_value_array; \
1219  g_err |= \
1220  cbor_encoder_create_array(&object##_map, &x_key##_value_array, length); \
1221  int i; \
1222  for (i = 0; i < (length); i++) { \
1223  g_err |= cbor_encode_boolean(&x_key##_value_array, (values)[i]); \
1224  } \
1225  g_err |= \
1226  cbor_encoder_close_container(&object##_map, &x_key##_value_array); \
1227  } while (0)
1228 
1254 #define oc_rep_set_float_array(object, key, values, length) \
1255  do { \
1256  g_err |= cbor_encode_text_string(&object##_map, #key, strlen(#key)); \
1257  CborEncoder key##_value_array; \
1258  g_err |= \
1259  cbor_encoder_create_array(&object##_map, &key##_value_array, length); \
1260  int i; \
1261  for (i = 0; i < (length); i++) { \
1262  g_err |= cbor_encode_floating_point(&key##_value_array, CborFloatType, \
1263  &(values)[i]); \
1264  } \
1265  g_err |= cbor_encoder_close_container(&object##_map, &key##_value_array); \
1266  } while (0)
1267 
1295 #define oc_rep_i_set_float_array(object, key, values, length) \
1296  do { \
1297  g_err |= cbor_encode_int(&object##_map, (int64_t)(key)); \
1298  CborEncoder x_key##_value_array; \
1299  g_err |= \
1300  cbor_encoder_create_array(&object##_map, &x_key##_value_array, length); \
1301  int i; \
1302  for (i = 0; i < (length); i++) { \
1303  g_err |= cbor_encode_floating_point(&x_key##_value_array, CborFloatType, \
1304  &(values)[i]); \
1305  } \
1306  g_err |= \
1307  cbor_encoder_close_container(&object##_map, &x_key##_value_array); \
1308  } while (0)
1309 
1335 #define oc_rep_set_double_array(object, key, values, length) \
1336  do { \
1337  g_err |= cbor_encode_text_string(&object##_map, #key, strlen(#key)); \
1338  CborEncoder key##_value_array; \
1339  g_err |= \
1340  cbor_encoder_create_array(&object##_map, &key##_value_array, length); \
1341  int i; \
1342  for (i = 0; i < (length); i++) { \
1343  g_err |= cbor_encode_floating_point(&key##_value_array, CborDoubleType, \
1344  &(values)[i]); \
1345  } \
1346  g_err |= cbor_encoder_close_container(&object##_map, &key##_value_array); \
1347  } while (0)
1348 
1376 #define oc_rep_i_set_double_array(object, key, values, length) \
1377  do { \
1378  g_err |= cbor_encode_int(&object##_map, (int64_t)(key)); \
1379  CborEncoder x_key##_value_array; \
1380  g_err |= \
1381  cbor_encoder_create_array(&object##_map, &x_key##_value_array, length); \
1382  int i; \
1383  for (i = 0; i < (length); i++) { \
1384  g_err |= cbor_encode_floating_point(&x_key##_value_array, \
1385  CborDoubleType, &(values)[i]); \
1386  } \
1387  g_err |= \
1388  cbor_encoder_close_container(&object##_map, &x_key##_value_array); \
1389  } while (0)
1390 
1437 #define oc_rep_set_string_array(object, key, values) \
1438  do { \
1439  g_err |= cbor_encode_text_string(&object##_map, #key, strlen(#key)); \
1440  CborEncoder key##_value_array; \
1441  g_err |= cbor_encoder_create_array(&object##_map, &key##_value_array, \
1442  CborIndefiniteLength); \
1443  int i; \
1444  for (i = 0; i < (int)oc_string_array_get_allocated_size(values); i++) { \
1445  if (oc_string_array_get_item_size(values, i) > 0) { \
1446  g_err |= cbor_encode_text_string( \
1447  &key##_value_array, oc_string_array_get_item(values, i), \
1448  oc_string_array_get_item_size(values, i)); \
1449  } \
1450  } \
1451  g_err |= cbor_encoder_close_container(&object##_map, &key##_value_array); \
1452  } while (0)
1453 
1479 #define oc_rep_set_float_array(object, key, values, length) \
1480  do { \
1481  g_err |= cbor_encode_text_string(&object##_map, #key, strlen(#key)); \
1482  CborEncoder key##_value_array; \
1483  g_err |= \
1484  cbor_encoder_create_array(&object##_map, &key##_value_array, length); \
1485  int i; \
1486  for (i = 0; i < (length); i++) { \
1487  g_err |= cbor_encode_floating_point(&key##_value_array, CborFloatType, \
1488  &(values)[i]); \
1489  } \
1490  g_err |= cbor_encoder_close_container(&object##_map, &key##_value_array); \
1491  } while (0)
1492 
1520 #define oc_rep_i_set_float_array(object, key, values, length) \
1521  do { \
1522  g_err |= cbor_encode_int(&object##_map, (int64_t)(key)); \
1523  CborEncoder x_key##_value_array; \
1524  g_err |= \
1525  cbor_encoder_create_array(&object##_map, &x_key##_value_array, length); \
1526  int i; \
1527  for (i = 0; i < (length); i++) { \
1528  g_err |= cbor_encode_floating_point(&x_key##_value_array, CborFloatType, \
1529  &(values)[i]); \
1530  } \
1531  g_err |= \
1532  cbor_encoder_close_container(&object##_map, &x_key##_value_array); \
1533  } while (0)
1534 
1581 #define oc_rep_i_set_string_array(object, key, values) \
1582  do { \
1583  g_err |= cbor_encode_int(&object##_map, (int64_t)(key)); \
1584  CborEncoder x_key##_value_array; \
1585  g_err |= cbor_encoder_create_array(&object##_map, &x_key##_value_array, \
1586  CborIndefiniteLength); \
1587  int i; \
1588  for (i = 0; i < (int)oc_string_array_get_allocated_size(values); i++) { \
1589  if (oc_string_array_get_item_size(values, i) > 0) { \
1590  g_err |= cbor_encode_text_string( \
1591  &x_key##_value_array, oc_string_array_get_item(values, i), \
1592  oc_string_array_get_item_size(values, i)); \
1593  } \
1594  } \
1595  g_err |= \
1596  cbor_encoder_close_container(&object##_map, &x_key##_value_array); \
1597  } while (0)
1598 
1610 CborError oc_rep_get_cbor_errno(void);
1611 
1612 typedef enum {
1613  OC_REP_NIL = 0,
1614  OC_REP_INT = 0x01,
1615  OC_REP_DOUBLE = 0x02,
1616  OC_REP_BOOL = 0x03,
1617  OC_REP_BYTE_STRING = 0x04,
1618  OC_REP_STRING = 0x05,
1619  OC_REP_OBJECT = 0x06,
1620  OC_REP_FLOAT = 0x07,
1621  // this may be used as a bitmask: OC_REP_INT_ARRAY = OC_REP_INT | OC_REP_ARRAY
1622  OC_REP_ARRAY = 0x10,
1623  OC_REP_INT_ARRAY = 0x11,
1624  OC_REP_DOUBLE_ARRAY = 0x12,
1625  OC_REP_BOOL_ARRAY = 0x13,
1626  OC_REP_BYTE_STRING_ARRAY = 0x14,
1627  OC_REP_STRING_ARRAY = 0x15,
1628  OC_REP_OBJECT_ARRAY = 0x16,
1629  OC_REP_FLOAT_ARRAY = 0x17,
1630  OC_REP_MIXED_ARRAY = 0x1f,
1631 } oc_rep_value_type_t;
1632 
1641 typedef struct oc_rep_s
1642 {
1643  oc_rep_value_type_t type;
1644  struct oc_rep_s *next;
1645  oc_string_t name;
1646  int iname;
1647  union oc_rep_value {
1648  int64_t integer;
1649  bool boolean;
1650  float float_p;
1651  double double_p;
1652  oc_string_t string;
1653  oc_array_t array;
1654  struct oc_rep_s *object;
1655  struct oc_rep_s *object_array;
1656  struct oc_rep_s *mixed_array;
1657  } value;
1659 
1660 // internal function
1661 void oc_rep_set_pool(struct oc_memb *rep_objects_pool);
1662 
1663 // internal function
1664 int oc_parse_rep(const uint8_t *payload, int payload_size,
1665  oc_rep_t **value_list);
1666 
1667 // internal function
1668 void oc_free_rep(oc_rep_t *rep);
1669 
1690 bool oc_rep_get_int(oc_rep_t *rep, const char *key, int64_t *value);
1691 
1712 bool oc_rep_i_get_int(oc_rep_t *rep, int key, int64_t *value);
1713 
1734 bool oc_rep_get_bool(oc_rep_t *rep, const char *key, bool *value);
1735 
1756 bool oc_rep_i_get_bool(oc_rep_t *rep, int key, bool *value);
1757 
1777 bool oc_rep_get_float(oc_rep_t *rep, const char *key, float *value);
1778 
1798 bool oc_rep_i_get_float(oc_rep_t *rep, int key, float *value);
1799 
1819 bool oc_rep_get_double(oc_rep_t *rep, const char *key, double *value);
1820 
1840 bool oc_rep_i_get_double(oc_rep_t *rep, int key, double *value);
1841 
1864 bool oc_rep_get_byte_string(oc_rep_t *rep, const char *key, char **value,
1865  size_t *size);
1866 
1889 bool oc_rep_i_get_byte_string(oc_rep_t *rep, int key, char **value,
1890  size_t *size);
1891 
1914 bool oc_rep_get_string(oc_rep_t *rep, const char *key, char **value,
1915  size_t *size);
1916 
1940 bool oc_rep_i_get_string(oc_rep_t *rep, int key, char **value, size_t *size);
1941 
1963 bool oc_rep_get_int_array(oc_rep_t *rep, const char *key, int64_t **value,
1964  size_t *size);
1965 
1987 bool oc_rep_i_get_int_array(oc_rep_t *rep, int key, int64_t **value,
1988  size_t *size);
1989 
2011 bool oc_rep_get_bool_array(oc_rep_t *rep, const char *key, bool **value,
2012  size_t *size);
2013 
2035 bool oc_rep_i_get_bool_array(oc_rep_t *rep, int key, bool **value,
2036  size_t *size);
2037 
2062 bool oc_rep_get_float_array(oc_rep_t *rep, const char *key, float **value,
2063  size_t *size);
2064 
2089 bool oc_rep_i_get_float_array(oc_rep_t *rep, int key, float **value,
2090  size_t *size);
2091 
2116 bool oc_rep_get_double_array(oc_rep_t *rep, const char *key, double **value,
2117  size_t *size);
2118 
2143 bool oc_rep_i_get_double_array(oc_rep_t *rep, int key, double **value,
2144  size_t *size);
2145 
2177 bool oc_rep_get_byte_string_array(oc_rep_t *rep, const char *key,
2178  oc_string_array_t *value, size_t *size);
2179 
2212  oc_string_array_t *value, size_t *size);
2213 
2246 bool oc_rep_get_string_array(oc_rep_t *rep, const char *key,
2247  oc_string_array_t *value, size_t *size);
2248 
2281 bool oc_rep_i_get_string_array(oc_rep_t *rep, int key, oc_string_array_t *value,
2282  size_t *size);
2311 bool oc_rep_get_object(oc_rep_t *rep, const char *key, oc_rep_t **value);
2312 
2342 
2380 bool oc_rep_get_object_array(oc_rep_t *rep, const char *key, oc_rep_t **value);
2381 
2420 
2452 bool oc_rep_get_mixed_array(oc_rep_t *rep, const char *key, oc_rep_t **value);
2453 
2486 
2490 #define OC_PRETTY_PRINT_TAB_CHARACTER " "
2491 
2535 size_t oc_rep_to_json(oc_rep_t *rep, char *buf, size_t buf_size,
2536  bool pretty_print);
2537 
2546 void oc_print_rep_as_json(oc_rep_t *rep, bool pretty_print);
2547 
2548 size_t py_oc_rep_to_json(oc_rep_t *rep, char *buf, size_t buf_size,
2549  bool pretty_print);
2550 
2551 #ifdef __cplusplus
2552 }
2553 #endif
2554 
2555 #endif /* OC_REP_H */
generic helpers
bool oc_rep_get_string(oc_rep_t *rep, const char *key, char **value, size_t *size)
Read a text string value from an oc_rep_t
bool oc_rep_i_get_float_array(oc_rep_t *rep, int key, float **value, size_t *size)
Read an float array value from an oc_rep_t with an integer key.
bool oc_rep_i_get_byte_string_array(oc_rep_t *rep, int key, oc_string_array_t *value, size_t *size)
Read an byte string array value from an oc_rep_t with integer key.
bool oc_rep_i_get_float(oc_rep_t *rep, int key, float *value)
Read a float value from an oc_rep_t
bool oc_rep_i_get_bool(oc_rep_t *rep, int key, bool *value)
Read a boolean value from an oc_rep_t with key as integer.
bool oc_rep_i_get_string(oc_rep_t *rep, int key, char **value, size_t *size)
Read a text string value from an oc_rep_t with integer key.
bool oc_rep_get_double_array(oc_rep_t *rep, const char *key, double **value, size_t *size)
Read an double array value from an oc_rep_t
bool oc_rep_get_object(oc_rep_t *rep, const char *key, oc_rep_t **value)
Read a object value from an oc_rep_t
int oc_rep_add_line_to_buffer(const char *line)
add a line to the response buffer note updates the occupied size in the response buffer
bool oc_rep_get_float_array(oc_rep_t *rep, const char *key, float **value, size_t *size)
Read an float array value from an oc_rep_t
bool oc_rep_i_get_double_array(oc_rep_t *rep, int key, double **value, size_t *size)
Read an double array value from an oc_rep_t with an integer key.
int oc_rep_add_line_size_to_buffer(const char *line, int len)
add a line to the response buffer note updates the occupied size in the response buffer
void oc_print_rep_as_json(oc_rep_t *rep, bool pretty_print)
prints the response tree as JSON to the output pretty_print: true: nicely formatted JSON on multiple ...
bool oc_rep_i_get_byte_string(oc_rep_t *rep, int key, char **value, size_t *size)
Read a byte string value from an oc_rep_t with an integer key.
const uint8_t * oc_rep_get_encoder_buf(void)
Get the buffer pointer at the start of the encoded cbor data.
bool oc_rep_i_get_mixed_array(oc_rep_t *rep, int key, oc_rep_t **value)
Read a mixed array value from an oc_rep_t with integer key.
bool oc_rep_i_get_object_array(oc_rep_t *rep, int key, oc_rep_t **value)
Read a object array value from an oc_rep_t with integer key.
void oc_rep_new(uint8_t *payload, int size)
Initialize the buffer used to hold the cbor encoded data.
bool oc_rep_get_string_array(oc_rep_t *rep, const char *key, oc_string_array_t *value, size_t *size)
Read a string array value from an oc_rep_t
bool oc_rep_get_int_array(oc_rep_t *rep, const char *key, int64_t **value, size_t *size)
Read an integer array value from an oc_rep_t
bool oc_rep_get_byte_string(oc_rep_t *rep, const char *key, char **value, size_t *size)
Read a byte string value from an oc_rep_t
bool oc_rep_get_mixed_array(oc_rep_t *rep, const char *key, oc_rep_t **value)
Read a mixed array value from an oc_rep_t
bool oc_rep_i_get_bool_array(oc_rep_t *rep, int key, bool **value, size_t *size)
Read an boolean array value from an oc_rep_t with integer key.
void oc_rep_encode_raw(const uint8_t *data, size_t len)
Encode raw data, as if it was already encoded.
bool oc_rep_i_get_int_array(oc_rep_t *rep, int key, int64_t **value, size_t *size)
Read an integer array value from an oc_rep_t with an integer key.
bool oc_rep_get_bool_array(oc_rep_t *rep, const char *key, bool **value, size_t *size)
Read an boolean array value from an oc_rep_t
bool oc_rep_get_object_array(oc_rep_t *rep, const char *key, oc_rep_t **value)
Read a object array value from an oc_rep_t
bool oc_rep_i_get_int(oc_rep_t *rep, int key, int64_t *value)
Read an integer from an oc_rep_t with an integer as key.
bool oc_rep_i_get_string_array(oc_rep_t *rep, int key, oc_string_array_t *value, size_t *size)
Read a string array value from an oc_rep_t with integer key.
bool oc_rep_get_byte_string_array(oc_rep_t *rep, const char *key, oc_string_array_t *value, size_t *size)
Read an byte string array value from an oc_rep_t
bool oc_rep_get_int(oc_rep_t *rep, const char *key, int64_t *value)
Read an integer from an oc_rep_t
void oc_rep_encode_raw_encoder(CborEncoder *encoder, const uint8_t *data, size_t len)
Encode raw data, as if it was already encoded.
size_t oc_rep_to_json(oc_rep_t *rep, char *buf, size_t buf_size, bool pretty_print)
Convert an oc_rep_t to JSON encoded string.
int oc_rep_get_encoded_payload_size(void)
Get the size of the cbor encoded data.
struct oc_rep_s oc_rep_t
parsed entry of a cbor object This represents a link list of response values one can iterate over the...
CborError oc_rep_get_cbor_errno(void)
Called after any oc_rep_set_*, oc_rep_start_*, oc_rep_begin_*, oc_rep_end_*, oc_rep_add_*,...
bool oc_rep_i_get_double(oc_rep_t *rep, int key, double *value)
Read a double value from an oc_rep_t
bool oc_rep_get_double(oc_rep_t *rep, const char *key, double *value)
Read a double value from an oc_rep_t
bool oc_rep_get_bool(oc_rep_t *rep, const char *key, bool *value)
Read a boolean value from an oc_rep_t
bool oc_rep_i_get_object(oc_rep_t *rep, int key, oc_rep_t **value)
Read a object value from an oc_rep_t with integer key.
bool oc_rep_get_float(oc_rep_t *rep, const char *key, float *value)
Read a float value from an oc_rep_t
parsed entry of a cbor object This represents a link list of response values one can iterate over the...
Definition: oc_rep.h:1642
oc_rep_value_type_t type
type of the data
Definition: oc_rep.h:1643
oc_string_t name
name of the tag
Definition: oc_rep.h:1645
union oc_rep_s::oc_rep_value value
the value as union
struct oc_rep_s * next
next in list
Definition: oc_rep.h:1644
int iname
integer (identifier) as tag name
Definition: oc_rep.h:1646