static int64_t OCTagsPayloadToCbor(OCTagsPayload *tags, CborEncoder *setMap) { CborEncoder tagsMap; int64_t cborEncoderResult = CborNoError; cborEncoderResult |= cbor_encoder_create_map(setMap, &tagsMap, CborIndefiniteLength); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create tags map"); cborEncoderResult |= ConditionalAddTextStringToMap(&tagsMap, OC_RSRVD_DEVICE_NAME, tags->n.deviceName); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_DEVICE_NAME in tags map"); cborEncoderResult |= ConditionalAddTextStringToMap(&tagsMap, OC_RSRVD_DEVICE_ID, (char *)tags->di.id); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_DEVICE_ID in tags map"); cborEncoderResult |= ConditionalAddTextStringToMap(&tagsMap, OC_RSRVD_RTS, tags->rts); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_RTS in tags map"); cborEncoderResult |= ConditionalAddTextStringToMap(&tagsMap, OC_RSRVD_DREL, tags->drel); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_DREL in tags map"); cborEncoderResult |= ConditionalAddTextStringToMap(&tagsMap, OC_RSRVD_BASE_URI, tags->baseURI); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_BASE_URI in tags map"); { uint64_t value = tags->bitmap; cborEncoderResult |= ConditionalAddIntToMap(&tagsMap, OC_RSRVD_BITMAP, &value); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_BITMAP in tags map"); value = tags->port; cborEncoderResult |= ConditionalAddIntToMap(&tagsMap, OC_RSRVD_HOSTING_PORT, &value); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_HOSTING_PORT in tags map"); value = tags->ins; cborEncoderResult |= ConditionalAddIntToMap(&tagsMap, OC_RSRVD_INS, &value); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_INS in tags map"); value = tags->ttl; cborEncoderResult |= ConditionalAddIntToMap(&tagsMap, OC_RSRVD_TTL, &value); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_TTL in tags map"); } cborEncoderResult |= cbor_encoder_close_container(setMap, &tagsMap); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to close container"); exit: return cborEncoderResult; }
static int64_t OCLinksPayloadToCbor(OCLinksPayload *rtPtr, CborEncoder *setMap) { CborEncoder linksArray; int64_t cborEncoderResult = CborNoError; cborEncoderResult |= cbor_encoder_create_array(setMap, &linksArray, CborIndefiniteLength); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create Links array"); while (rtPtr) { CborEncoder linksMap; cborEncoderResult |= cbor_encoder_create_map(&linksArray, &linksMap, CborIndefiniteLength); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create Links map"); cborEncoderResult |= ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_HREF, rtPtr->href); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_HREF in Links map"); cborEncoderResult|= ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_REL, rtPtr->rel); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_REL in Links map"); cborEncoderResult |= ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_TITLE, rtPtr->title); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_TITLE in Links map"); cborEncoderResult |= ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_URI, rtPtr->uri); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_URI in Links map"); cborEncoderResult |= AddStringLLToMap(&linksMap, OC_RSRVD_RESOURCE_TYPE, rtPtr->rt); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_RT in Links map"); cborEncoderResult |= AddStringLLToMap(&linksMap, OC_RSRVD_INTERFACE, rtPtr->itf); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_ITF in Links map"); cborEncoderResult |= AddStringLLToMap(&linksMap, OC_RSRVD_MEDIA_TYPE, rtPtr->mt); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_MT in Links map"); { uint64_t value = rtPtr->ins; cborEncoderResult |= ConditionalAddIntToMap(&linksMap, OC_RSRVD_INS, &value); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_INS in Links map"); } cborEncoderResult |= cbor_encoder_close_container(&linksArray, &linksMap); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing Links map"); rtPtr = rtPtr->next; } cborEncoderResult |= cbor_encoder_close_container(setMap, &linksArray); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing links array"); exit: return cborEncoderResult; }
static int64_t OCTagsPayloadToCbor(OCTagsPayload *tags, CborEncoder *setMap) { int64_t cborEncoderResult = CborNoError; cborEncoderResult |= ConditionalAddTextStringToMap(setMap, OC_RSRVD_DEVICE_NAME, tags->n.deviceName); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_DEVICE_NAME in tags map"); cborEncoderResult |= ConditionalAddTextStringToMap(setMap, OC_RSRVD_DEVICE_ID, (char *)tags->di.id); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_DEVICE_ID in tags map"); cborEncoderResult |= ConditionalAddIntToMap(setMap, OC_RSRVD_DEVICE_TTL, &tags->ttl); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_TTL in tags map"); exit: return cborEncoderResult; }
int64_t OCRDPayloadToCbor(const OCRDPayload *rdPayload, uint8_t *outPayload, size_t *size) { if (!outPayload || !size) { OC_LOG(ERROR, TAG, "Invalid parameters."); return OC_STACK_INVALID_PARAM; } CborEncoder encoder; int flags = 0; cbor_encoder_init(&encoder, outPayload, *size, flags); CborEncoder rootArray; CborError cborEncoderResult; cborEncoderResult = cbor_encoder_create_array(&encoder, &rootArray, CBOR_ROOT_ARRAY_LENGTH); if (CborNoError != cborEncoderResult) { OC_LOG(ERROR, TAG, "Failed creating cbor array."); goto cbor_error; } if (rdPayload->rdDiscovery) { CborEncoder map; cborEncoderResult = cbor_encoder_create_map(&rootArray, &map, CborIndefiniteLength); if (CborNoError != cborEncoderResult) { OC_LOG(ERROR, TAG, "Failed creating discovery map."); goto cbor_error; } if (CborNoError != ConditionalAddTextStringToMap(&map, OC_RSRVD_DEVICE_NAME, sizeof(OC_RSRVD_DEVICE_NAME) - 1, (char *)rdPayload->rdDiscovery->n.deviceName)) { OC_LOG(ERROR, TAG, "Failed setting OC_RSRVD_DEVICE_NAME."); goto cbor_error; } if (CborNoError != ConditionalAddTextStringToMap(&map, OC_RSRVD_DEVICE_ID, sizeof(OC_RSRVD_DEVICE_ID) - 1, (char *)rdPayload->rdDiscovery->di.id)) { OC_LOG(ERROR, TAG, "Failed setting OC_RSRVD_DEVICE_ID."); goto cbor_error; } uint64_t sel = (uint8_t) rdPayload->rdDiscovery->sel; if (CborNoError != ConditionalAddIntToMap(&map, OC_RSRVD_RD_DISCOVERY_SEL, sizeof(OC_RSRVD_RD_DISCOVERY_SEL) - 1, &sel)) { OC_LOG(ERROR, TAG, "Failed setting OC_RSRVD_RD_DISCOVERY_SEL."); goto cbor_error; } cborEncoderResult = cbor_encoder_close_container(&rootArray, &map); if (CborNoError != cborEncoderResult) { OC_LOG(ERROR, TAG, "Failed closing discovery map."); goto cbor_error; } } else if (rdPayload->rdPublish) { CborEncoder colArray; cborEncoderResult = cbor_encoder_create_array(&rootArray, &colArray, CborIndefiniteLength); if (CborNoError != cborEncoderResult) { OC_LOG(ERROR, TAG, "Failed creating collection array."); goto cbor_error; } OCResourceCollectionPayload *rdPublish = rdPayload->rdPublish; while (rdPublish) { if (OC_STACK_OK != OCTagsPayloadToCbor(rdPublish->tags, &colArray)) { OC_LOG(ERROR, TAG, "Failed creating tags payload."); goto cbor_error; } if (OC_STACK_OK != OCLinksPayloadToCbor(rdPublish->setLinks, &colArray)) { OC_LOG(ERROR, TAG, "Failed creating links payload."); goto cbor_error; } rdPublish = rdPublish->next; } cborEncoderResult = cbor_encoder_close_container(&rootArray, &colArray); if (CborNoError != cborEncoderResult) { OC_LOG(ERROR, TAG, "Failed closing collection array."); goto cbor_error; } } cborEncoderResult = cbor_encoder_close_container(&encoder, &rootArray); if (CborNoError != cborEncoderResult) { OC_LOG(ERROR, TAG, "Failed closing root array container. "); goto cbor_error; } *size = encoder.ptr - outPayload; return OC_STACK_OK; cbor_error: OICFree(outPayload); return OC_STACK_ERROR; }
OCStackResult OCLinksPayloadToCbor(OCLinksPayload *rtPtr, CborEncoder *setMap) { CborEncoder linksArray; CborError cborEncoderResult; cborEncoderResult = cbor_encoder_create_array(setMap, &linksArray, CborIndefiniteLength); if (CborNoError != cborEncoderResult) { OC_LOG(ERROR, TAG, "Failed creating LINKS array."); return OC_STACK_ERROR; } while (rtPtr) { CborEncoder linksMap; cborEncoderResult = cbor_encoder_create_map(&linksArray, &linksMap, CborIndefiniteLength); if (CborNoError != cborEncoderResult) { OC_LOG(ERROR, TAG, "Failed creating LINKS map."); return OC_STACK_ERROR; } if (CborNoError != ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_HREF, sizeof(OC_RSRVD_HREF) - 1, rtPtr->href)) { OC_LOG(ERROR, TAG, "Failed adding OC_RSRVD_HREF in LINKS map."); return OC_STACK_ERROR; } if (CborNoError != ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_REL, sizeof(OC_RSRVD_REL) - 1, rtPtr->rel)) { OC_LOG(ERROR, TAG, "Failed adding OC_RSRVD_REL in LINKS map."); return OC_STACK_ERROR; } if (CborNoError != ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_TITLE, sizeof(OC_RSRVD_TITLE) - 1, rtPtr->title)) { OC_LOG(ERROR, TAG, "Failed adding OC_RSRVD_TITLE in LINKS map."); return OC_STACK_ERROR; } if (CborNoError != ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_URI, sizeof(OC_RSRVD_URI) - 1, rtPtr->uri)) { OC_LOG(ERROR, TAG, "Failed adding OC_RSRVD_URI in LINKS map."); return OC_STACK_ERROR; } if (CborNoError != AddStringLLToMap(&linksMap, OC_RSRVD_RESOURCE_TYPE, sizeof(OC_RSRVD_RESOURCE_TYPE) - 1, rtPtr->rt)) { OC_LOG(ERROR, TAG, "Failed adding OC_RSRVD_RESOURCE_TYPE in LINKS map."); return OC_STACK_ERROR; } if (CborNoError != AddStringLLToMap(&linksMap, OC_RSRVD_INTERFACE, sizeof(OC_RSRVD_INTERFACE) - 1, rtPtr->itf)) { OC_LOG(ERROR, TAG, "Failed adding OC_RSRVD_INTERFACE in LINKS map."); return OC_STACK_ERROR; } if (CborNoError != AddStringLLToMap(&linksMap, OC_RSRVD_MEDIA_TYPE, sizeof(OC_RSRVD_MEDIA_TYPE) - 1, rtPtr->mt)) { OC_LOG(ERROR, TAG, "Failed adding OC_RSRVD_MEDIA_TYPE in LINKS map."); return OC_STACK_ERROR; } uint64_t temp = (uint64_t)rtPtr->ins; if (CborNoError != ConditionalAddIntToMap(&linksMap, OC_RSRVD_INS, sizeof(OC_RSRVD_INS) - 1, &temp)) { OC_LOG(ERROR, TAG, "Failed adding OC_RSRVD_INS in LINKS map."); return OC_STACK_ERROR; } cborEncoderResult = cbor_encoder_close_container(&linksArray, &linksMap); if (CborNoError != cborEncoderResult) { OC_LOG(ERROR, TAG, "Failed closing LINKS map."); return OC_STACK_ERROR; } rtPtr = rtPtr->next; } cborEncoderResult = cbor_encoder_close_container(setMap, &linksArray); if (CborNoError != cborEncoderResult) { OC_LOG(ERROR, TAG, "Failed closing LINKS array."); return OC_STACK_ERROR;; } return OC_STACK_OK; }
OCStackResult OCTagsPayloadToCbor(OCTagsPayload *tags, CborEncoder *setMap) { CborEncoder tagsMap; CborError cborEncoderResult = cbor_encoder_create_map(setMap, &tagsMap, CborIndefiniteLength); if (CborNoError != cborEncoderResult) { OC_LOG(ERROR, TAG, "Failed creating TAGS map."); return OC_STACK_ERROR; } if (CborNoError != ConditionalAddTextStringToMap(&tagsMap, OC_RSRVD_DEVICE_NAME, sizeof(OC_RSRVD_DEVICE_NAME) - 1, (char *)tags->n.deviceName)) { OC_LOG(ERROR, TAG, "Failed adding OC_RSRVD_DEVICE_NAME in TAGS map."); return OC_STACK_ERROR; } if (CborNoError != ConditionalAddTextStringToMap(&tagsMap, OC_RSRVD_DEVICE_ID, sizeof(OC_RSRVD_DEVICE_ID) - 1, (char *)tags->di.id)) { OC_LOG(ERROR, TAG, "Failed adding OC_RSRVD_DEVICE_ID in TAGS map."); return OC_STACK_ERROR; } if (CborNoError != ConditionalAddTextStringToMap(&tagsMap, OC_RSRVD_RTS, sizeof(OC_RSRVD_RTS) - 1, (char *)tags->rts)) { OC_LOG(ERROR, TAG, "Failed adding OC_RSRVD_RTS in TAGS map."); return OC_STACK_ERROR; } if (CborNoError != ConditionalAddTextStringToMap(&tagsMap, OC_RSRVD_DREL, sizeof(OC_RSRVD_DREL) - 1, (char *)tags->drel)) { OC_LOG(ERROR, TAG, "Failed adding OC_RSRVD_DREL in TAGS map."); return OC_STACK_ERROR; } if (CborNoError != ConditionalAddTextStringToMap(&tagsMap, OC_RSRVD_BASE_URI, sizeof(OC_RSRVD_BASE_URI) - 1, (char *)tags->baseURI)) { OC_LOG(ERROR, TAG, "Failed adding OC_RSRVD_BASE_URI in TAGS map."); return OC_STACK_ERROR; } uint64_t temp = (uint64_t)tags->bitmap; if (CborNoError != ConditionalAddIntToMap(&tagsMap, OC_RSRVD_BITMAP, sizeof(OC_RSRVD_BITMAP) - 1, &temp)) { OC_LOG(ERROR, TAG, "Failed adding OC_RSRVD_BITMAP in TAGS map."); return OC_STACK_ERROR; } temp = (uint64_t)tags->port; if (CborNoError != ConditionalAddIntToMap(&tagsMap, OC_RSRVD_HOSTING_PORT, sizeof(OC_RSRVD_HOSTING_PORT) - 1, &temp)) { OC_LOG(ERROR, TAG, "Failed adding OC_RSRVD_HOSTING_PORT in TAGS map."); return OC_STACK_ERROR; } temp = (uint64_t)tags->ins; if (CborNoError != ConditionalAddIntToMap(&tagsMap, OC_RSRVD_INS, sizeof(OC_RSRVD_INS) - 1, &temp)) { OC_LOG(ERROR, TAG, "Failed adding OC_RSRVD_INS in TAGS map."); return OC_STACK_ERROR; } temp = (uint64_t)tags->ttl; if (CborNoError != ConditionalAddIntToMap(&tagsMap, OC_RSRVD_TTL, sizeof(OC_RSRVD_TTL) - 1, &temp)) { OC_LOG(ERROR, TAG, "Failed adding OC_RSRVD_TTL in TAGS map."); return OC_STACK_ERROR; } cborEncoderResult = cbor_encoder_close_container(setMap, &tagsMap); if (CborNoError != cborEncoderResult) { OC_LOG(ERROR, TAG, "Failed closing TAGS map."); return OC_STACK_ERROR; } return OC_STACK_OK; }
int64_t OCRDPayloadToCbor(const OCRDPayload *rdPayload, uint8_t *outPayload, size_t *size) { int64_t cborEncoderResult = CborErrorIO; int flags = 0; CborEncoder encoder; VERIFY_PARAM_NON_NULL(TAG, rdPayload, "Invalid input parameter rdPayload"); VERIFY_PARAM_NON_NULL(TAG, outPayload, "Invalid input parameter outPayload"); VERIFY_PARAM_NON_NULL(TAG, size, "Invalid input parameter size"); cbor_encoder_init(&encoder, outPayload, *size, flags); if (rdPayload->rdDiscovery) { CborEncoder map; cborEncoderResult |= cbor_encoder_create_map(&encoder, &map, CborIndefiniteLength); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create discovery map"); cborEncoderResult |= ConditionalAddTextStringToMap(&map, OC_RSRVD_DEVICE_NAME, rdPayload->rdDiscovery->n.deviceName); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_DEVICE_NAME in map"); cborEncoderResult |= ConditionalAddTextStringToMap(&map, OC_RSRVD_DEVICE_ID, (char *)rdPayload->rdDiscovery->di.id); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_DEVICE_ID in map"); { uint64_t value = rdPayload->rdDiscovery->sel; cborEncoderResult |= ConditionalAddIntToMap(&map, OC_RSRVD_RD_DISCOVERY_SEL, &value); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add RD_DISCOVERY_SEL in map"); } cborEncoderResult |= cbor_encoder_close_container(&encoder, &map); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing discovery map"); } else if (rdPayload->rdPublish) { CborEncoder colArray; cborEncoderResult |= cbor_encoder_create_array(&encoder, &colArray, CborIndefiniteLength); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create collection array"); OCResourceCollectionPayload *rdPublish = rdPayload->rdPublish; while (rdPublish) { cborEncoderResult |= OCTagsPayloadToCbor(rdPublish->tags, &colArray); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed adding tags payload"); cborEncoderResult |= OCLinksPayloadToCbor(rdPublish->setLinks, &colArray); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed adding setLinks payload"); rdPublish = rdPublish->next; } cborEncoderResult |= cbor_encoder_close_container(&encoder, &colArray); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing collection array"); } else { CborEncoder map; cborEncoderResult |= cbor_encoder_create_map(&encoder, &map, CborIndefiniteLength); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed entering discovery map"); cborEncoderResult |= cbor_encoder_close_container(&encoder, &map); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing discovery map"); } if (cborEncoderResult == CborErrorOutOfMemory) { *size += encoder.ptr - encoder.end; } else { *size = encoder.ptr - outPayload; } return cborEncoderResult; exit: OICFree(outPayload); return cborEncoderResult; }
static int64_t OCLinksPayloadToCbor(OCLinksPayload *links, CborEncoder *setMap) { CborEncoder linksArray; int64_t cborEncoderResult = CborNoError; cborEncoderResult |= cbor_encode_text_string(setMap, OC_RSRVD_LINKS, sizeof(OC_RSRVD_LINKS) - 1); cborEncoderResult |= cbor_encoder_create_array(setMap, &linksArray, CborIndefiniteLength); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create Links array"); while (links) { CborEncoder linksMap; cborEncoderResult |= cbor_encoder_create_map(&linksArray, &linksMap, CborIndefiniteLength); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create links map"); cborEncoderResult |= ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_HREF, links->href); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_HREF in links map"); cborEncoderResult |= ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_REL, links->rel); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_REL in links map"); cborEncoderResult |= AddStringLLToMap(&linksMap, OC_RSRVD_RESOURCE_TYPE, links->rt); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_RT in links map"); cborEncoderResult |= AddStringLLToMap(&linksMap, OC_RSRVD_INTERFACE, links->itf); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_ITF in links map"); // Policy CborEncoder policyMap; cborEncoderResult |= cbor_encode_text_string(&linksMap, OC_RSRVD_POLICY, sizeof(OC_RSRVD_POLICY) - 1); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed adding policy tag to links map"); cborEncoderResult |= cbor_encoder_create_map(&linksMap, &policyMap, CborIndefiniteLength); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed adding policy map to links map"); // Bitmap cborEncoderResult |= cbor_encode_text_string(&policyMap, OC_RSRVD_BITMAP, sizeof(OC_RSRVD_BITMAP) - 1); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed adding bitmap tag to policy map"); cborEncoderResult |= cbor_encode_uint(&policyMap, links->p); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed adding bitmap value to policy map"); cborEncoderResult |= cbor_encoder_close_container(&linksMap, &policyMap); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing policy map"); cborEncoderResult |= ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_TITLE, links->title); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_TITLE in links map"); cborEncoderResult |= ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_URI, links->anchor); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_URI in links map"); cborEncoderResult |= ConditionalAddIntToMap(&linksMap, OC_RSRVD_INS, (uint64_t *) &links->ins); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_INS in links map"); cborEncoderResult |= ConditionalAddIntToMap(&linksMap, OC_RSRVD_TTL, &links->ttl); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_TTL in links map"); cborEncoderResult |= AddStringLLToMap(&linksMap, OC_RSRVD_MEDIA_TYPE, links->type); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_MT in links map"); // Finsihed encoding a resource, close the map. cborEncoderResult |= cbor_encoder_close_container(&linksArray, &linksMap); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing links map"); links = links->next; } cborEncoderResult |= cbor_encoder_close_container(setMap, &linksArray); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing links array"); exit: return cborEncoderResult; }