Commit 430a8ad2 authored by Ignacio Solis's avatar Ignacio Solis

Merge pull request #10 from chris-wood/8-chris-chunker_integration

Adding the CCNxChunker to Libparc
parents 6dbcc01b eca00da8
......@@ -13,10 +13,12 @@ set(LIBPARC_ALGOL_HEADER_FILES
algol/parc_Base64.h
algol/parc_BitVector.h
algol/parc_Buffer.h
algol/parc_BufferChunker.h
algol/parc_BufferComposer.h
algol/parc_BufferDictionary.h
algol/parc_ByteArray.h
algol/parc_Clock.h
algol/parc_Chunker.h
algol/parc_CMacro.h
algol/parc_Collection.h
algol/parc_Deque.h
......@@ -31,6 +33,7 @@ set(LIBPARC_ALGOL_HEADER_FILES
algol/parc_EventQueue.h
algol/parc_EventBuffer.h
algol/parc_File.h
algol/parc_FileChunker.h
algol/parc_FileInputStream.h
algol/parc_FileOutputStream.h
algol/parc_Hash.h
......@@ -84,15 +87,18 @@ set(LIBPARC_ALGOL_SOURCE_FILES
algol/parc_Base64.c
algol/parc_BitVector.c
algol/parc_Buffer.c
algol/parc_BufferChunker.c
algol/parc_BufferComposer.c
algol/parc_BufferDictionary.c
algol/parc_ByteArray.c
algol/parc_Clock.c
algol/parc_Chunker.c
algol/parc_Deque.c
algol/parc_Dictionary.c
algol/parc_DisplayIndented.c
algol/parc_Environment.c
algol/parc_File.c
algol/parc_FileChunker.c
algol/parc_FileInputStream.c
algol/parc_FileOutputStream.c
algol/parc_Hash.c
......
/*
* Copyright (c) 2013-2015, Xerox Corporation (Xerox)and Palo Alto Research Center (PARC)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Patent rights are not granted under this agreement. Patent rights are
* available under FRAND terms.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL XEROX or PARC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author Christopher Wood, Palo Alto Research Center (Xerox PARC)
* @copyright 2013-2015, Xerox Corporation (Xerox)and Palo Alto Research Center (PARC). All rights reserved.
*/
#include <config.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_Buffer.h>
#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_BufferChunker.h>
PARCChunkerInterface *PARCBufferChunkerAsBunker = &(PARCChunkerInterface) {
.ForwardIterator = (void *(*)(const void *))parcBufferChunker_ForwardIterator,
.ReverseIterator = (void *(*)(const void *))parcBufferChunker_ReverseIterator,
.Release = (void (*)(void **))parcBufferChunker_Release
};
struct _parc_chunker_state {
size_t chunkNumber;
int direction;
bool atEnd;
size_t position;
size_t nextChunkSize;
};
typedef struct _parc_chunker_state _ChunkerState;
struct parc_buffer_chunker {
// State
size_t chunkSize;
// Container for the data to be parsed
PARCBuffer *data;
// The current element of the iterator
PARCBuffer *currentElement;
};
static void
_destroy(PARCBufferChunker **chunkerP)
{
if ((*chunkerP)->data != NULL) {
parcBuffer_Release(&(*chunkerP)->data);
}
if ((*chunkerP)->currentElement != NULL) {
parcBuffer_Release(&(*chunkerP)->currentElement);
}
}
static void *
_InitForward(PARCBufferChunker *chunker)
{
_ChunkerState *state = parcMemory_Allocate(sizeof(_ChunkerState));
state->chunkNumber = 0;
state->direction = 0;
state->position = 0;
state->atEnd = false;
if (parcBuffer_Remaining(chunker->data) < chunker->chunkSize) {
state->nextChunkSize = parcBuffer_Remaining(chunker->data);
} else {
state->nextChunkSize = chunker->chunkSize;
}
return state;
}
static void *
_InitReverse(PARCBufferChunker *chunker)
{
_ChunkerState *state = parcMemory_Allocate(sizeof(_ChunkerState));
state->chunkNumber = 0;
state->direction = 1;
state->atEnd = false;
if (parcBuffer_Remaining(chunker->data) < chunker->chunkSize) {
state->position = 0;
state->nextChunkSize = parcBuffer_Remaining(chunker->data);
} else {
state->position = parcBuffer_Remaining(chunker->data) - chunker->chunkSize;
state->nextChunkSize = chunker->chunkSize;
}
return state;
}
static bool
_ccnxChunker_HasNext(PARCBufferChunker *chunker, void *voidstate)
{
_ChunkerState *state = (_ChunkerState *) voidstate;
return !state->atEnd;
}
static void
_advanceStateForward(PARCBufferChunker *chunker, _ChunkerState *state)
{
state->position += state->nextChunkSize;
size_t remaining = parcBuffer_Remaining(chunker->data);
if (remaining == 0) {
state->atEnd = true;
} else if (remaining > chunker->chunkSize) {
state->nextChunkSize = chunker->chunkSize;
} else {
state->nextChunkSize = remaining;
}
}
static void
_advanceStateBackward(PARCBufferChunker *chunker, _ChunkerState *state)
{
// Previous chunk size
size_t chunkSize = state->nextChunkSize;
if (chunkSize != chunker->chunkSize || state->position == 0) {
state->atEnd = true;
} else {
if (state->position < chunkSize) {
state->nextChunkSize = state->position; // on next read, go to the current position
state->position = 0; // we reached the beginning
} else {
state->position -= chunkSize;
}
}
}
static void
_advanceState(PARCBufferChunker *chunker, _ChunkerState *state)
{
state->chunkNumber++;
if (state->direction == 0) {
_advanceStateForward(chunker, state);
} else {
_advanceStateBackward(chunker, state);
}
}
static void *
_ccnxChunker_NextFromBuffer(PARCBufferChunker *chunker, _ChunkerState *state)
{
size_t chunkSize = state->nextChunkSize;
parcBuffer_SetPosition(chunker->data, state->position);
PARCBuffer *slice = parcBuffer_CreateFromArray(parcBuffer_Overlay(chunker->data, chunkSize), chunkSize);
slice = parcBuffer_Flip(slice);
_advanceState(chunker, state);
return slice;
}
static void *
_ccnxChunker_Next(PARCBufferChunker *chunker, void *state)
{
PARCBuffer *buffer = _ccnxChunker_NextFromBuffer(chunker, state);
if (chunker->currentElement != NULL) {
parcBuffer_Release(&chunker->currentElement);
}
if (buffer != NULL) {
chunker->currentElement = parcBuffer_Acquire(buffer);
}
return state;
}
static void *
_ccnxChunker_GetElement(PARCBufferChunker *chunker, void *state)
{
return chunker->currentElement;
}
static void
_ccnxChunker_Finish(PARCBufferChunker *chunker, void *state)
{
_ChunkerState *thestate = (_ChunkerState *) state;
parcMemory_Deallocate(&thestate);
}
static void
_ccnxChunker_AssertValid(const void *state)
{
// pass
}
parcObject_ExtendPARCObject(PARCBufferChunker, _destroy, NULL, NULL, NULL, NULL, NULL, NULL);
parcObject_ImplementAcquire(parcBufferChunker, PARCBufferChunker);
parcObject_ImplementRelease(parcBufferChunker, PARCBufferChunker);
PARCBufferChunker *
parcBufferChunker_Create(PARCBuffer *data, size_t chunkSize)
{
PARCBufferChunker *chunker = parcObject_CreateInstance(PARCBufferChunker);
if (chunker != NULL) {
chunker->chunkSize = chunkSize;
chunker->data = parcBuffer_Acquire(data);
chunker->currentElement = NULL;
}
return chunker;
}
PARCIterator *
parcBufferChunker_ForwardIterator(const PARCBufferChunker *chunker)
{
PARCIterator *iterator = parcIterator_Create((void *) chunker,
(void *(*)(PARCObject *))_InitForward,
(bool (*)(PARCObject *, void *))_ccnxChunker_HasNext,
(void *(*)(PARCObject *, void *))_ccnxChunker_Next,
NULL,
(void *(*)(PARCObject *, void *))_ccnxChunker_GetElement,
(void (*)(PARCObject *, void *))_ccnxChunker_Finish,
(void (*)(const void *))_ccnxChunker_AssertValid);
return iterator;
}
PARCIterator *
parcBufferChunker_ReverseIterator(const PARCBufferChunker *chunker)
{
PARCIterator *iterator = parcIterator_Create((void *) chunker,
(void *(*)(PARCObject *))_InitReverse,
(bool (*)(PARCObject *, void *))_ccnxChunker_HasNext,
(void *(*)(PARCObject *, void *))_ccnxChunker_Next,
NULL,
(void *(*)(PARCObject *, void *))_ccnxChunker_GetElement,
(void (*)(PARCObject *, void *))_ccnxChunker_Finish,
(void (*)(const void *))_ccnxChunker_AssertValid);
return iterator;
}
/*
* Copyright (c) 2013-2015, Xerox Corporation (Xerox)and Palo Alto Research Center (PARC)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Patent rights are not granted under this agreement. Patent rights are
* available under FRAND terms.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL XEROX or PARC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file parc_BufferChunker.h
* @ingroup ContentObject
* @brief A BufferChunker is a chunker that segments a PARCBuffer.
*
* @author Christopher A. Wood, Palo Alto Research Center (Xerox PARC)
* @copyright 2013-2015, Xerox Corporation (Xerox)and Palo Alto Research Center (PARC). All rights reserved.
*/
#ifndef libccnx_parc_BufferChunker_h
#define libccnx_parc_BufferChunker_h
#include <config.h>
#include <parc/algol/parc_Chunker.h>
struct parc_buffer_chunker;
/**
* @typedef PARCChunker
* @brief The PARC Chunker
*/
typedef struct parc_buffer_chunker PARCBufferChunker;
/**
* The mapping of a `PARCArrayList` to the generic `PARCList`.
*/
extern PARCChunkerInterface *PARCBufferChunkerAsChunker;
/**
* Create a new chunker to segment data contained in a `PARCBuffer.`
*
* @param [in] data A `PARCBuffer` which contains the data.
* @param [in] chunkSize The size per chunk.
*
* @retval CCNxChunker A newly allocated `CCNxChunker`
* @retval NULL An error occurred.
*
* Example
* @code
* {
* PARCBuffer *dataToChunk = ...
* CCNxChunker *chunker = ccnxChunker_CreateFromBuffer(dataToChunk, 32);
* }
*/
PARCBufferChunker *parcBufferChunker_Create(PARCBuffer *data, size_t chunkSize);
/**
* Increase the number of references to a `CCNxChunker` instance.
*
* Note that new `CCNxChunker` is not created,
* only that the given `CCNxChunker` reference count is incremented.
* Discard the reference by invoking {@link ccnxChunker_Release}.
*
* @param [in] chunker A pointer to the original `CCNxChunker`.
* @return The value of the input parameter @p chunker.
*
* Example:
* @code
* {
* PARCBufferChunker *original = parcBufferChunker_Create(...);
*
* PARCBufferChunker *reference = parcBufferChunker_Acquire(original);
*
* parcBufferChunker_Release(&original);
* parcBufferChunker_Release(&reference);
* }
* @endcode
*
* @see parcBufferChunker_Release
*/
PARCBufferChunker *parcBufferChunker_Acquire(const PARCBufferChunker *chunker);
/**
* Release a previously acquired reference to the specified instance,
* decrementing the reference count for the instance.
*
* The pointer to the instance is set to NULL as a side-effect of this function.
*
* If the invocation causes the last reference to the instance to be released,
* the instance is deallocated and the instance's implementation will perform
* additional cleanup and release other privately held references.
*
* @param [in,out] chunkerP A pointer to a pointer to the instance to release.
*
*
* Example:
* @code
* {
* ...
*
* PARCBufferChunker *chunker = parcBufferChunker_Acquire(instance);
*
* parcBufferChunker_Release(&chunker);
* }
* @endcode
*/
void parcBufferChunker_Release(PARCBufferChunker **chunkerP);
/**
* Determine if two `PARCBufferChunker` instances are equal.
*
* The following equivalence relations on non-null `PARCBufferChunker` instances are maintained:
*
* * It is reflexive: for any non-null reference value x, `parcBufferChunker_Equals(x, x)`
* must return true.
*
* * It is symmetric: for any non-null reference values x and y,
* `parcBufferChunker_Equals(x, y)` must return true if and only if
* `parcBufferChunker_Equals(y, x)` returns true.
*
* * It is transitive: for any non-null reference values x, y, and z, if
* `parcBufferChunker_Equals(x, y)` returns true and
* `parcBufferChunker_Equals(y, z)` returns true,
* then `parcBufferChunker_Equals(x, z)` must return true.
*
* * It is consistent: for any non-null reference values x and y, multiple
* invocations of `parcBufferChunker_Equals(x, y)` consistently return true or
* consistently return false.
*
* * For any non-null reference value x, `parcBufferChunker_Equals(x, NULL)` must
* return false.
*
* @param chunkerA A pointer to a `PARCBufferChunker` instance.
* @param chunkerB A pointer to a `PARCBufferChunker` instance.
* @return true if the two `PARCBufferChunker` instances are equal.
*
* Example:
* @code
* {
* PARCBuffer *dataToChunk = ...
* PARCBufferChunker *chunkerA = parcBufferChunker_Create(dataToChunk, 32);
* PARCBufferChunker *chunkerB = parcBufferChunker_Create(dataToChunk, 32);
*
* bool equals = parcBufferChunker_Equals(chunkerA, chunkerB);
* }
* @endcode
*/
bool parcBufferChunker_Equals(const PARCBufferChunker *chunkerA, const PARCBufferChunker *chunkerB);
/**
* Return an iterator to traverse the chunks of the underlying data in sequential order.
*
* This function can only be called once per chunker instance since the iterator
* will mutate internal state of the chunker.
*
* @param [in] chunker A `PARCBufferChunker` instance.
*
* @return a `PARCIterator` that traverses the chunks of the underlying data.
*
* Example
* @code
* {
* PARCBuffer *dataToChunk = ...
* PARCBufferChunker *chunker = parcBufferChunker_Create(dataToChunk, 32);
*
* PARCIterator *itr = parcBufferChunker_ForwardIterator(chunker);
*
* // use the iterator to traverse the chunker
* }
* @endcode
*/
PARCIterator *parcBufferChunker_ForwardIterator(const PARCBufferChunker *chunker);
/**
* Return an iterator to traverse the chunks of the underlying data in sequential order.
*
* This function can only be called once per chunker instance since the iterator
* will mutate internal state of the chunker.
*
* @param [in] chunker A `PARCBufferChunker` instance.
*
* @return a `PARCIterator` that traverses the chunks of the underlying data.
*
* Example
* @code
* {
* PARCBuffer *dataToChunk = ...
* PARCBufferChunker *chunker = parcBufferChunker_Create(dataToChunk, 32);
*
* PARCIterator *itr = parcBufferChunker_ReverseIterator(chunker);
*
* // use the iterator to traverse the chunker
* }
* @endcode
*/
PARCIterator *parcBufferChunker_ReverseIterator(const PARCBufferChunker *chunker);
#endif // libccnx_parc_BufferChunker_h
/*
* Copyright (c) 2013-2015, Xerox Corporation (Xerox)and Palo Alto Research Center (PARC)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Patent rights are not granted under this agreement. Patent rights are
* available under FRAND terms.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL XEROX or PARC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author Christopher Wood, Palo Alto Research Center (Xerox PARC)
* @copyright 2013-2015, Xerox Corporation (Xerox)and Palo Alto Research Center (PARC). All rights reserved.
*/
#include <config.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_Chunker.h>
struct parc_chunker {
void *instance;
const PARCChunkerInterface *interface;
};
static void
_destroy(PARCChunker **chunkerP)
{
(*chunkerP)->interface->Release(&(*chunkerP)->instance);
}
parcObject_ExtendPARCObject(PARCChunker, _destroy, NULL, NULL, NULL, NULL, NULL, NULL);
parcObject_ImplementAcquire(parcChunker, PARCChunker);
parcObject_ImplementRelease(parcChunker, PARCChunker);
PARCChunker *
parcChunker_Create(void *instance, PARCChunkerInterface *interface)
{
PARCChunker *chunker = parcObject_CreateInstance(PARCChunker);
if (chunker != NULL) {
chunker->instance = instance;
chunker->interface = interface;
}
return chunker;
}
PARCIterator *
parcChunker_ForwardIterator(const PARCChunker *chunker)
{
return (chunker->interface)->ForwardIterator(chunker->instance);
}
PARCIterator *
parcChunker_ReverseIterator(const PARCChunker *chunker)
{
return (chunker->interface)->ReverseIterator(chunker->instance);
}
/*
* Copyright (c) 2013-2015, Xerox Corporation (Xerox)and Palo Alto Research Center (PARC)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Patent rights are not granted under this agreement. Patent rights are
* available under FRAND terms.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL XEROX or PARC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file ccnx_Chunker.h
* @ingroup ContentObject
* @brief A Chunker is an object that breaks up a large piece of data from a `PARCBuffer`
* or a file and provides an iterator to walk over the chunks in sequential order.
*
* @author Christopher A. Wood, Palo Alto Research Center (Xerox PARC)
* @copyright 2013-2015, Xerox Corporation (Xerox)and Palo Alto Research Center (PARC). All rights reserved.
*/
#ifndef libccnx_ccnx_Chunker_h
#define libccnx_ccnx_Chunker_h
#include <config.h>
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_Iterator.h>
struct parc_chunker;
/**
* @typedef PARCChunker
* @brief The PARC Chunker
*/
typedef struct parc_chunker PARCChunker;
typedef struct PARCChunkerInterface {
/**
* @see parcChunker_ForwardIterator
*/
void *(*ForwardIterator)(const void *original);
/**
* @see parcChunker_ReverseIterator
*/
void *(*ReverseIterator)(const void *original);
/**
* @see parcChunker_Release
*/
void (*Release)(void **originalP);
} PARCChunkerInterface;
/**
* Create a new chunker from the given concrete instance.
*
* @param [in] instance A `PARCChunker` instance.
* @param [in] interface The interface implementation of the chunker.
*
* @retval PARCChunker A newly allocated `PARCChunker`
* @retval NULL An error occurred.
*
* Example
* @code
* {
* PARCBuffer *dataToChunk = ...
* PARCChunkerBuffer *bufferChunker = ccnxBufferChunker_Create(dataToChunk, 32);
* PARCChunker *chunker = parcChunker_Create(bufferCunker, &CCNxBufferChunkerAsChunker);
* }
*/
PARCChunker *parcChunker_Create(void *instance, PARCChunkerInterface *interface);
/**
* Create a new chunker to segment data contained in a file.
*
* @param [in] fileName The name of a file from which to read.
* @param [in] chunkSize The size per chunk.
*
* @retval PARCChunker A newly allocated `PARCChunker`
* @retval NULL An error occurred.
*
* Example
* @code
* {
* char *bigFileName = "big_file.bin";
* PARCChunker *chunker = parcChunker_CreateFromBuffer(bigFileName, 32);
* }
*/
//PARCChunker *parcChunker_CreateFromFile(char *fileName, size_t maxDataSize);
/**
* Increase the number of references to a `PARCChunker` instance.
*
* Note that new `PARCChunker` is not created,
* only that the given `PARCChunker` reference count is incremented.
* Discard the reference by invoking {@link parcChunker_Release}.
*
* @param [in] chunker A pointer to the original `PARCChunker`.
* @return The value of the input parameter @p chunker.
*
* Example:
* @code
* {
* PARCChunker *original = ...
*
* PARCChunker *reference = parcChunker_Acquire(original);
*
* parcChunker_Release(&original);
* parcChunker_Release(&reference);
* }
* @endcode
*
* @see parcChunker_Release
*/
PARCChunker *parcChunker_Acquire(const PARCChunker *chunker);
/**
* Release a previously acquired reference to the specified instance,
* decrementing the reference count for the instance.
*
* The pointer to the instance is set to NULL as a side-effect of this function.
*
* If the invocation causes the last reference to the instance to be released,
* the instance is deallocated and the instance's implementation will perform
* additional cleanup and release other privately held references.
*
* @param [in,out] chunkerP A pointer to a pointer to the instance to release.
*