ssize_t ccnxCodecTlvUtilities_EncodeCustomList(CCNxCodecTlvEncoder *encoder, CCNxTlvDictionary *packetDictionary, int listKey) { ssize_t length = 0; size_t size = ccnxTlvDictionary_ListSize(packetDictionary, listKey); for (int i = 0; i < size; i++) { PARCBuffer *buffer; uint32_t key; ssize_t innerLength = -1; bool success = ccnxTlvDictionary_ListGetByPosition(packetDictionary, listKey, i, &buffer, &key); if (success) { innerLength = ccnxCodecTlvEncoder_AppendBuffer(encoder, key, buffer); } if (innerLength < 0) { return -1; } length += innerLength; } return length; }
ssize_t ccnxCodecSchemaV1ManifestEncoder_Encode(CCNxCodecTlvEncoder *encoder, CCNxTlvDictionary *packetDictionary) { ssize_t length = 0; ssize_t numHashGroups = ccnxTlvDictionary_ListSize(packetDictionary, CCNxCodecSchemaV1TlvDictionary_Lists_HASH_GROUP_LIST); for (size_t i = 0; i < numHashGroups; i++) { // Skip past the TL of the hash group to append the pointers inside ssize_t groupLength = 0; ccnxCodecTlvEncoder_AppendContainer(encoder, CCNxCodecSchemaV1Types_CCNxMessage_HashGroup, groupLength); CCNxManifestInterface *interface = ccnxManifestInterface_GetInterface(packetDictionary); CCNxManifestHashGroup *group = interface->getHashGroup(packetDictionary, i); // Encode any metadata, if present. if (ccnxManifestHashGroup_HasMetadata(group)) { groupLength += _appendMetadata(encoder, group); } // Append the HashGroup pointers size_t numPointers = ccnxManifestHashGroup_GetNumberOfPointers(group); for (size_t p = 0; p < numPointers; p++) { CCNxManifestHashGroupPointer *ptr = ccnxManifestHashGroup_GetPointerAtIndex(group, p); ssize_t ptrLength = _appendPointer(encoder, ptr); if (ptrLength < 0) { return ptrLength; } groupLength += ptrLength; } // Now that we know the overall length, rewind back to the start and append the TL // part of the container. size_t endPosition = ccnxCodecTlvEncoder_Position(encoder); ssize_t offset = endPosition - groupLength - 4; ccnxCodecTlvEncoder_PutUint16(encoder, offset, CCNxCodecSchemaV1Types_CCNxMessage_HashGroup); ccnxCodecTlvEncoder_PutUint16(encoder, offset + 2, groupLength); ccnxCodecTlvEncoder_SetPosition(encoder, endPosition); length += groupLength + 4; ccnxManifestHashGroup_Release(&group); } return length; }