void writeNonNegativeIntegerTlv(unsigned int type, uint64_t value) { ndn_Error error; if ((error = ndn_TlvEncoder_writeNonNegativeIntegerTlv(this, type, value))) throw std::runtime_error(ndn_getErrorString(error)); }
/** * 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; }
/** * This private function is called by ndn_TlvEncoder_writeNestedTlv to write the TLVs * in the body of the DigestSha256 value. * @param context This is the ndn_Signature struct pointer which was passed to writeTlv. * (It is ignored.) * @param encoder the ndn_TlvEncoder which is calling this. * @return 0 for success, else an error code. */ static ndn_Error encodeDigestSha256Value(const void *context, struct ndn_TlvEncoder *encoder) { ndn_Error error; if ((error = ndn_TlvEncoder_writeNonNegativeIntegerTlv (encoder, ndn_Tlv_SignatureType, ndn_Tlv_SignatureType_DigestSha256))) return error; return NDN_ERROR_success; }
/** * This private function is called by ndn_TlvEncoder_writeNestedTlv to write the TLVs * in the body of the Delegation value. * @param context This is the ndn_DelegationSet_Delegation 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 encodeDelegationValue(const void *context, struct ndn_TlvEncoder *encoder) { struct ndn_DelegationSet_Delegation *delegation = (struct ndn_DelegationSet_Delegation *)context; ndn_Error error; size_t dummyBeginOffset, dummyEndOffset; if ((error = ndn_TlvEncoder_writeNonNegativeIntegerTlv (encoder, ndn_Tlv_Link_Preference, delegation->preference))) return error; if ((error = ndn_encodeTlvName (&delegation->name, &dummyBeginOffset, &dummyEndOffset, encoder))) return error; return NDN_ERROR_success; }
/** * This private function is called by ndn_TlvEncoder_writeNestedTlv to write the TLVs * in the body of the ControlResponse value. * @param context This is the ndn_ControlResponse 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 encodeControlResponseValue(const void *context, struct ndn_TlvEncoder *encoder) { struct ndn_ControlResponse *controlResponse = (struct ndn_ControlResponse *)context; ndn_Error error; struct ndn_ForwardingFlags defaultFlags; if ((error = ndn_TlvEncoder_writeNonNegativeIntegerTlv (encoder, ndn_Tlv_NfdCommand_StatusCode, controlResponse->statusCode))) return error; if ((error = ndn_TlvEncoder_writeBlobTlv (encoder, ndn_Tlv_NfdCommand_StatusText, &controlResponse->statusText))) return error; if (controlResponse->hasBodyAsControlParameters) { if ((error = ndn_encodeTlvControlParameters (&controlResponse->bodyAsControlParameters, encoder))) return error; } return NDN_ERROR_success; }
/** * This private function is called by ndn_TlvEncoder_writeNestedTlv to write the * TLVs in the body of a signature value which has a KeyLocator and * ValidityPeriod, e.g. SignatureSha256WithRsa. * @param context This is the ndn_Signature struct pointer which was passed to * writeTlv. Use signature->type as the TLV type, assuming that the * ndn_SignatureType enum has the same values as the TLV signature types. * @param encoder the ndn_TlvEncoder which is calling this. * @return 0 for success, else an error code. */ static ndn_Error encodeSignatureWithKeyLocatorAndValidityPeriodValue (const void *context, struct ndn_TlvEncoder *encoder) { struct ndn_Signature *signature = (struct ndn_Signature *)context; ndn_Error error; if ((error = ndn_TlvEncoder_writeNonNegativeIntegerTlv (encoder, ndn_Tlv_SignatureType, signature->type))) return error; if ((error = ndn_TlvEncoder_writeNestedTlv (encoder, ndn_Tlv_KeyLocator, ndn_encodeTlvKeyLocatorValue, &signature->keyLocator, 0))) return error; if (ndn_ValidityPeriod_hasPeriod(&signature->validityPeriod)) { if ((error = ndn_TlvEncoder_writeNestedTlv (encoder, ndn_Tlv_ValidityPeriod_ValidityPeriod, encodeValidityPeriodValue, &signature->validityPeriod, 0))) return error; } return NDN_ERROR_success; }