Ejemplo n.º 1
0
CCNxNameSegment *
ccnxNameSegment_ParseURISegment(const PARCURISegment *uriSegment)
{
    CCNxNameSegment *result = NULL;

    PARCBuffer *buffer = parcURISegment_GetBuffer(uriSegment);

    size_t originalPosition = parcBuffer_Position(buffer);
    CCNxNameLabel *label = ccnxNameLabel_Parse(buffer);

    if (ccnxNameLabel_IsValid(label)) {
        PARCBuffer *value = parcBuffer_Slice(buffer);

        CCNxNameLabelType nameType = ccnxNameLabel_GetType(label);
        if (nameType != CCNxNameLabelType_Unknown) {
            result = ccnxNameSegment_CreateLabelValue(label, value);
        }

        ccnxNameLabel_Release(&label);
        parcBuffer_Release(&value);

        parcBuffer_SetPosition(buffer, originalPosition);
    }

    return result;
}
Ejemplo n.º 2
0
LONGBOW_TEST_CASE(parcURISegment, parcURISegment_GetBuffer)
{
    const char *pointer;
    PARCURISegment *segment = parcURISegment_Parse(URI_PATH_SEGMENT, &pointer);
    assertNotNull(segment, "Expected non-null result.");
    assertTrue(*pointer == 0, "Expected pointer to point to the null terminating byte.");

    PARCBuffer *buffer = parcURISegment_GetBuffer(segment);

    char *expected = URI_PATH_SEGMENT;
    char *actual = (char *) parcBuffer_Overlay(buffer, 0);
    size_t compareLength = strlen(URI_PATH_SEGMENT);
    assertTrue(strncmp(expected, actual, compareLength), "Buffer does not contain original data.");

    parcURISegment_Release(&segment);
}