YAMI4Industry
Functions
serialization.h File Reference
#include "common.h"
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Functions

enum yami_result yami_put_type (uint8_t buffer[], size_t buffer_size, size_t *buffer_position, enum yami_parameter_type type)
 Places type indicator value in the serialization buffer. More...
 
enum yami_result yami_get_type (const uint8_t buffer[], size_t buffer_size, size_t *buffer_position, enum yami_parameter_type *type)
 Reads type code from the serialization buffer. More...
 
enum yami_result yami_put_integer (uint8_t buffer[], size_t buffer_size, size_t *buffer_position, int32_t value)
 Places integer value in the serialization buffer. More...
 
enum yami_result yami_get_integer (const uint8_t buffer[], size_t buffer_size, size_t *buffer_position, int32_t *value)
 Reads integer value from the serialization buffer. More...
 
enum yami_result yami_put_long_long (uint8_t buffer[], size_t buffer_size, size_t *buffer_position, int64_t value)
 Places long long value in the serialization buffer. More...
 
enum yami_result yami_get_long_long (const uint8_t buffer[], size_t buffer_size, size_t *buffer_position, int64_t *value)
 Reads long long value from the serialization buffer. More...
 
enum yami_result yami_put_cstring (uint8_t buffer[], size_t buffer_size, size_t *buffer_position, const char value[])
 Places string value in the serialization buffer. More...
 
enum yami_result yami_get_raw_cstring (const uint8_t buffer[], size_t buffer_size, size_t *buffer_position, char value[], size_t value_length)
 Reads raw string value from the serialization buffer. More...
 
enum yami_result yami_put_binary (uint8_t buffer[], size_t buffer_size, size_t *buffer_position, const uint8_t value[], size_t value_length)
 Places binary value in the serialization buffer. More...
 
enum yami_result yami_get_raw_binary (const uint8_t buffer[], size_t buffer_size, size_t *buffer_position, uint8_t value[], size_t value_length)
 Reads raw binary value from the serialization buffer. More...
 
enum yami_result yami_put_boolean_array (uint8_t buffer[], size_t buffer_size, size_t *buffer_position, const int32_t value[], size_t value_length)
 Places boolean array in the serialization buffer. More...
 
enum yami_result yami_get_raw_boolean_array (const uint8_t buffer[], size_t buffer_size, size_t *buffer_position, int32_t value[], size_t value_length)
 Reads raw boolean array from the serialization buffer. More...
 
enum yami_result yami_put_integer_array (uint8_t buffer[], size_t buffer_size, size_t *buffer_position, const int32_t value[], size_t value_length)
 Places integer array in the serialization buffer. More...
 
enum yami_result yami_get_raw_integer_array (const uint8_t buffer[], size_t buffer_size, size_t *buffer_position, int32_t value[], size_t value_length)
 Reads raw integer array from the serialization buffer. More...
 
enum yami_result yami_put_long_long_array (uint8_t buffer[], size_t buffer_size, size_t *buffer_position, const int64_t value[], size_t value_length)
 Places long long array in the serialization buffer. More...
 
enum yami_result yami_get_raw_long_long_array (const uint8_t buffer[], size_t buffer_size, size_t *buffer_position, int64_t value[], size_t value_length)
 Reads raw long long array from the serialization buffer. More...
 
enum yami_result yami_skip_field (const uint8_t buffer[], size_t buffer_size, size_t *buffer_position, enum yami_parameter_type type)
 Skips the given field in serialization buffer. More...
 
enum yami_result yami_fill_message_header (uint8_t buffer[], size_t buffer_size, size_t *buffer_position, const char object_name[], const char message_name[], int64_t message_id)
 Places message header fields in the serialization buffer. More...
 
void yami_fill_reply_header (uint8_t buffer[], size_t buffer_size, size_t *buffer_position, int64_t message_id)
 Places reply header fields in the serialization buffer. More...
 
enum yami_result yami_fill_exception_header (uint8_t buffer[], size_t buffer_size, size_t *buffer_position, const char reason[], int64_t message_id)
 Places exception header fields in the serialization buffer. More...
 
enum yami_result yami_parse_message_header (const uint8_t buffer[], size_t buffer_size, size_t *buffer_position, char out_header_type[], size_t header_type_size, char out_object_name[], size_t object_name_size, char out_message_name[], size_t message_name_size, char out_reason[], size_t reason_size, int64_t *out_message_id)
 Parses message header. More...
 
void yami_fill_frame_header (uint8_t buffer[], uint32_t message_id, size_t message_header_size, size_t frame_payload_size)
 
enum yami_result yami_parse_frame_header (const uint8_t buffer[], size_t buffer_size, size_t *buffer_position, uint32_t *message_id, size_t *message_header_size, size_t *frame_payload_size)
 

Function Documentation

enum yami_result yami_fill_exception_header ( uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
const char  reason[],
int64_t  message_id 
)

Places exception header fields in the serialization buffer.

Places exception header fields in the serialization buffer at the specified index and advances the index to the position after the header.

Parameters
buffer(in/out) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the new value should be written
reasonexception reason
message_idmessage identifier
Returns
yami_ok or yami_not_enough_space
void yami_fill_frame_header ( uint8_t  buffer[],
uint32_t  message_id,
size_t  message_header_size,
size_t  frame_payload_size 
)
enum yami_result yami_fill_message_header ( uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
const char  object_name[],
const char  message_name[],
int64_t  message_id 
)

Places message header fields in the serialization buffer.

Places message header fields in the serialization buffer at the specified index and advances the index to the position after the header.

Parameters
buffer(in/out) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the new value should be written
object_nametarget object name
message_nametarget message name
message_idmessage identifier
Returns
yami_ok or yami_not_enough_space
void yami_fill_reply_header ( uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
int64_t  message_id 
)

Places reply header fields in the serialization buffer.

Places reply header fields in the serialization buffer at the specified index and advances the index to the position after the header. This function assumes that the buffer is big enough and does not check the buffer size.

Parameters
buffer(in/out) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the new value should be written
message_idmessage identifier
enum yami_result yami_get_integer ( const uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
int32_t *  value 
)

Reads integer value from the serialization buffer.

Reads integer value from the serialization buffer from the specified index and advances the index to the position immediately after the value that was read.

Parameters
buffer(in) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the value should be read from
value(out) integer value to be read
Returns
yami_ok or yami_not_enough_space
enum yami_result yami_get_long_long ( const uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
int64_t *  value 
)

Reads long long value from the serialization buffer.

Reads long long value from the serialization buffer from the specified index and advances the index to the position immediately after the value that was read.

Parameters
buffer(in) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the value should be read from
value(out) long long value to be read
Returns
yami_ok or yami_not_enough_space
enum yami_result yami_get_raw_binary ( const uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
uint8_t  value[],
size_t  value_length 
)

Reads raw binary value from the serialization buffer.

Reads raw binary value from the serialization buffer from the specified index and advances the index to the position immediately after the value that was read. Note: The binary is read without the length prefix, so it is assumed that the caller has already read the length prefix and has allocated the buffer that is big enough to accommodate the output.

Parameters
buffer(in) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the value should be read from
value(out) buffer to store the binary value
value_lengthlength of binary to read
Returns
yami_ok or yami_not_enough_space
enum yami_result yami_get_raw_boolean_array ( const uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
int32_t  value[],
size_t  value_length 
)

Reads raw boolean array from the serialization buffer.

Reads raw boolean array from the serialization buffer from the specified index and advances the index to the position immediately after the value that was read. Note: The array is read without the length prefix, so it is assumed that the caller has already read the length prefix and has allocated the buffer that is big enough to accommodate the output. The array is read in an unpacked form.

Parameters
buffer(in) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the value should be read from
value(out) buffer to store the array value
value_lengthlength of array to read
Returns
yami_ok or yami_not_enough_space
enum yami_result yami_get_raw_cstring ( const uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
char  value[],
size_t  value_length 
)

Reads raw string value from the serialization buffer.

Reads raw string value from the serialization buffer from the specified index and advances the index to the position immediately after the value that was read. Note: The string is read without the length prefix, so it is assumed that the caller has already read the length prefix and has allocated the buffer that is big enough to accommodate the output, together with the nul character that is appended after the extracted value.

Parameters
buffer(in) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the value should be read from
value(out) buffer to store the string
value_lengthlength of string to read
Returns
yami_ok or yami_not_enough_space
enum yami_result yami_get_raw_integer_array ( const uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
int32_t  value[],
size_t  value_length 
)

Reads raw integer array from the serialization buffer.

Reads raw integer array from the serialization buffer from the specified index and advances the index to the position immediately after the value that was read. Note: The array is read without the length prefix, so it is assumed that the caller has already read the length prefix and has allocated the buffer that is big enough to accommodate the output.

Parameters
buffer(in) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the value should be read from
value(out) buffer to store the array value
value_lengthlength of array to read
Returns
yami_ok or yami_not_enough_space
enum yami_result yami_get_raw_long_long_array ( const uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
int64_t  value[],
size_t  value_length 
)

Reads raw long long array from the serialization buffer.

Reads raw long long array from the serialization buffer from the specified index and advances the index to the position immediately after the value that was read. Note: The array is read without the length prefix, so it is assumed that the caller has already read the length prefix and has allocated the buffer that is big enough to accommodate the output.

Parameters
buffer(in) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the value should be read from
value(out) buffer to store the array value
value_lengthlength of array to read
Returns
yami_ok or yami_not_enough_space
enum yami_result yami_get_type ( const uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
enum yami_parameter_type type 
)

Reads type code from the serialization buffer.

Reads type code from the serialization buffer from the specified index and advances the index to the position immediately after the value that was read.

Parameters
buffer(in) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the value should be read from
type(out) type code to be read
Returns
yami_ok or yami_unexpected_value or yami_not_enough_space
enum yami_result yami_parse_frame_header ( const uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
uint32_t *  message_id,
size_t *  message_header_size,
size_t *  frame_payload_size 
)
enum yami_result yami_parse_message_header ( const uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
char  out_header_type[],
size_t  header_type_size,
char  out_object_name[],
size_t  object_name_size,
char  out_message_name[],
size_t  message_name_size,
char  out_reason[],
size_t  reason_size,
int64_t *  out_message_id 
)

Parses message header.

Parses message header and extracts individual fields. Note: only those fields which are found in the header are returned, the remaining parameters are set to empty strings or to 0.

Parameters
buffer(in) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the header values should be read from
out_header_typeset to the value of "type" field, this field is expected
header_type_sizemax length of the header type (char buffer size)
out_object_nameset to the value of "object_name" field, if found
object_name_sizemax length of object name (char buffer size)
out_message_nameset to the value of "message_name" field, if found
message_name_sizemax length of message name (char buffer size)
out_reasonset to the value of "reason" field, if found
reason_sizemax length of reason (char buffer size)
out_message_idset to the value of "message_id" field, this field is expected
Returns
yami_ok if the header was parsed correctly, yami_no_such_name if the header lacks expected fields or yami_not_enough_space if the output parameters are too small or yami_unexpected_value if the buffer contains unrecognized data
enum yami_result yami_put_binary ( uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
const uint8_t  value[],
size_t  value_length 
)

Places binary value in the serialization buffer.

Places binary value in the serialization buffer at the specified index and advances the index to the position after the written value. Note: The function stores the length prefix before the binary itself.

Parameters
buffer(in/out) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the new value should be written
valuebinary value to be written
value_lengthlength of the binary value
Returns
yami_ok or yami_not_enough_space
enum yami_result yami_put_boolean_array ( uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
const int32_t  value[],
size_t  value_length 
)

Places boolean array in the serialization buffer.

Places boolean array in the serialization buffer at the specified index and advances the index to the position after the written value. Note: The function stores the length prefix before the array itself. The boolean array is stored in the packed form, properly padded.

Parameters
buffer(in/out) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the new value should be written
valueboolean array to be written, each array field contains a single boolean value
value_lengthlength of the array
Returns
yami_ok or yami_not_enough_space
enum yami_result yami_put_cstring ( uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
const char  value[] 
)

Places string value in the serialization buffer.

Places string value in the serialization buffer at the specified index and advances the index to the position after the written value. Note: It is assumed that the string is nul-terminated and the function will stop copying characters at the first nul character. The function stores the length prefix before the string itself; the length does not take into account the nul character.

Parameters
buffer(in/out) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the new value should be written
valuestring value to be written, nul-terminated
Returns
yami_ok or yami_not_enough_space
enum yami_result yami_put_integer ( uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
int32_t  value 
)

Places integer value in the serialization buffer.

Places integer value in the serialization buffer at the specified index and advances the index to the position immediately after the written value.

Parameters
buffer(in/out) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the new value should be written
valueinteger value to be written
Returns
yami_ok or yami_not_enough_space
enum yami_result yami_put_integer_array ( uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
const int32_t  value[],
size_t  value_length 
)

Places integer array in the serialization buffer.

Places integer array in the serialization buffer at the specified index and advances the index to the position after the written value. Note: The function stores the length prefix before the array itself.

Parameters
buffer(in/out) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the new value should be written
valueinteger array to be written
value_lengthlength of the array
Returns
yami_ok or yami_not_enough_space
enum yami_result yami_put_long_long ( uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
int64_t  value 
)

Places long long value in the serialization buffer.

Places long long value in the serialization buffer at the specified index and advances the index to the position immediately after the written value.

Parameters
buffer(in/out) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the new value should be written
valuelong long value to be written
Returns
yami_ok or yami_not_enough_space
enum yami_result yami_put_long_long_array ( uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
const int64_t  value[],
size_t  value_length 
)

Places long long array in the serialization buffer.

Places long long array in the serialization buffer at the specified index and advances the index to the position after the written value. Note: The function stores the length prefix before the array itself.

Parameters
buffer(in/out) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the new value should be written
valuelong long array to be written
value_lengthlength of the array
Returns
yami_ok or yami_not_enough_space
enum yami_result yami_put_type ( uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
enum yami_parameter_type  type 
)

Places type indicator value in the serialization buffer.

Places type indicator value in the serialization buffer at the specified index and advances the index to the position immediately after the written value.

Parameters
buffer(in/out) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array where the new value should be written
typetype code to be written
Returns
yami_ok or yami_not_enough_space
enum yami_result yami_skip_field ( const uint8_t  buffer[],
size_t  buffer_size,
size_t *  buffer_position,
enum yami_parameter_type  type 
)

Skips the given field in serialization buffer.

Skips the field of the given type in the serialization buffer. This function can be particularly useful when processing fields that can have varying length (strings, binaries and arrays).

Parameters
buffer(in) serialization buffer
buffer_sizesize of the serialization buffer
buffer_position(in/out) position (in bytes) in the buffer array
typetype of the field to be skipped
Returns
yami_ok or yami_not_enough_space