CCNxPortalAnchor * ccnxPortalAnchor_Deserialize(PARCBuffer *buffer) { PARCJSON *json = parcJSON_ParseBuffer(buffer); CCNxPortalAnchor *result = ccnxPortalAnchor_CreateFromJSON(json); parcJSON_Release(&json); return result; }
LONGBOW_TEST_CASE(JSON, parcJSON_ParseBuffer_WithExcess) { char *string = "{ \"string\" : \"string\", \"null\" : null, \"true\" : true, \"false\" : false, \"integer\" : 31415, \"float\" : 3.141500, \"array\" : [ null, false, true, 31415, \"string\", [ null, false, true, 31415, \"string\" ], { } ] }Xhowdy"; PARCBuffer *buffer = parcBuffer_WrapCString((char *) string); PARCJSON *json = parcJSON_ParseBuffer(buffer); char actual = parcBuffer_GetUint8(buffer); assertTrue(actual == 'X', "Expected buffer position to point to X, actual %x", actual); parcBuffer_Release(&buffer); parcJSON_Release(&json); }
/** * Decodes the "value" of the CPI "TLV" * * the CPI packet is encoded as a single TLV container of type 0xBEEF (detected in _decodeMessage). * At this point, the cpiDecoder wraps the CPI payload, which is the encapsulated JSON * * @param [in] cpiDecoder Decoder wrapping the value * @param [in] packetDictionary where to place the results * * @retval true Good decode * @retval false An error * * Example: * @code * <#example#> * @endcode */ static bool _decodeCPI(CCNxCodecTlvDecoder *cpiDecoder, CCNxTlvDictionary *packetDictionary) { // we just take the whole contents of the decoder and put in the the PAYLOAD dictionary entry. size_t length = ccnxCodecTlvDecoder_Remaining(cpiDecoder); PARCBuffer *payload = ccnxCodecTlvDecoder_GetValue(cpiDecoder, length); PARCJSON *json = parcJSON_ParseBuffer(payload); bool success = ccnxTlvDictionary_PutJson(packetDictionary, CCNxCodecSchemaV1TlvDictionary_MessageFastArray_PAYLOAD, json); parcJSON_Release(&json); parcBuffer_Release(&payload); return success; }