KM3NeT CLB
2.0
KM3NeT CLB v2 Embedded Software
|
DataBuffer reads and writes data into a buffer in the same format as defined in the data Java DataOutput / DataInput interfaces. More...
Go to the source code of this file.
Data Structures | |
struct | DataBuffer |
Defines a DataBuffer structure. More... | |
Macros | |
#define | DB_ERR_NONE 0x00 |
Indicates no error. | |
#define | DB_ERR_INVALID_BUFFER 0x01 |
Indicates an invalid buffer. | |
#define | DB_ERR_END_OF_BUFFER 0x02 |
Indicates the end of the buffer has been reached. | |
#define | DB_ERR_NOT_SUPPORTED 0x03 |
De type is not supported. More... | |
#define | DB_STR_OVERHEAD 2 |
Overhead for a String. | |
#define | DB_BUF_INIT(PTR, LEN) { .start = PTR, .cur = PTR, .end = PTR + LEN, .error = DB_ERR_NONE } |
Simple buffer initialization. More... | |
Functions | |
static void | dbReset (DataBuffer *buf) |
Resets the buffer to its initial state. More... | |
static uint32_t | dbLength (DataBuffer *buf) |
Returns the lenght of the current buffer. More... | |
static uint32_t | dbFree (DataBuffer *buf) |
Returns the number of bytes still free in the buffer. More... | |
bool | dbSkip (DataBuffer *buf, size_t skipSize) |
Skips a number of bytes in the buffer. More... | |
static uint32_t | dbSize (DataBuffer *buf) |
Returns the total size of the buffer. More... | |
bool | dbWrite (DataBuffer *buf, uint8_t *buffer, int len) |
Writes the given buffer with the specified length. More... | |
bool | dbRead (DataBuffer *buf, uint8_t *buffer, int len) |
Reads into given buffer with the specified length. More... | |
bool | dbWriteI8 (DataBuffer *buf, int8_t byte) |
Writes a byte. More... | |
bool | dbReadI8 (DataBuffer *buf, int8_t *byte) |
Reads an byte. More... | |
bool | dbWriteU8 (DataBuffer *buf, uint8_t byte) |
Writes a unsigned byte. More... | |
bool | dbReadU8 (DataBuffer *buf, uint8_t *byte) |
Reads an unsigned byte. More... | |
bool | dbWriteF32 (DataBuffer *buf, f32_t flt) |
Writes a 32-bit floating point. More... | |
bool | dbReadF32 (DataBuffer *buf, f32_t *flt) |
Reads an 32-bit floating point. More... | |
bool | dbWriteF64 (DataBuffer *buf, f64_t flt) |
Writes a 64-bit floating point. More... | |
bool | dbReadF64 (DataBuffer *buf, f64_t *flt) |
Reads an 64-bit floating point. More... | |
static bool | dbWriteBool (DataBuffer *buf, bool boolean) |
Writes a boolean. More... | |
static bool | dbReadBool (DataBuffer *buf, bool *boolean) |
Reads a boolean. More... | |
bool | dbWriteI16 (DataBuffer *buf, int16_t i) |
Writes a short (16 bits signed) integer. More... | |
bool | dbWriteU16 (DataBuffer *buf, uint16_t u) |
Writes a unsigned short (16 bits unsigned) integer. More... | |
bool | dbReadI16 (DataBuffer *buf, int16_t *i) |
Reads a short (16 bits signed) integer. More... | |
bool | dbReadU16 (DataBuffer *buf, uint16_t *u) |
Reads a unsigned short (16 bits unsigned) integer. More... | |
bool | dbWriteI32 (DataBuffer *buf, int32_t i) |
Writes an 32 bits signed integer. More... | |
bool | dbWriteU32 (DataBuffer *buf, uint32_t u) |
Writes an 32 bits unsigned integer. More... | |
bool | dbReadI32 (DataBuffer *buf, int32_t *i) |
Reads an 32 bits signed integer. More... | |
bool | dbReadU32 (DataBuffer *buf, uint32_t *u) |
Reads an 32 bits unsigned integer. More... | |
bool | dbWriteI64 (DataBuffer *buf, int64_t i) |
Writes an 64 bits signed integer. More... | |
bool | dbReadI64 (DataBuffer *buf, int64_t *i) |
Reads an 64 bits signed integer. More... | |
bool | dbWriteU64 (DataBuffer *buf, uint64_t i) |
Writes an 64 bits unsigned integer. More... | |
bool | dbReadU64 (DataBuffer *buf, uint64_t *i) |
Reads an 64 bits unsigned integer. More... | |
bool | dbWriteString (DataBuffer *buf, const char *s, int max) |
Writes a String as 'sort of' UTF-8 encoding, as defined in the Java DataOuput and DataInput writeUTF / readUTF methods. More... | |
bool | dbReadString (DataBuffer *buf, char *s, int size) |
Reads a string from the stream. More... | |
DataBuffer reads and writes data into a buffer in the same format as defined in the data Java DataOutput / DataInput interfaces.
Supported are: the 'Write', Byte, Short, Int, Long and Boolean.
Definition in file databuffer.h.
#define DB_BUF_INIT | ( | PTR, | |
LEN | |||
) | { .start = PTR, .cur = PTR, .end = PTR + LEN, .error = DB_ERR_NONE } |
Simple buffer initialization.
Usage: char buf[80]; DataBuffer db = DB_BUF_INIT( buf, sizeof(buf) );
PTR | The pointer to the start of the buffer. |
LEN | The length of the buffer in bytes. |
Definition at line 63 of file databuffer.h.
#define DB_ERR_NOT_SUPPORTED 0x03 |
De type is not supported.
Definition at line 37 of file databuffer.h.
|
inlinestatic |
Returns the number of bytes still free in the buffer.
buf | The buffer to query. |
Definition at line 95 of file databuffer.h.
|
inlinestatic |
Returns the lenght of the current buffer.
buf | The buffer to query. |
Definition at line 83 of file databuffer.h.
bool dbRead | ( | DataBuffer * | buf, |
uint8_t * | buffer, | ||
int | len | ||
) |
Reads into given buffer with the specified length.
buffer | The buffer to copy in to. |
len | The number of bytes to copy |
true | Success |
false | Failure, check buf.error |
Definition at line 48 of file databuffer.c.
|
inlinestatic |
Reads a boolean.
buf | The buffer to read from. |
boolean | The boolean. |
true | Success |
false | Failure, check buf.error |
Definition at line 263 of file databuffer.h.
bool dbReadF32 | ( | DataBuffer * | buf, |
f32_t * | flt | ||
) |
Reads an 32-bit floating point.
buf | The buffer to read from. |
flt | The the byte |
true | Success |
false | Failure, check buf.error |
Definition at line 340 of file databuffer.c.
bool dbReadF64 | ( | DataBuffer * | buf, |
f64_t * | flt | ||
) |
Reads an 64-bit floating point.
buf | The buffer to read from. |
flt | The the byte |
true | Success |
false | Failure, check buf.error |
Definition at line 345 of file databuffer.c.
bool dbReadI16 | ( | DataBuffer * | buf, |
int16_t * | i | ||
) |
Reads a short (16 bits signed) integer.
buf | The buffer to write into. |
i | Pointer to a 16 bit signed integer. Will write the value to the location of the pointer. |
true | Success |
false | Failure, check buf.error |
Definition at line 194 of file databuffer.c.
bool dbReadI32 | ( | DataBuffer * | buf, |
int32_t * | i | ||
) |
Reads an 32 bits signed integer.
buf | The buffer to write into. |
i | Pointer to the 32 bit signed integer. Will write the value to the location of the pointer. |
true | Success |
false | Failure, check buf.error |
Definition at line 262 of file databuffer.c.
bool dbReadI64 | ( | DataBuffer * | buf, |
int64_t * | i | ||
) |
Reads an 64 bits signed integer.
buf | The buffer to write into. |
i | Pointer to the 64 bit signed integer. Will write the value to the location of the pointer. |
true | Success |
false | Failure, check buf.error |
Definition at line 284 of file databuffer.c.
bool dbReadI8 | ( | DataBuffer * | buf, |
int8_t * | byte | ||
) |
Reads an byte.
buf | The buffer to read from. |
byte | The the byte |
true | Success |
false | Failure, check buf.error |
Definition at line 136 of file databuffer.c.
bool dbReadString | ( | DataBuffer * | buf, |
char * | s, | ||
int | size | ||
) |
Reads a string from the stream.
Values which are out of the range of this sytems char type are replaced with a question mark.
buf | The buffer to read from. |
s | The target string pointer with pre-allocated memory |
size | The size of hte target memory to prevent overflow. |
true | Success |
false | Failure, check buf.error |
Definition at line 103 of file databuffer.c.
bool dbReadU16 | ( | DataBuffer * | buf, |
uint16_t * | u | ||
) |
Reads a unsigned short (16 bits unsigned) integer.
buf | The buffer to write into. |
u | Pointer to a 16 bit unsigned integer. Will write the value to the location of the pointer. |
true | Success |
false | Failure, check buf.error |
Definition at line 186 of file databuffer.c.
bool dbReadU32 | ( | DataBuffer * | buf, |
uint32_t * | u | ||
) |
Reads an 32 bits unsigned integer.
buf | The buffer to write into. |
u | Pointer to the 32 bit unsigned integer. Will write the value to the location of the pointer. |
true | Success |
false | Failure, check buf.error |
Definition at line 219 of file databuffer.c.
bool dbReadU64 | ( | DataBuffer * | buf, |
uint64_t * | i | ||
) |
Reads an 64 bits unsigned integer.
buf | The buffer to write into. |
i | Pointer to the 64 bit unsigned integer. Will write the value to the location of the pointer. |
true | Success |
false | Failure, check buf.error |
Definition at line 230 of file databuffer.c.
bool dbReadU8 | ( | DataBuffer * | buf, |
uint8_t * | byte | ||
) |
Reads an unsigned byte.
buf | The buffer to read from. |
byte | The the byte |
true | Success |
false | Failure, check buf.error |
Definition at line 153 of file databuffer.c.
|
inlinestatic |
Resets the buffer to its initial state.
buf | The buffer to reset. |
Definition at line 70 of file databuffer.h.
|
inlinestatic |
Returns the total size of the buffer.
buf | The buffer to query. |
Definition at line 119 of file databuffer.h.
bool dbSkip | ( | DataBuffer * | buf, |
size_t | skipSize | ||
) |
Skips a number of bytes in the buffer.
buf | The buffer. |
skipSize | The number of bytes to skip |
true | Success |
false | Failure, check buf.error. Prolly not so many bytes available. |
Definition at line 179 of file databuffer.c.
bool dbWrite | ( | DataBuffer * | buf, |
uint8_t * | buffer, | ||
int | len | ||
) |
Writes the given buffer with the specified length.
buffer | The buffer to copy |
len | The number of bytes to copy |
true | Success |
false | Failure, check buf.error |
Definition at line 40 of file databuffer.c.
|
inlinestatic |
Writes a boolean.
buf | The buffer to write into. |
boolean | The boolean. |
true | Success |
false | Failure, check buf.error |
Definition at line 249 of file databuffer.h.
bool dbWriteF32 | ( | DataBuffer * | buf, |
f32_t | flt | ||
) |
Writes a 32-bit floating point.
buf | The buffer to write into. |
flt | The floating-point number. |
true | Success |
false | Failure, check buf.error |
Definition at line 318 of file databuffer.c.
bool dbWriteF64 | ( | DataBuffer * | buf, |
f64_t | flt | ||
) |
Writes a 64-bit floating point.
buf | The buffer to write into. |
flt | The floating-point number. |
true | Success |
false | Failure, check buf.error |
Definition at line 332 of file databuffer.c.
bool dbWriteI16 | ( | DataBuffer * | buf, |
int16_t | i | ||
) |
Writes a short (16 bits signed) integer.
buf | The buffer to write into. |
i | The 16 bit signed integer to write. |
true | Success |
false | Failure, check buf.error |
Definition at line 173 of file databuffer.c.
bool dbWriteI32 | ( | DataBuffer * | buf, |
int32_t | i | ||
) |
Writes an 32 bits signed integer.
buf | The buffer to write into. |
i | The 32 bit signed integer. |
true | Success |
false | Failure, check buf.error |
Definition at line 213 of file databuffer.c.
bool dbWriteI64 | ( | DataBuffer * | buf, |
int64_t | i | ||
) |
Writes an 64 bits signed integer.
buf | The buffer to write into. |
i | The 64 bit signed integer. |
true | Success |
false | Failure, check buf.error |
Definition at line 269 of file databuffer.c.
bool dbWriteI8 | ( | DataBuffer * | buf, |
int8_t | byte | ||
) |
Writes a byte.
buf | The buffer to write into. |
byte | The byte. |
true | Success |
false | Failure, check buf.error |
Definition at line 129 of file databuffer.c.
bool dbWriteString | ( | DataBuffer * | buf, |
const char * | s, | ||
int | max | ||
) |
Writes a String as 'sort of' UTF-8 encoding, as defined in the Java DataOuput and DataInput writeUTF / readUTF methods.
However, it does not write any characters above ASCII value 127. If these values are encountered, a '@' (at) sign will be inserted instead.
buf | The buffer to write to |
s | The string to write (must be null-terminated!) |
max | The maximum bytes in buffer it should use. Else string is truncated. |
true | Success |
false | Failure, check buf.error |
Definition at line 74 of file databuffer.c.
bool dbWriteU16 | ( | DataBuffer * | buf, |
uint16_t | u | ||
) |
Writes a unsigned short (16 bits unsigned) integer.
buf | The buffer to write into. |
u | The 16 bit unsigned integer to write. |
true | Success |
false | Failure, check buf.error |
Definition at line 162 of file databuffer.c.
bool dbWriteU32 | ( | DataBuffer * | buf, |
uint32_t | u | ||
) |
Writes an 32 bits unsigned integer.
buf | The buffer to write into. |
u | The 32 bit unsigned integer. |
true | Success |
false | Failure, check buf.error |
Definition at line 200 of file databuffer.c.
bool dbWriteU64 | ( | DataBuffer * | buf, |
uint64_t | i | ||
) |
Writes an 64 bits unsigned integer.
buf | The buffer to write into. |
i | The 64 bit signed integer. |
true | Success |
false | Failure, check buf.error |
Definition at line 245 of file databuffer.c.
bool dbWriteU8 | ( | DataBuffer * | buf, |
uint8_t | byte | ||
) |
Writes a unsigned byte.
buf | The buffer to write into. |
byte | The byte. |
true | Success |
false | Failure, check buf.error |
Definition at line 146 of file databuffer.c.