Example #1
0
void
athena_EncodeMessage(CCNxMetaMessage *message)
{
    PARCSigner *signer = ccnxValidationCRC32C_CreateSigner();
    CCNxCodecNetworkBufferIoVec *iovec = ccnxCodecTlvPacket_DictionaryEncode(message, signer);
    assertTrue(ccnxWireFormatMessage_PutIoVec(message, iovec), "ccnxWireFormatMessage_PutIoVec failed");;
    ccnxCodecNetworkBufferIoVec_Release(&iovec);
    parcSigner_Release(&signer);
}
LONGBOW_TEST_CASE(Global, ccnxMetaMessage_EncodeDecode)
{
    CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar");
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    ccnxName_Release(&name);

    PARCSigner *signer = ccnxValidationCRC32C_CreateSigner(); // Would really be SHA256 or something.

    // Encode it to wire format.
    PARCBuffer *wireFormatBuffer = ccnxMetaMessage_CreateWireFormatBuffer(interest, signer);

    // Now decode it from wireformat.
    CCNxMetaMessage *decodedMessage = ccnxMetaMessage_CreateFromWireFormatBuffer(wireFormatBuffer);

    // At this point, the unpacked dictionary should be equivalent to the original interest.
    assertTrue(ccnxInterest_Equals(interest, decodedMessage), "Expected an equivalent interest to be unpacked");

    parcBuffer_Release(&wireFormatBuffer);
    ccnxInterest_Release(&interest);
    ccnxMetaMessage_Release(&decodedMessage);
    parcSigner_Release(&signer);
}