S2OPC OPCUA Toolkit
|
A buffer of bytes with a maximum size, length and position. More...
Go to the source code of this file.
Data Structures | |
struct | SOPC_Buffer |
Bytes buffer structure. More... | |
Functions | |
SOPC_Buffer * | SOPC_Buffer_Create (uint32_t size) |
Allocate a buffer and its data bytes of the given definitive size and returns it. More... | |
SOPC_Buffer * | SOPC_Buffer_CreateResizable (uint32_t initial_size, uint32_t maximum_size) |
Allocate a resizable buffer and its initial and maximum data bytes. More... | |
SOPC_Buffer * | SOPC_Buffer_Attach (uint8_t *data, uint32_t size) |
Wraps a raw memory area into an SOPC_Buffer. More... | |
void | SOPC_Buffer_Clear (SOPC_Buffer *buffer) |
Deallocate buffer data bytes content. More... | |
void | SOPC_Buffer_Delete (SOPC_Buffer *buffer) |
Deallocate buffer and its data bytes content (Clear + deallocate pointer) More... | |
void | SOPC_Buffer_Reset (SOPC_Buffer *buffer) |
Reset length, position and data bytes to zero value of an allocated buffer. More... | |
SOPC_ReturnStatus | SOPC_Buffer_ResetAfterPosition (SOPC_Buffer *buffer, uint32_t position) |
reset data bytes after position (>=) to zero and set buffer position and length to given position More... | |
SOPC_ReturnStatus | SOPC_Buffer_GetPosition (SOPC_Buffer *buffer, uint32_t *position) |
Get buffer current position. More... | |
SOPC_ReturnStatus | SOPC_Buffer_SetPosition (SOPC_Buffer *buffer, uint32_t position) |
Set buffer to the given position. More... | |
SOPC_ReturnStatus | SOPC_Buffer_SetDataLength (SOPC_Buffer *buffer, uint32_t length) |
Set buffer to the given length. More... | |
SOPC_ReturnStatus | SOPC_Buffer_Write (SOPC_Buffer *buffer, const uint8_t *data_src, uint32_t count) |
Write the given bytes into the buffer data bytes from the buffer position (adapting buffer position and length if necessary) More... | |
SOPC_ReturnStatus | SOPC_Buffer_Read (uint8_t *data_dest, SOPC_Buffer *buffer, uint32_t count) |
Read the given bytes of the buffer data bytes from the buffer position (adapting buffer position to next position to read) More... | |
SOPC_ReturnStatus | SOPC_Buffer_Copy (SOPC_Buffer *dest, SOPC_Buffer *src) |
Copy the data bytes and properties from the source buffer to the destination buffer. More... | |
SOPC_ReturnStatus | SOPC_Buffer_CopyWithLength (SOPC_Buffer *dest, SOPC_Buffer *src, uint32_t limitedLength) |
Copy the data bytes and properties for the given length from the source buffer to the destination buffer. More... | |
uint32_t | SOPC_Buffer_Remaining (SOPC_Buffer *buffer) |
Returns the remaining number of unread bytes in the buffer. More... | |
int64_t | SOPC_Buffer_ReadFrom (SOPC_Buffer *buffer, SOPC_Buffer *src, uint32_t n) |
Reads n bytes from src into buffer . More... | |
SOPC_ReturnStatus | SOPC_Buffer_ReadFile (const char *path, SOPC_Buffer **buf) |
Reads the contents of a file into a SOPC_Buffer. More... | |
SOPC_ReturnStatus | SOPC_Buffer_PrintU32 (SOPC_Buffer *buf, const uint32_t value) |
Print the value into the buffer data bytes from the buffer position (adapting buffer position and length if necessary) There is no terminating NULL character added at the end of the printed value. More... | |
SOPC_ReturnStatus | SOPC_Buffer_PrintI32 (SOPC_Buffer *buf, const int32_t value) |
Print the value into the buffer data bytes from the buffer position (adapting buffer position and length if necessary) The I32 format written in the buffer does not take into account the spacing for '-' in the case of a positive value. There is no terminating NULL character added at the end of the printed value. More... | |
SOPC_ReturnStatus | SOPC_Buffer_PrintFloatDouble (SOPC_Buffer *buf, const double value) |
Print the value into the buffer data bytes from the buffer position (adapting buffer position and length if necessary) The float/double format written in the buffer does not take into account the spacing for '-' in the case of a positive value. The output is equivalent to '%.*g' print format with SOPC_PRECISION_PRINTING_FLOAT_NUMBERS as precision. There is no terminating NULL character added at the end of the printed value. More... | |
A buffer of bytes with a maximum size, length and position.
SOPC_Buffer* SOPC_Buffer_Create | ( | uint32_t | size | ) |
Allocate a buffer and its data bytes of the given definitive size and returns it.
size | The size of the data bytes allocated (static size). |
SOPC_Buffer* SOPC_Buffer_CreateResizable | ( | uint32_t | initial_size, |
uint32_t | maximum_size | ||
) |
Allocate a resizable buffer and its initial and maximum data bytes.
initial_size | The size of the data bytes allocated initially (also used as increment step) |
maximum_size | The size of the maximum data bytes finally allocated |
SOPC_Buffer* SOPC_Buffer_Attach | ( | uint8_t * | data, |
uint32_t | size | ||
) |
Wraps a raw memory area into an SOPC_Buffer.
data | A pointer the memory zone. |
size | The size of the memory zone. |
The ownership of the memory area is transferred to the SOPC_Buffer. In other words, the memory will be freed when SOPC_Buffer_Clear or SOPC_Buffer_Delete is called.
void SOPC_Buffer_Clear | ( | SOPC_Buffer * | buffer | ) |
Deallocate buffer data bytes content.
buffer | Pointer to the buffer in which data bytes content must be deallocated. |
void SOPC_Buffer_Delete | ( | SOPC_Buffer * | buffer | ) |
Deallocate buffer and its data bytes content (Clear + deallocate pointer)
buffer | Pointer to the buffer to deallocate (pointer must not be used anymore after operation) |
void SOPC_Buffer_Reset | ( | SOPC_Buffer * | buffer | ) |
Reset length, position and data bytes to zero value of an allocated buffer.
buffer | Pointer to the buffer to reset |
SOPC_ReturnStatus SOPC_Buffer_ResetAfterPosition | ( | SOPC_Buffer * | buffer, |
uint32_t | position | ||
) |
reset data bytes after position (>=) to zero and set buffer position and length to given position
buffer | Pointer to the buffer to reset to the given position |
position | New position of the reset buffer (position <= buffer->length) |
SOPC_ReturnStatus SOPC_Buffer_GetPosition | ( | SOPC_Buffer * | buffer, |
uint32_t * | position | ||
) |
Get buffer current position.
buffer | Pointer to the buffer from which to get current position |
position | Non-NULL pointer to store the current position of the buffer |
SOPC_ReturnStatus SOPC_Buffer_SetPosition | ( | SOPC_Buffer * | buffer, |
uint32_t | position | ||
) |
Set buffer to the given position.
buffer | Pointer to the buffer to set to the given position |
position | New position of the buffer (<= buffer->length) |
SOPC_ReturnStatus SOPC_Buffer_SetDataLength | ( | SOPC_Buffer * | buffer, |
uint32_t | length | ||
) |
Set buffer to the given length.
buffer | Pointer to the buffer to set to the given length |
length | New length of the buffer (<= buffer->maxsize && >= buffer->position) |
SOPC_ReturnStatus SOPC_Buffer_Write | ( | SOPC_Buffer * | buffer, |
const uint8_t * | data_src, | ||
uint32_t | count | ||
) |
Write the given bytes into the buffer data bytes from the buffer position (adapting buffer position and length if necessary)
buffer | Pointer to the buffer to write into |
data_src | Pointer to the bytes to be written in the buffer (HYP: nb bytes >= count bytes) |
count | Number of bytes to write in the buffer (count + buffer->position <= buffer->maxsize) |
SOPC_ReturnStatus SOPC_Buffer_Read | ( | uint8_t * | data_dest, |
SOPC_Buffer * | buffer, | ||
uint32_t | count | ||
) |
Read the given bytes of the buffer data bytes from the buffer position (adapting buffer position to next position to read)
data_dest | Pointer to the bytes to set to read bytes value of the buffer (HYP: nb bytes >= count bytes) If NULL ,then data are simply skipped |
buffer | Pointer to the buffer to read from |
count | Number of bytes to read from the buffer (count + buffer->position <= buffer->length) |
SOPC_ReturnStatus SOPC_Buffer_Copy | ( | SOPC_Buffer * | dest, |
SOPC_Buffer * | src | ||
) |
Copy the data bytes and properties from the source buffer to the destination buffer.
dest | Pointer to the destination buffer of the copy operation (dest->maxsize >= src->length) |
src | Pointer to the source buffer of the copy operation |
SOPC_ReturnStatus SOPC_Buffer_CopyWithLength | ( | SOPC_Buffer * | dest, |
SOPC_Buffer * | src, | ||
uint32_t | limitedLength | ||
) |
Copy the data bytes and properties for the given length from the source buffer to the destination buffer.
dest | Pointer to the destination buffer of the copy operation (dest->maxsize >= limitedLength) |
src | Pointer to the source buffer of the copy operation (src->length >= limitedLength, src->position <= limitedLength) |
limitedLength | The length to use for the copy, number of bytes copied and length set in destination buffer |
uint32_t SOPC_Buffer_Remaining | ( | SOPC_Buffer * | buffer | ) |
Returns the remaining number of unread bytes in the buffer.
buffer | The buffer. |
int64_t SOPC_Buffer_ReadFrom | ( | SOPC_Buffer * | buffer, |
SOPC_Buffer * | src, | ||
uint32_t | n | ||
) |
Reads n
bytes from src
into buffer
.
buffer | The buffer to read the bytes into. |
src | The source buffer. |
n | The maximum number of bytes to read. |
SOPC_ReturnStatus SOPC_Buffer_ReadFile | ( | const char * | path, |
SOPC_Buffer ** | buf | ||
) |
Reads the contents of a file into a SOPC_Buffer.
path | The path to the file. |
buf | Out parameter, points to a new buffer holding the contents of the file. This buffer should be freed by the caller. |
SOPC_STATUS_OK
on success, an error code in case of failure. SOPC_ReturnStatus SOPC_Buffer_PrintU32 | ( | SOPC_Buffer * | buf, |
const uint32_t | value | ||
) |
Print the value into the buffer data bytes from the buffer position (adapting buffer position and length if necessary) There is no terminating NULL character added at the end of the printed value.
value | uint32_t to print into the buffer |
buf | Pointer to the buffer to write into |
SOPC_ReturnStatus SOPC_Buffer_PrintI32 | ( | SOPC_Buffer * | buf, |
const int32_t | value | ||
) |
Print the value into the buffer data bytes from the buffer position (adapting buffer position and length if necessary) The I32 format written in the buffer does not take into account the spacing for '-' in the case of a positive value. There is no terminating NULL character added at the end of the printed value.
value | int32_t to print into the buffer |
buf | Pointer to the buffer to write into |
SOPC_ReturnStatus SOPC_Buffer_PrintFloatDouble | ( | SOPC_Buffer * | buf, |
const double | value | ||
) |
Print the value into the buffer data bytes from the buffer position (adapting buffer position and length if necessary) The float/double format written in the buffer does not take into account the spacing for '-' in the case of a positive value. The output is equivalent to '%.*g' print format with SOPC_PRECISION_PRINTING_FLOAT_NUMBERS as precision. There is no terminating NULL character added at the end of the printed value.
For exemple : '42', '-4.3e+111'
About special values, the syntax is as follows (including double quote) :
This format is JSON compatible for standard values.
value | double to print into the buffer |
buf | Pointer to the buffer to write into |