uint8_indexer.c 1.51 KB
Newer Older
1
/****************************************************************************
2
 * Uint8 indexing functions                               *
3 4 5
 ****************************************************************************/

/**
6
 * @file uint8_indexer.c
7 8
 * @author Celine Mercier
 * @date May 4th 2016
9
 * @brief Functions handling the indexing and retrieval of uint8 arrays.
10 11 12 13 14
 */


#include <stdlib.h>
#include <stdio.h>
15
#include <stdint.h>
16 17
#include <math.h>

18
#include "uint8_indexer.h"
19 20 21 22 23 24 25 26 27
#include "obiblob.h"
#include "obiblob_indexer.h"
#include "obidebug.h"
#include "obitypes.h"


#define DEBUG_LEVEL 0	// TODO has to be defined somewhere else (cython compil flag?)


28
Obi_blob_p obi_uint8_to_blob(const uint8_t* value, int value_length)
29
{
30
	return obi_blob((byte_t*)value, ELEMENT_SIZE_UINT8, value_length, value_length);
31 32 33
}


34
const uint8_t* obi_blob_to_uint8(Obi_blob_p value_b)
35
{
36
	return ((uint8_t*) (value_b->value));
37 38 39
}


40
index_t obi_index_uint8(Obi_indexer_p indexer, const uint8_t* value, int value_length)
41 42 43 44 45
{
	Obi_blob_p  value_b;
	index_t 	idx;

	// Encode value
46
	value_b = obi_uint8_to_blob(value, value_length);
47 48 49 50 51 52 53 54 55 56 57 58
	if (value_b == NULL)
		return -1;

	// Add in the indexer
	idx = obi_indexer_add(indexer, value_b);

	free(value_b);

	return idx;
}


59
const uint8_t* obi_retrieve_uint8(Obi_indexer_p indexer, index_t idx, int* value_length)
60 61 62 63 64 65 66
{
	Obi_blob_p  value_b;

	// Get encoded value
	value_b = obi_indexer_get(indexer, idx);

	// Return decoded sequence
67 68
	*value_length = value_b->length_decoded_value;
	return obi_blob_to_uint8(value_b);
69 70
}