ndn_Error ndn_encodeTlvName (const struct ndn_Name *name, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset, struct ndn_TlvEncoder *encoder) { size_t nameValueLength = 0; size_t i; ndn_Error error; for (i = 0; i < name->nComponents; ++i) nameValueLength += ndn_TlvEncoder_sizeOfBlobTlv(ndn_Tlv_NameComponent, &name->components[i].value); if ((error = ndn_TlvEncoder_writeTypeAndLength(encoder, ndn_Tlv_Name, nameValueLength))) return error; *signedPortionBeginOffset = encoder->offset; if (name->nComponents == 0) // There is no "final component", so set signedPortionEndOffset arbitrarily. *signedPortionEndOffset = *signedPortionBeginOffset; else { for (i = 0; i < name->nComponents; ++i) { if (i == name->nComponents - 1) // We will begin the final component. *signedPortionEndOffset = encoder->offset; if ((error = ndn_TlvEncoder_writeBlobTlv (encoder, ndn_Tlv_NameComponent, &name->components[i].value))) return error; } } return NDN_ERROR_success; }
/** * This private function is called by ndn_TlvEncoder_writeNestedTlv to write the TLVs in the body of the MetaInfo value. * @param context This is the ndn_MetaInfo struct pointer which was passed to writeTlv. * @param encoder the ndn_TlvEncoder which is calling this. * @return 0 for success, else an error code. */ static ndn_Error encodeMetaInfoValue(const void *context, struct ndn_TlvEncoder *encoder) { struct ndn_MetaInfo *metaInfo = (struct ndn_MetaInfo *)context; ndn_Error error; if (!((int)metaInfo->type < 0 || metaInfo->type == ndn_ContentType_BLOB)) { // Not the default, so we need to encode the type. if (metaInfo->type == ndn_ContentType_LINK || metaInfo->type == ndn_ContentType_KEY || metaInfo->type == ndn_ContentType_NACK) { // The ContentType enum is set up with the correct integer for each NDN-TLV ContentType. if ((error = ndn_TlvEncoder_writeNonNegativeIntegerTlv (encoder, ndn_Tlv_ContentType, metaInfo->type))) return error; } else if (metaInfo->type == ndn_ContentType_OTHER_CODE) { if ((error = ndn_TlvEncoder_writeNonNegativeIntegerTlv (encoder, ndn_Tlv_ContentType, metaInfo->otherTypeCode))) return error; } else // We don't expect this to happen. return NDN_ERROR_unrecognized_ndn_ContentType; } if ((error = ndn_TlvEncoder_writeOptionalNonNegativeIntegerTlvFromDouble (encoder, ndn_Tlv_FreshnessPeriod, metaInfo->freshnessPeriod))) return error; if (metaInfo->finalBlockId.value.value && metaInfo->finalBlockId.value.length > 0) { // The FinalBlockId has an inner NameComponent. if ((error = ndn_TlvEncoder_writeTypeAndLength (encoder, ndn_Tlv_FinalBlockId, ndn_TlvEncoder_sizeOfBlobTlv (metaInfo->finalBlockId.type, &metaInfo->finalBlockId.value)))) return error; if ((error = ndn_encodeTlvNameComponent(&metaInfo->finalBlockId, encoder))) return error; } return NDN_ERROR_success; }
ndn_Error ndn_encodeTlvName (const struct ndn_Name *name, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset, struct ndn_TlvEncoder *encoder) { size_t nameValueLength = 0; size_t i; ndn_Error error; for (i = 0; i < name->nComponents; ++i) { const struct ndn_NameComponent *component = &name->components[i]; // Get the type the same as in ndn_encodeTlvNameComponent. unsigned int type; if (component->type == ndn_NameComponentType_OTHER_CODE) type = (unsigned int)component->otherTypeCode; else // The enum values are the same as the TLV type codes. type = (unsigned int)component->type; nameValueLength += ndn_TlvEncoder_sizeOfBlobTlv(type, &component->value); } if ((error = ndn_TlvEncoder_writeTypeAndLength(encoder, ndn_Tlv_Name, nameValueLength))) return error; *signedPortionBeginOffset = encoder->offset; if (name->nComponents == 0) // There is no "final component", so set signedPortionEndOffset arbitrarily. *signedPortionEndOffset = *signedPortionBeginOffset; else { for (i = 0; i < name->nComponents; ++i) { if (i == name->nComponents - 1) // We will begin the final component. *signedPortionEndOffset = encoder->offset; if ((error = ndn_encodeTlvNameComponent(&name->components[i], encoder))) return error; } } return NDN_ERROR_success; }