err = err | cbor_encode_boolean(&array, valArray->bArray[i]);
break;
case OCREP_PROP_STRING:
- err = err | cbor_encode_text_string(&array, valArray->strArray[i],
- strlen(valArray->strArray[i]));
+ if (!valArray->strArray[i])
+ {
+ err = err | cbor_encode_null(&array);
+ }
+ else
+ {
+ err = err | cbor_encode_text_string(&array, valArray->strArray[i],
+ strlen(valArray->strArray[i]));
+ }
break;
case OCREP_PROP_OBJECT:
- err = OCConvertSingleRepPayload(&array, valArray->objArray[i]);
+ if (!valArray->objArray[i])
+ {
+ err = err | cbor_encode_null(&array);
+ }
+ else
+ {
+ err = OCConvertSingleRepPayload(&array, valArray->objArray[i]);
+ }
break;
case OCREP_PROP_ARRAY:
OC_LOG(ERROR, TAG, "ConvertArray Invalid child array");
}
break;
case OCREP_PROP_STRING:
- arr = (char**)OICMalloc(dimTotal * sizeof(char*));
+ arr = (char**)OICCalloc(dimTotal, sizeof(char*));
if(arr)
{
for(size_t i = 0; i < dimTotal && !err; ++i)
{
- err = err || cbor_value_dup_text_string(&insideArray, &tempStr,
- &len, NULL);
+ if (!cbor_type_is_null(&insideArray))
+ {
+ err = err || cbor_value_dup_text_string(&insideArray, &tempStr,
+ &len, NULL);
+ ((char**)arr)[i] = tempStr;
+ }
err = err || cbor_value_advance(&insideArray);
- ((char**)arr)[i] = tempStr;
}
if(err || !OCRepPayloadSetStringArrayAsOwner(out, name, (char**)arr, dimensions))
{
}
break;
case OCREP_PROP_OBJECT:
- arr = (OCRepPayload**)OICMalloc(dimTotal * sizeof(OCRepPayload*));
+ arr = (OCRepPayload**)OICCalloc(dimTotal, sizeof(OCRepPayload*));
if(arr)
{
for(size_t i = 0; i < dimTotal && !err; ++i)
{
- pl = NULL;
- err = err || OCParseSingleRepPayload(&pl, &insideArray);
+ if (!cbor_type_is_null(&insideArray))
+ {
+ pl = NULL;
+ err = err || OCParseSingleRepPayload(&pl, &insideArray);
+ ((OCRepPayload**)arr)[i] = pl;
+ }
err = err || cbor_value_advance(&insideArray);
- ((OCRepPayload**)arr)[i] = pl;
}
if(err || !OCRepPayloadSetPropObjectArrayAsOwner(out, name,
(OCRepPayload**)arr, dimensions))
err = err || cbor_value_leave_container(&insidePropArray, &ifArray);
}
}
+
err = err || cbor_value_map_find_value(repParent, OC_RSRVD_REPRESENTATION, &curVal);
if(cbor_value_is_map(&curVal))
{
}
template<>
+ void get_payload_array::copy_to_array(std::string item, void* array, size_t pos)
+ {
+ ((char**)array)[pos] = OICStrdup(item.c_str());
+ }
+
+ template<>
+ void get_payload_array::copy_to_array(std::string& item, void* array, size_t pos)
+ {
+ ((char**)array)[pos] = OICStrdup(item.c_str());
+ }
+
+ template<>
void get_payload_array::copy_to_array(const std::string& item, void* array, size_t pos)
{
((char**)array)[pos] = OICStrdup(item.c_str());
std::string OCRepresentation::payload_array_helper_copy<std::string>(
size_t index, const OCRepPayloadValue* pl)
{
- return std::string(pl->arr.strArray[index]);
+ if (pl->arr.strArray[index])
+ {
+ return std::string(pl->arr.strArray[index]);
+ }
+ else
+ {
+ return std::string{};
+ }
}
template<>
OCRepresentation OCRepresentation::payload_array_helper_copy<OCRepresentation>(
size_t index, const OCRepPayloadValue* pl)
{
OCRepresentation r;
- r.setPayload(pl->arr.objArray[index]);
+ if (pl->arr.objArray[index])
+ {
+ r.setPayload(pl->arr.objArray[index]);
+ }
return r;
}