From c653a53b14c8389a981de19c7bd3044dd1cf7bb7 Mon Sep 17 00:00:00 2001 From: Habib Virji Date: Thu, 10 Dec 2015 10:57:55 +0000 Subject: [PATCH] Change RD payload in correct format. Updated RD without surrounding array. [ { "di":"", }, [ {links} ] ] Change-Id: I6d6082bcb04f03a80e367dfc081a3e381a4d8f8d Signed-off-by: Habib Virji Reviewed-on: https://gerrit.iotivity.org/gerrit/4495 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz --- resource/csdk/stack/src/rdpayload.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/resource/csdk/stack/src/rdpayload.c b/resource/csdk/stack/src/rdpayload.c index 426a4dc..12358fb 100644 --- a/resource/csdk/stack/src/rdpayload.c +++ b/resource/csdk/stack/src/rdpayload.c @@ -49,19 +49,11 @@ int64_t OCRDPayloadToCbor(const OCRDPayload *rdPayload, uint8_t *outPayload, siz 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); + cborEncoderResult = cbor_encoder_create_map(&encoder, &map, CborIndefiniteLength); if (CborNoError != cborEncoderResult) { OC_LOG(ERROR, TAG, "Failed creating discovery map."); @@ -86,7 +78,7 @@ int64_t OCRDPayloadToCbor(const OCRDPayload *rdPayload, uint8_t *outPayload, siz OC_LOG(ERROR, TAG, "Failed setting OC_RSRVD_RD_DISCOVERY_SEL."); goto cbor_error; } - cborEncoderResult = cbor_encoder_close_container(&rootArray, &map); + cborEncoderResult = cbor_encoder_close_container(&encoder, &map); if (CborNoError != cborEncoderResult) { OC_LOG(ERROR, TAG, "Failed closing discovery map."); @@ -96,7 +88,7 @@ int64_t OCRDPayloadToCbor(const OCRDPayload *rdPayload, uint8_t *outPayload, siz else if (rdPayload->rdPublish) { CborEncoder colArray; - cborEncoderResult = cbor_encoder_create_array(&rootArray, &colArray, CborIndefiniteLength); + cborEncoderResult = cbor_encoder_create_array(&encoder, &colArray, CborIndefiniteLength); if (CborNoError != cborEncoderResult) { OC_LOG(ERROR, TAG, "Failed creating collection array."); @@ -118,23 +110,32 @@ int64_t OCRDPayloadToCbor(const OCRDPayload *rdPayload, uint8_t *outPayload, siz } rdPublish = rdPublish->next; } - cborEncoderResult = cbor_encoder_close_container(&rootArray, &colArray); + cborEncoderResult = cbor_encoder_close_container(&encoder, &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) + else { - OC_LOG(ERROR, TAG, "Failed closing root array container. "); - goto cbor_error; + CborEncoder map; + cborEncoderResult = cbor_encoder_create_map(&encoder, &map, CborIndefiniteLength); + if (CborNoError != cborEncoderResult) + { + OC_LOG(ERROR, TAG, "Failed creating discovery map."); + goto cbor_error; + } + cborEncoderResult = cbor_encoder_close_container(&encoder, &map); + if (CborNoError != cborEncoderResult) + { + OC_LOG(ERROR, TAG, "Failed creating discovery map."); + goto cbor_error; + } } - *size = encoder.ptr - outPayload; - return OC_STACK_OK; + return OC_STACK_OK; cbor_error: OICFree(outPayload); return OC_STACK_ERROR; -- 2.7.4