58 lines
1.5 KiB
C
58 lines
1.5 KiB
C
/****************************************************************************
|
|
* Obiblob functions *
|
|
****************************************************************************/
|
|
|
|
/**
|
|
* @file obiblob.c
|
|
* @author Celine Mercier
|
|
* @date April 11th 2016
|
|
* @brief Functions handling Obiblob structures.
|
|
*/
|
|
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <math.h>
|
|
|
|
#include "obiblob.h"
|
|
#include "obierrno.h"
|
|
#include "obitypes.h" // For byte_t type
|
|
#include "obidebug.h"
|
|
|
|
|
|
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
|
|
|
|
|
// TODO: endianness problem?
|
|
|
|
|
|
Obi_blob_p obi_blob(byte_t* encoded_value, uint8_t element_size, int32_t length_encoded_value, int32_t length_decoded_value)
|
|
{
|
|
Obi_blob_p blob;
|
|
|
|
// Allocate the memory for the blob structure
|
|
blob = (Obi_blob_p) malloc(sizeof(Obi_blob_t) + length_encoded_value);
|
|
if (blob == NULL)
|
|
{
|
|
obi_set_errno(OBI_MALLOC_ERROR);
|
|
obidebug(1, "\nError allocating memory for a blob");
|
|
return NULL;
|
|
}
|
|
|
|
// Store the number of bits on which each element is encoded
|
|
blob->element_size = element_size;
|
|
|
|
// Store the length (in bytes) of the encoded value
|
|
blob->length_encoded_value = length_encoded_value;
|
|
|
|
// Store the initial length (in bytes) of the decoded value
|
|
blob->length_decoded_value = length_decoded_value;
|
|
|
|
// Store the encoded value
|
|
memcpy(blob->value, encoded_value, length_encoded_value);
|
|
|
|
return blob;
|
|
}
|
|
|