static void test_JSON(char * testBuf, size_t testLen, char * id) { lwm2m_data_t * tlvP; int size; int length; uint8_t * buffer; lwm2m_media_type_t format = LWM2M_CONTENT_JSON; size = lwm2m_data_parse((uint8_t *)testBuf, testLen, format, &tlvP); if (size <= 0) { printf("\n\nJSON buffer %s decoding failed !\n", id); return; } else printf("\n\nJSON buffer %s decoding:\n", id); dump_tlv(stdout, size, tlvP, 0); length = lwm2m_data_serialize(size, tlvP, &format, &buffer); dump_json(buffer, length); lwm2m_data_free(size, tlvP); lwm2m_free(buffer); }
void json (char *file) { FN; Tree_s *tree; open_file(file); tree = object(); if (tree) { printf("is Object\n"); } else { printf("is not object\n"); } close_file(); dump_json(tree); pr_json(tree); }
static void test_TLV(char * testBuf, size_t testLen, char * id) { lwm2m_data_t * tlvP; int size; int length; uint8_t * buffer; lwm2m_media_type_t format = LWM2M_CONTENT_TLV; printf("Buffer %s:\n", id); decode(testBuf, testLen, 0); printf("\n\nBuffer %s using lwm2m_data_t:\n", id); size = lwm2m_data_parse((uint8_t *)testBuf, testLen, format, &tlvP); dump_tlv(stdout, size, tlvP, 0); length = lwm2m_data_serialize(size, tlvP, &format, &buffer); if (length != testLen) { printf("\n\nSerialize Buffer %s to TLV failed: %d bytes instead of %d\n", id, length, testLen); } else if (memcmp(buffer, testBuf, length) != 0) { printf("\n\nSerialize Buffer %s to TLV failed:\n", id); output_buffer(stdout, buffer, length, 0); printf("\ninstead of:\n"); output_buffer(stdout, testBuf, length, 0); } else { printf("\n\nSerialize Buffer %s to TLV OK\n", id); } lwm2m_free(buffer); format = LWM2M_CONTENT_JSON; length = lwm2m_data_serialize(size, tlvP, &format, &buffer); if (length <= 0) { printf("\n\nSerialize Buffer %s to JSON failed.\n", id); } else { dump_json(buffer, length); lwm2m_free(buffer); } lwm2m_data_free(size, tlvP); }