obiblob.h 3.01 KB
Newer Older
1
/****************************************************************************
2
 * Obiblob header file	                                                    *
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 ****************************************************************************/

/**
 * @file obiblob.h
 * @author Celine Mercier
 * @date November 18th 2015
 * @brief Header file for handling Obi_blob structures.
 */


#ifndef OBIBLOB_H_
#define OBIBLOB_H_


#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>

#include "obitypes.h"


24 25
#define ELEMENT_SIZE_STR (8)		/**< The size of an element from a value of type character string.
                              	  	 */
26 27
#define ELEMENT_SIZE_UINT8 (8)		/**< The size of an element from a value of type uint8_t.
                              	  	 */
28 29 30 31
#define ELEMENT_SIZE_SEQ_2 (2)		/**< The size of an element from a value of type DNA sequence encoded on 2 bits.
                              	  	 */
#define ELEMENT_SIZE_SEQ_4 (4)		/**< The size of an element from a value of type DNA sequence encoded on 4 bits.
                              	  	 */
32 33 34


/**
35
 * @brief Blob structure, for handling encoded values.
36 37
 */
typedef struct Obi_blob {
38
	uint8_t  element_size;		 	/**< Size in bits of one element from the encoded value.
39 40 41 42 43 44 45 46 47 48
	 	 	 	 	 	 	 	 	 */
	int32_t  length_encoded_value;	/**< Length in bytes of the encoded value.
	 	 	 	 	 	 	 	 	 */
	int32_t  length_decoded_value;	/**< Length in bytes of the decoded value.
	 	 	 	 	 	 	 	 	 */
	byte_t   value[];				/**< Encoded value.
	 	 	 	 	 	 	 	 	 */
} Obi_blob_t, *Obi_blob_p;


Celine Mercier committed
49

50 51 52 53 54 55 56 57 58 59 60 61 62 63
/**
 * @brief Function building a blob structure.
 *
 * @param encoded_value A pointer to the encoded value that will be stored in the blob.
 * @param element_size The size in bits of one element from the encoded value.
 * @param length_encoded_value The length in bytes of the encoded value.
 * @param length_decoded_value The length in bytes of the decoded value.
 *
 * @returns A pointer to the created blob structure.
 * @retval NULL if an error occurred.
 *
 * @since April 2016
 * @author Celine Mercier (celine.mercier@metabarcoding.org)
 */
Celine Mercier committed
64 65 66
Obi_blob_p obi_blob(byte_t* encoded_value, uint8_t element_size, int32_t length_encoded_value, int32_t length_decoded_value);


67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
/**
 * @brief Function comparing two blobs.
 *
 * The encoding is compared first, then the length of the
 * values, then the values themselves.
 *
 * @param value_1 A pointer to the first blob structure.
 * @param value_2 A pointer to the second blob structure.
 *
 * @returns A value < 0 if value_1 < value_2,
 * 			a value > 0 if value_1 > value_2,
 * 			and 0 if value_1 == value_2.
 *
 * @since October 2015
 * @author Celine Mercier (celine.mercier@metabarcoding.org)
 */
int obi_blob_compare(Obi_blob_p value_1, Obi_blob_p value_2);


/**
 * @brief Function calculating the size in bytes of a blob.
 *
 * @param value A pointer to the blob structure.
 *
 * @returns The size of the blob in bytes.
 *
 * @since October 2015
 * @author Celine Mercier (celine.mercier@metabarcoding.org)
 */
int obi_blob_sizeof(Obi_blob_p value);


99 100
#endif /* OBIBLOB_H_ */