コード例 #1
0
uint8_t
ccnxInterestPayloadId_GetType(const CCNxInterestPayloadId *id)
{
    PARCBuffer *data = ccnxNameSegment_GetValue(id->nameSegment);
    parcBuffer_Rewind(data);
    uint8_t type = parcBuffer_GetUint8(data);
    return type;
}
コード例 #2
0
PARCBuffer *
ccnxInterestPayloadId_GetValue(const CCNxInterestPayloadId *id)
{
    PARCBuffer *data = ccnxNameSegment_GetValue(id->nameSegment);
    parcBuffer_Rewind(data);
    parcBuffer_SetPosition(data, 1);
    return data;
}
コード例 #3
0
bool
ccnxNameSegment_Equals(const CCNxNameSegment *segmentA, const CCNxNameSegment *segmentB)
{
    bool result = false;

    if (segmentA == segmentB) {
        result = true;
    } else if (segmentA == NULL || segmentB == NULL) {
        result = false;
    } else {
        if (ccnxNameLabel_Equals(segmentA->label, segmentB->label)) {
            if (parcBuffer_Equals(ccnxNameSegment_GetValue(segmentA), ccnxNameSegment_GetValue(segmentB))) {
                result = true;
            }
        }
    }

    return result;
}
コード例 #4
0
PARCBufferComposer *
ccnxNameSegment_BuildString(const CCNxNameSegment *segment, PARCBufferComposer *composer)
{
    ccnxNameLabel_BuildString(segment->label, composer);

    if (ccnxNameSegment_Length(segment) > 0) {
        PARCURISegment *uriSegment = parcURISegment_CreateFromBuffer(ccnxNameSegment_GetValue(segment));
        parcURISegment_BuildString(uriSegment, composer);

        parcURISegment_Release(&uriSegment);
    }

    return composer;
}
コード例 #5
0
int
ccnxNameSegment_Compare(const CCNxNameSegment *segmentA, const CCNxNameSegment *segmentB)
{
    if (segmentA == NULL) {
        if (segmentB == NULL) {
            return 0;
        }
        return -1;
    } else {
        if (segmentB == NULL) {
            return +1;
        }
    }

    if (ccnxNameSegment_Length(segmentA) < ccnxNameSegment_Length(segmentB)) {
        return -1;
    }
    if (ccnxNameSegment_Length(segmentA) > ccnxNameSegment_Length(segmentB)) {
        return +1;
    }

    int result = parcBuffer_Compare(ccnxNameSegment_GetValue(segmentA), ccnxNameSegment_GetValue(segmentB));
    return result;
}
コード例 #6
0
ファイル: metis_TlvName.c プロジェクト: PARC/Metis
MetisTlvName *
metisTlvName_CreateFromCCNxName(const CCNxName *ccnxName)
{
    // to avoid reallocs, calculate the exact size we need
    size_t memoryLength = 0;
    for (size_t i = 0; i < ccnxName_GetSegmentCount(ccnxName); i++) {
        CCNxNameSegment *segment = ccnxName_GetSegment(ccnxName, i);
        memoryLength += 4 + ccnxNameSegment_Length(segment);
    }

    MetisTlvName *name = parcMemory_AllocateAndClear(sizeof(MetisTlvName));
    assertNotNull(name, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(MetisTlvName));

    name->memoryLength = memoryLength;
    name->memory = parcMemory_Allocate(memoryLength);
    assertNotNull(name->memory, "parcMemory_Allocate(%zu) returned NULL", memoryLength);

    uint8_t *p = name->memory;
    uint8_t *end = p + memoryLength;
    for (size_t i = 0; i < ccnxName_GetSegmentCount(ccnxName); i++) {
        CCNxNameSegment *segment = ccnxName_GetSegment(ccnxName, i);
        uint16_t type = ccnxNameSegment_GetType(segment);
        uint16_t length = ccnxNameSegment_Length(segment);

        *(uint16_t *) p = htons(type);
        p += 2;

        *(uint16_t *) p = htons(length);
        p += 2;

        if (length >0) {
            PARCBuffer *buffer = ccnxNameSegment_GetValue(segment);
            uint8_t *overlay = parcBuffer_Overlay(buffer, 0);
            memcpy(p, overlay, length);

            p += length;
        }

        // sanity check
        assertTrue(p <= end, "Wrote past the end of buffer, now at %p end at %p", p, end);
    }

    _setup(name);
    return name;
}