Port serial to new memory format
This commit is contained in:
1 parent
77195fb1d0
commit
256ff916a2
16 files changed
+218
-240
No files matched your search
@@ -155,6 +155,9 @@ M_SHARED_PTR_DEF(shared_str, string_t)
|
||||
M_QUEUE_DEF(queue_10, int, 10 )
|
||||
M_STACK_DEF(stack_20, string_t, 20)
|
||||
|
||||
#include "m-serial-json.h"
|
||||
|
||||
#include "m-serial-bin.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
@@ -1050,22 +1050,21 @@
|
||||
, /* no IN_STR & INIT */ ) \
|
||||
\
|
||||
M_IF_METHOD(OUT_SERIAL, oplist)( \
|
||||
M_INLINE m_serial_return_code_t \
|
||||
M_F(name, _out_serial)(m_serial_write_t f, const array_t array) \
|
||||
M_P(m_serial_return_code_t, name, _out_serial, m_serial_write_t f, const array_t array) \
|
||||
{ \
|
||||
M_ARRA4_CONTRACT(array); \
|
||||
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||
m_serial_return_code_t ret; \
|
||||
m_serial_local_t local; \
|
||||
ret = f->m_interface->write_array_start(local, f, array->size); \
|
||||
ret = f->m_interface->write_array_start M_R(local, f, array->size); \
|
||||
for (size_t i = 0; i < array->size; i++) { \
|
||||
type const *item = M_F(name, _cget)(array, i); \
|
||||
if (i != 0) { \
|
||||
ret |= f->m_interface->write_array_next(local, f); \
|
||||
ret |= f->m_interface->write_array_next M_R(local, f); \
|
||||
} \
|
||||
ret |= M_CALL_OUT_SERIAL(oplist, f, *item); \
|
||||
} \
|
||||
ret |= f->m_interface->write_array_end(local, f); \
|
||||
ret |= f->m_interface->write_array_end M_R(local, f); \
|
||||
return ret & M_SERIAL_FAIL; \
|
||||
} \
|
||||
, /* no OUT_SERIAL */ ) \
|
||||
|
||||
+8
-9
@@ -1383,8 +1383,7 @@
|
||||
, /* no in_str */ ) \
|
||||
\
|
||||
M_IF_METHOD_BOTH(OUT_SERIAL, key_oplist, value_oplist)( \
|
||||
M_INLINE m_serial_return_code_t \
|
||||
M_F(name, _out_serial)(m_serial_write_t f, tree_t const t1) \
|
||||
M_P(m_serial_return_code_t, name, _out_serial, m_serial_write_t f, tree_t const t1) \
|
||||
{ \
|
||||
M_BPTR33_CONTRACT(N, isMulti, key_oplist, t1); \
|
||||
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||
@@ -1396,31 +1395,31 @@
|
||||
/* Format is different between associative container \
|
||||
& set container */ \
|
||||
M_IF(isMap)( \
|
||||
ret = f->m_interface->write_map_start(local, f, t1->size); \
|
||||
ret = f->m_interface->write_map_start M_R(local, f, t1->size); \
|
||||
for (M_F(name, _it)(it, t1) ; \
|
||||
!M_F(name, _end_p)(it); \
|
||||
M_F(name, _next)(it)){ \
|
||||
item = M_F(name, _cref)(it); \
|
||||
if (first_done) \
|
||||
ret |= f->m_interface->write_map_next(local, f); \
|
||||
ret |= f->m_interface->write_map_next M_R(local, f); \
|
||||
ret |= M_CALL_OUT_SERIAL(key_oplist, f, *item->key_ptr); \
|
||||
ret |= f->m_interface->write_map_value(local, f); \
|
||||
ret |= f->m_interface->write_map_value M_R(local, f); \
|
||||
ret |= M_CALL_OUT_SERIAL(value_oplist, f, *item->value_ptr); \
|
||||
first_done = true; \
|
||||
} \
|
||||
ret |= f->m_interface->write_map_end(local, f); \
|
||||
ret |= f->m_interface->write_map_end M_R(local, f); \
|
||||
, \
|
||||
ret = f->m_interface->write_array_start(local, f, t1->size); \
|
||||
ret = f->m_interface->write_array_start M_R(local, f, t1->size); \
|
||||
for (M_F(name, _it)(it, t1) ; \
|
||||
!M_F(name, _end_p)(it); \
|
||||
M_F(name, _next)(it)){ \
|
||||
item = M_F(name, _cref)(it); \
|
||||
if (first_done) \
|
||||
ret |= f->m_interface->write_array_next(local, f); \
|
||||
ret |= f->m_interface->write_array_next M_R(local, f); \
|
||||
ret |= M_CALL_OUT_SERIAL(key_oplist, f, *item); \
|
||||
first_done = true; \
|
||||
} \
|
||||
ret |= f->m_interface->write_array_end(local, f); \
|
||||
ret |= f->m_interface->write_array_end M_R(local, f); \
|
||||
) \
|
||||
return ret & M_SERIAL_FAIL; \
|
||||
} \
|
||||
|
||||
+6
-7
@@ -480,8 +480,7 @@ M_P(bool, m_bstring, _fread, m_bstring_t v, FILE *f, size_t num)
|
||||
and output it in the given serializer
|
||||
See serialization for return code.
|
||||
*/
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_bstring_out_serial(m_serial_write_t serial, const m_bstring_t v)
|
||||
M_P(m_serial_return_code_t, m_bstring, _out_serial, m_serial_write_t serial, const m_bstring_t v)
|
||||
{
|
||||
M_ASSERT (serial != NULL && serial->m_interface != NULL);
|
||||
M_BSTRING_CONTRACT (v);
|
||||
@@ -489,15 +488,15 @@ m_bstring_out_serial(m_serial_write_t serial, const m_bstring_t v)
|
||||
m_serial_return_code_t ret;
|
||||
size_t size = m_bstring_size(v);
|
||||
uint8_t *ptr = m_bstr1ng_cstr(v);
|
||||
ret = serial->m_interface->write_array_start(local, serial, size);
|
||||
ret = serial->m_interface->write_array_start M_R(local, serial, size);
|
||||
if (size > 0) {
|
||||
ret |= serial->m_interface->write_integer(serial, ptr[0], 1);
|
||||
ret |= serial->m_interface->write_integer M_R(serial, ptr[0], 1);
|
||||
for(size_t i = 1; i < size; i++) {
|
||||
ret |= serial->m_interface->write_array_next(local, serial);
|
||||
ret |= serial->m_interface->write_integer(serial, ptr[i], 1);
|
||||
ret |= serial->m_interface->write_array_next M_R(local, serial);
|
||||
ret |= serial->m_interface->write_integer M_R(serial, ptr[i], 1);
|
||||
}
|
||||
}
|
||||
ret |= serial->m_interface->write_array_end(local, serial);
|
||||
ret |= serial->m_interface->write_array_end M_R(local, serial);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -412,17 +412,20 @@ M_BEGIN_PROTECTED_CODE
|
||||
#endif
|
||||
|
||||
|
||||
/* In order to support context for memory functions, the prototypes and usages of some functions are modified
|
||||
/* In order to support local context for memory functions, the prototypes and usages of some functions are modified
|
||||
* so that they can accept a first argument 'm_pool' which is the memory context parameter.
|
||||
* For some functions, there is no meaning of a local memory context parameter: for all data shared between threads,
|
||||
* only a global memory context has any meaning. For such cases, the memory context parameter is not requested to
|
||||
* the used but set to 0.
|
||||
* This is controlled through M_USE_POOL parameter that define the type of the memory context parameter.
|
||||
*
|
||||
* Several macros are defined **globally** to support such features.
|
||||
* They expand to nothing if the memory context parameter is not requested.
|
||||
* For some functions, there is no meaning of a local memory context parameter:
|
||||
* for all data shared between threads, only a global memory context has any meaning.
|
||||
* For such cases, the memory context parameter is globally requested to the user through M_USE_GLOBAL_POOL or set to 0.
|
||||
*
|
||||
* This is controlled through M_USE_POOL parameter that define the type of the memory context parameter
|
||||
* to be used globally for all M*LIB. There is no possibility to support only some containers and not others.
|
||||
*
|
||||
* Several macros are defined **globally** to support such features and being internally used by M*LIB containers.
|
||||
* They expand to nothing if the memory context parameter is not requested:
|
||||
* * M_P_EXPAND: expand to the first parameter 'm_pool' of type M_USE_POOL for a function that may use memory context.
|
||||
* * M_P_EXPAND_void: same but assume that there is no argument in the initial funciton.
|
||||
* * M_P_EXPAND_void: same but assume that there is no argument in the initial function.
|
||||
* * M_R_EXPAND: expand to the first parameter 'm_pool' (followed by a comma)
|
||||
* * M_R_EXPAND_void: same but assume that there is no argument
|
||||
* * M_R: add the parameter m_pool to the function call if needed,
|
||||
@@ -458,7 +461,8 @@ M_BEGIN_PROTECTED_CODE
|
||||
|
||||
// M_P: Expand to a prototype of a function that may trigger exception / accept memory context
|
||||
// M_N: Expand to a prototype of a function that may not trigger exception or accept memory context
|
||||
// If not M_F, no overloaded M_INLINE and no M_P_EXPAND, simplify M_P
|
||||
// If not user M_F, no overloaded M_INLINE and no M_P_EXPAND,
|
||||
// simplify definition of M_P/M_N to provide faster compile time.
|
||||
// (faster build: 0.54s instead of 0.80s in extreme expanding)
|
||||
#if !defined(M_USE_POOL) && !defined(M_F) && !defined(M_USE_FINE_GRAINED_LINKAGE) && !defined(M_USE_DEF) && !defined(M_USE_DECL)
|
||||
# define M_P(rettype, name, suffix, ...) static inline rettype name ## suffix(__VA_ARGS__)
|
||||
@@ -5201,6 +5205,7 @@ m_core_parse2_enum (const char str[], const char **endptr)
|
||||
* each time it is called with a pseudo random wait.
|
||||
* It is used to avoid too many threads trying to grab some atomic
|
||||
* variables at the same times (it makes the threads waits randomly).
|
||||
* Initialization is cheap.
|
||||
*/
|
||||
typedef struct m_core_backoff_s {
|
||||
unsigned int count; // Number of times it has been run
|
||||
@@ -5274,7 +5279,7 @@ struct m_string_s;
|
||||
* - OK & done (object is fully parsed),
|
||||
* - OK & continue parsing (object is partially parsed)
|
||||
* - Fail parsing
|
||||
* - Fail parsing with given arguments (give explicit size)
|
||||
* - Fail parsing with given arguments (give explicit size) but a retry will succeed.
|
||||
*/
|
||||
typedef enum m_serial_return_code_e {
|
||||
M_SERIAL_OK_DONE = 0, M_SERIAL_OK_CONTINUE = 1, M_SERIAL_FAIL = 2, M_SERIAL_FAIL_RETRY = 4
|
||||
@@ -5354,7 +5359,7 @@ typedef struct m_serial_read_interface_s {
|
||||
m_serial_return_code_t (*read_boolean)(m_serial_read_t,bool *);
|
||||
m_serial_return_code_t (*read_integer)(m_serial_read_t, long long *, const size_t size_of_type);
|
||||
m_serial_return_code_t (*read_float)(m_serial_read_t, long double *, const size_t size_of_type);
|
||||
m_serial_return_code_t (*read_string)(m_serial_read_t, struct m_string_s *);
|
||||
m_serial_return_code_t (*read_string)(M_P_EXPAND m_serial_read_t, struct m_string_s *);
|
||||
m_serial_return_code_t (*read_array_start)(m_serial_local_t, m_serial_read_t, size_t *);
|
||||
m_serial_return_code_t (*read_array_next)(m_serial_local_t, m_serial_read_t);
|
||||
m_serial_return_code_t (*read_map_start)(m_serial_local_t, m_serial_read_t, size_t *);
|
||||
@@ -5384,22 +5389,22 @@ typedef struct m_serial_write_s {
|
||||
* All function pointers shall be not null.
|
||||
*/
|
||||
typedef struct m_serial_write_interface_s {
|
||||
m_serial_return_code_t (*write_boolean)(m_serial_write_t,const bool data);
|
||||
m_serial_return_code_t (*write_integer)(m_serial_write_t,const long long data, const size_t size_of_type);
|
||||
m_serial_return_code_t (*write_float)(m_serial_write_t, const long double data, const size_t size_of_type);
|
||||
m_serial_return_code_t (*write_string)(m_serial_write_t,const char data[], size_t len);
|
||||
m_serial_return_code_t (*write_array_start)(m_serial_local_t, m_serial_write_t, const size_t number_of_elements);
|
||||
m_serial_return_code_t (*write_array_next)(m_serial_local_t, m_serial_write_t);
|
||||
m_serial_return_code_t (*write_array_end)(m_serial_local_t, m_serial_write_t);
|
||||
m_serial_return_code_t (*write_map_start)(m_serial_local_t, m_serial_write_t, const size_t number_of_elements);
|
||||
m_serial_return_code_t (*write_map_value)(m_serial_local_t, m_serial_write_t);
|
||||
m_serial_return_code_t (*write_map_next)(m_serial_local_t, m_serial_write_t);
|
||||
m_serial_return_code_t (*write_map_end)(m_serial_local_t, m_serial_write_t);
|
||||
m_serial_return_code_t (*write_tuple_start)(m_serial_local_t, m_serial_write_t);
|
||||
m_serial_return_code_t (*write_tuple_id)(m_serial_local_t, m_serial_write_t, const char * const field_name[], const int max, const int index);
|
||||
m_serial_return_code_t (*write_tuple_end)(m_serial_local_t, m_serial_write_t);
|
||||
m_serial_return_code_t (*write_variant_start)(m_serial_local_t, m_serial_write_t, const char * const field_name[], const int max, const int index);
|
||||
m_serial_return_code_t (*write_variant_end)(m_serial_local_t, m_serial_write_t);
|
||||
m_serial_return_code_t (*write_boolean)(M_P_EXPAND m_serial_write_t,const bool data);
|
||||
m_serial_return_code_t (*write_integer)(M_P_EXPAND m_serial_write_t,const long long data, const size_t size_of_type);
|
||||
m_serial_return_code_t (*write_float)(M_P_EXPAND m_serial_write_t, const long double data, const size_t size_of_type);
|
||||
m_serial_return_code_t (*write_string)(M_P_EXPAND m_serial_write_t,const char data[], size_t len);
|
||||
m_serial_return_code_t (*write_array_start)(M_P_EXPAND m_serial_local_t, m_serial_write_t, const size_t number_of_elements);
|
||||
m_serial_return_code_t (*write_array_next)(M_P_EXPAND m_serial_local_t, m_serial_write_t);
|
||||
m_serial_return_code_t (*write_array_end)(M_P_EXPAND m_serial_local_t, m_serial_write_t);
|
||||
m_serial_return_code_t (*write_map_start)(M_P_EXPAND m_serial_local_t, m_serial_write_t, const size_t number_of_elements);
|
||||
m_serial_return_code_t (*write_map_value)(M_P_EXPAND m_serial_local_t, m_serial_write_t);
|
||||
m_serial_return_code_t (*write_map_next)(M_P_EXPAND m_serial_local_t, m_serial_write_t);
|
||||
m_serial_return_code_t (*write_map_end)(M_P_EXPAND m_serial_local_t, m_serial_write_t);
|
||||
m_serial_return_code_t (*write_tuple_start)(M_P_EXPAND m_serial_local_t, m_serial_write_t);
|
||||
m_serial_return_code_t (*write_tuple_id)(M_P_EXPAND m_serial_local_t, m_serial_write_t, const char * const field_name[], const int max, const int index);
|
||||
m_serial_return_code_t (*write_tuple_end)(M_P_EXPAND m_serial_local_t, m_serial_write_t);
|
||||
m_serial_return_code_t (*write_variant_start)(M_P_EXPAND m_serial_local_t, m_serial_write_t, const char * const field_name[], const int max, const int index);
|
||||
m_serial_return_code_t (*write_variant_end)(M_P_EXPAND m_serial_local_t, m_serial_write_t);
|
||||
} m_serial_write_interface_t;
|
||||
|
||||
|
||||
@@ -5409,23 +5414,23 @@ typedef struct m_serial_write_interface_s {
|
||||
*/
|
||||
#define M_OUT_SERIAL_DEFAULT_ARG(serial, x) \
|
||||
_Generic(((void)0,(x)), \
|
||||
bool: (serial)->m_interface->write_boolean(serial, M_AS_TYPE(bool, (x))), \
|
||||
char: (serial)->m_interface->write_integer(serial, M_AS_TYPE(char,(x)), sizeof (x)), \
|
||||
signed char: (serial)->m_interface->write_integer(serial, M_AS_TYPE(signed char,(x)), sizeof (x)), \
|
||||
unsigned char: (serial)->m_interface->write_integer(serial, (long long) M_AS_TYPE(unsigned char,(x)), sizeof (x)), \
|
||||
signed short: (serial)->m_interface->write_integer(serial, M_AS_TYPE(signed short,(x)), sizeof (x)), \
|
||||
unsigned short: (serial)->m_interface->write_integer(serial, (long long) M_AS_TYPE(unsigned short,(x)), sizeof (x)), \
|
||||
signed int: (serial)->m_interface->write_integer(serial, M_AS_TYPE(signed int,(x)), sizeof (x)), \
|
||||
unsigned int: (serial)->m_interface->write_integer(serial, (long long) M_AS_TYPE(unsigned int,(x)), sizeof (x)), \
|
||||
long int: (serial)->m_interface->write_integer(serial, M_AS_TYPE(long,(x)), sizeof (x)), \
|
||||
unsigned long int: (serial)->m_interface->write_integer(serial, (long long) M_AS_TYPE(unsigned long,(x)), sizeof (x)), \
|
||||
long long int: (serial)->m_interface->write_integer(serial, M_AS_TYPE(long long,(x)), sizeof (x)), \
|
||||
unsigned long long int: (serial)->m_interface->write_integer(serial, (long long) M_AS_TYPE(unsigned long long,(x)), sizeof (x)), \
|
||||
float: (serial)->m_interface->write_float(serial, M_AS_TYPE(float,(x)), sizeof (x)), \
|
||||
double: (serial)->m_interface->write_float(serial, M_AS_TYPE(double,(x)), sizeof (x)), \
|
||||
long double: (serial)->m_interface->write_float(serial, M_AS_TYPE(long double,(x)), sizeof (x)), \
|
||||
const char *: (serial)->m_interface->write_string(serial, M_AS_TYPE(const char *,(x)), m_core_out_serial_strlen(M_AS_TYPE(const char *,(x))) ), \
|
||||
char *: (serial)->m_interface->write_string(serial, M_AS_TYPE(char *,(x)), m_core_out_serial_strlen(M_AS_TYPE(const char *,(x))) ), \
|
||||
bool: (serial)->m_interface->write_boolean M_R(serial, M_AS_TYPE(bool, (x))), \
|
||||
char: (serial)->m_interface->write_integer M_R(serial, M_AS_TYPE(char,(x)), sizeof (x)), \
|
||||
signed char: (serial)->m_interface->write_integer M_R(serial, M_AS_TYPE(signed char,(x)), sizeof (x)), \
|
||||
unsigned char: (serial)->m_interface->write_integer M_R(serial, (long long) M_AS_TYPE(unsigned char,(x)), sizeof (x)), \
|
||||
signed short: (serial)->m_interface->write_integer M_R(serial, M_AS_TYPE(signed short,(x)), sizeof (x)), \
|
||||
unsigned short: (serial)->m_interface->write_integer M_R(serial, (long long) M_AS_TYPE(unsigned short,(x)), sizeof (x)), \
|
||||
signed int: (serial)->m_interface->write_integer M_R(serial, M_AS_TYPE(signed int,(x)), sizeof (x)), \
|
||||
unsigned int: (serial)->m_interface->write_integer M_R(serial, (long long) M_AS_TYPE(unsigned int,(x)), sizeof (x)), \
|
||||
long int: (serial)->m_interface->write_integer M_R(serial, M_AS_TYPE(long,(x)), sizeof (x)), \
|
||||
unsigned long int: (serial)->m_interface->write_integer M_R(serial, (long long) M_AS_TYPE(unsigned long,(x)), sizeof (x)), \
|
||||
long long int: (serial)->m_interface->write_integer M_R(serial, M_AS_TYPE(long long,(x)), sizeof (x)), \
|
||||
unsigned long long int: (serial)->m_interface->write_integer M_R(serial, (long long) M_AS_TYPE(unsigned long long,(x)), sizeof (x)), \
|
||||
float: (serial)->m_interface->write_float M_R(serial, M_AS_TYPE(float,(x)), sizeof (x)), \
|
||||
double: (serial)->m_interface->write_float M_R(serial, M_AS_TYPE(double,(x)), sizeof (x)), \
|
||||
long double: (serial)->m_interface->write_float M_R(serial, M_AS_TYPE(long double,(x)), sizeof (x)), \
|
||||
const char *: (serial)->m_interface->write_string M_R(serial, M_AS_TYPE(const char *,(x)), m_core_out_serial_strlen(M_AS_TYPE(const char *,(x))) ), \
|
||||
char *: (serial)->m_interface->write_string M_R(serial, M_AS_TYPE(char *,(x)), m_core_out_serial_strlen(M_AS_TYPE(const char *,(x))) ), \
|
||||
const void *: M_SERIAL_FAIL /* unsupported */, \
|
||||
void *: M_SERIAL_FAIL /* unsupported */)
|
||||
|
||||
|
||||
@@ -974,26 +974,25 @@
|
||||
, /* no IN_STR */ ) \
|
||||
\
|
||||
M_IF_METHOD(OUT_SERIAL, oplist)( \
|
||||
M_INLINE m_serial_return_code_t \
|
||||
M_F(name, _out_serial)(m_serial_write_t f, const deque_t deque) \
|
||||
M_P(m_serial_return_code_t, name, _out_serial, m_serial_write_t f, const deque_t deque) \
|
||||
{ \
|
||||
M_D3QU3_CONTRACT(deque); \
|
||||
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||
m_serial_local_t local; \
|
||||
m_serial_return_code_t ret; \
|
||||
bool first_done = false; \
|
||||
ret = f->m_interface->write_array_start(local, f, deque->count); \
|
||||
ret = f->m_interface->write_array_start M_R(local, f, deque->count); \
|
||||
M_F(name, _it_ct) it; \
|
||||
for (M_F(name, _it)(it, deque) ; \
|
||||
!M_F(name, _end_p)(it); \
|
||||
M_F(name, _next)(it)){ \
|
||||
type const *item = M_F(name, _cref)(it); \
|
||||
if (first_done) \
|
||||
ret |= f->m_interface->write_array_next(local, f); \
|
||||
ret |= f->m_interface->write_array_next M_R(local, f); \
|
||||
ret |= M_CALL_OUT_SERIAL(oplist, f, *item); \
|
||||
first_done = true; \
|
||||
} \
|
||||
ret |= f->m_interface->write_array_end(local, f); \
|
||||
ret |= f->m_interface->write_array_end M_R(local, f); \
|
||||
return ret & M_SERIAL_FAIL; \
|
||||
} \
|
||||
, /* no OUT_SERIAL */ ) \
|
||||
|
||||
@@ -1119,8 +1119,7 @@ M_ARRAY_DEF(m_array_index, m_indexhash_t, M_POD_OPLIST)
|
||||
, /* no IN_STR */ ) \
|
||||
\
|
||||
M_IF_METHOD_BOTH(OUT_SERIAL, key_oplist, value_oplist)( \
|
||||
M_INLINE m_serial_return_code_t \
|
||||
M_F(name, _out_serial)(m_serial_write_t f, dict_t const t1) \
|
||||
M_P(m_serial_return_code_t, name, _out_serial, m_serial_write_t f, dict_t const t1) \
|
||||
{ \
|
||||
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||
m_serial_local_t local; \
|
||||
@@ -1131,31 +1130,31 @@ M_ARRAY_DEF(m_array_index, m_indexhash_t, M_POD_OPLIST)
|
||||
/* Format is different between associative container \
|
||||
& set container */ \
|
||||
M_IF(isSet)( \
|
||||
ret = f->m_interface->write_array_start(local, f, M_F(name, _size)(t1)); \
|
||||
ret = f->m_interface->write_array_start M_R(local, f, M_F(name, _size)(t1)); \
|
||||
for (M_F(name, _it)(it, t1) ; \
|
||||
!M_F(name, _end_p)(it); \
|
||||
M_F(name, _next)(it)){ \
|
||||
item = M_F(name, _cref)(it); \
|
||||
if (first_done) \
|
||||
ret |= f->m_interface->write_array_next(local, f); \
|
||||
ret |= f->m_interface->write_array_next M_R(local, f); \
|
||||
ret |= M_CALL_OUT_SERIAL(key_oplist, f, *item); \
|
||||
first_done = true; \
|
||||
} \
|
||||
ret |= f->m_interface->write_array_end(local, f); \
|
||||
ret |= f->m_interface->write_array_end M_R(local, f); \
|
||||
, \
|
||||
ret = f->m_interface->write_map_start(local, f, M_F(name, _size)(t1)); \
|
||||
ret = f->m_interface->write_map_start M_R(local, f, M_F(name, _size)(t1)); \
|
||||
for (M_F(name, _it)(it, t1) ; \
|
||||
!M_F(name, _end_p)(it); \
|
||||
M_F(name, _next)(it)){ \
|
||||
item = M_F(name, _cref)(it); \
|
||||
if (first_done) \
|
||||
ret |= f->m_interface->write_map_next(local, f); \
|
||||
ret |= f->m_interface->write_map_next M_R(local, f); \
|
||||
ret |= M_CALL_OUT_SERIAL(key_oplist, f, item->key); \
|
||||
ret |= f->m_interface->write_map_value(local, f); \
|
||||
ret |= f->m_interface->write_map_value M_R(local, f); \
|
||||
ret |= M_CALL_OUT_SERIAL(value_oplist, f, item->value); \
|
||||
first_done = true; \
|
||||
} \
|
||||
ret |= f->m_interface->write_map_end(local, f); \
|
||||
ret |= f->m_interface->write_map_end M_R(local, f); \
|
||||
) \
|
||||
return ret & M_SERIAL_FAIL; \
|
||||
} \
|
||||
|
||||
@@ -748,18 +748,17 @@
|
||||
, /* no IN_STR & INIT */ ) \
|
||||
\
|
||||
M_IF_METHOD(OUT_SERIAL, oplist)( \
|
||||
M_INLINE m_serial_return_code_t \
|
||||
M_F(name, _out_serial)(m_serial_write_t f, const list_t list) \
|
||||
M_P(m_serial_return_code_t, name, _out_serial, m_serial_write_t f, const list_t list) \
|
||||
{ \
|
||||
M_ASSERT (list != NULL); \
|
||||
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||
m_serial_return_code_t ret; \
|
||||
m_serial_local_t local; \
|
||||
bool first_done = false; \
|
||||
ret = f->m_interface->write_array_start(local, f, (size_t)-1); \
|
||||
ret = f->m_interface->write_array_start M_R(local, f, (size_t)-1); \
|
||||
if (ret == M_SERIAL_FAIL_RETRY) { \
|
||||
size_t n = M_F(name, _size)(list); \
|
||||
ret = f->m_interface->write_array_start(local, f, n); \
|
||||
ret = f->m_interface->write_array_start M_R(local, f, n); \
|
||||
} \
|
||||
it_t it; \
|
||||
for (M_F(name, _it)(it, list) ; \
|
||||
@@ -767,11 +766,11 @@
|
||||
M_F(name, _next)(it)){ \
|
||||
type const *item = M_F(name, _cref)(it); \
|
||||
if (first_done) \
|
||||
ret |= f->m_interface->write_array_next(local, f); \
|
||||
ret |= f->m_interface->write_array_next M_R(local, f); \
|
||||
ret |= M_CALL_OUT_SERIAL(oplist, f, *item); \
|
||||
first_done = true; \
|
||||
} \
|
||||
ret |= f->m_interface->write_array_end(local, f); \
|
||||
ret |= f->m_interface->write_array_end M_R(local, f); \
|
||||
return ret & M_SERIAL_FAIL; \
|
||||
} \
|
||||
, /* no OUT_SERIAL */ ) \
|
||||
|
||||
+2
-3
@@ -478,10 +478,9 @@
|
||||
,/* No PARSE_STR */) \
|
||||
\
|
||||
M_IF_METHOD(OUT_SERIAL, oplist)( \
|
||||
M_INLINE m_serial_return_code_t \
|
||||
M_F(name, _out_serial)(m_serial_write_t f, const prioqueue_t p) \
|
||||
M_P(m_serial_return_code_t, name, _out_serial, m_serial_write_t f, const prioqueue_t p) \
|
||||
{ \
|
||||
return M_F(name, _array_out_serial)(f, p->array); \
|
||||
return M_F(name, _array_out_serial) M_R(f, p->array); \
|
||||
} \
|
||||
,/* No OUT_SERIAL */) \
|
||||
\
|
||||
|
||||
+4
-5
@@ -1075,8 +1075,7 @@ typedef enum {
|
||||
, /* no in_str */ ) \
|
||||
\
|
||||
M_IF_METHOD(OUT_SERIAL, oplist)( \
|
||||
M_INLINE m_serial_return_code_t \
|
||||
M_F(name, _out_serial)(m_serial_write_t f, tree_t const t1) \
|
||||
M_P(m_serial_return_code_t, name, _out_serial, m_serial_write_t f, tree_t const t1) \
|
||||
{ \
|
||||
M_RBTR33_CONTRACT(t1); \
|
||||
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||
@@ -1085,17 +1084,17 @@ typedef enum {
|
||||
M_F(name, _subtype_ct) const *item; \
|
||||
bool first_done = false; \
|
||||
it_t it; \
|
||||
ret = f->m_interface->write_array_start(local, f, t1->size); \
|
||||
ret = f->m_interface->write_array_start M_R(local, f, t1->size); \
|
||||
for (M_F(name, _it)(it, t1) ; \
|
||||
!M_F(name, _end_p)(it); \
|
||||
M_F(name, _next)(it)){ \
|
||||
item = M_F(name, _cref)(it); \
|
||||
if (first_done) \
|
||||
ret |= f->m_interface->write_array_next(local, f); \
|
||||
ret |= f->m_interface->write_array_next M_R(local, f); \
|
||||
ret |= M_CALL_OUT_SERIAL(oplist, f, *item); \
|
||||
first_done = true; \
|
||||
} \
|
||||
ret |= f->m_interface->write_array_end(local, f); \
|
||||
ret |= f->m_interface->write_array_end M_R(local, f); \
|
||||
return ret & M_SERIAL_FAIL; \
|
||||
} \
|
||||
, /* no OUT_SERIAL */ ) \
|
||||
|
||||
+29
-29
@@ -111,9 +111,9 @@ m_ser1al_bin_read_size(FILE *f, size_t *size)
|
||||
|
||||
/* Write the boolean 'data' into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_bin_write_boolean(m_serial_write_t serial, const bool data)
|
||||
M_P(m_serial_return_code_t, m_ser1al_bin, _write_boolean, m_serial_write_t serial, const bool data)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
size_t n = fwrite (M_ASSIGN_CAST(const void*, &data), sizeof (bool), 1, f);
|
||||
return n == 1 ? M_SERIAL_OK_DONE : m_core_serial_fail();
|
||||
@@ -121,9 +121,9 @@ m_ser1al_bin_write_boolean(m_serial_write_t serial, const bool data)
|
||||
|
||||
/* Write the integer 'data' of 'size_of_type' bytes into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_bin_write_integer(m_serial_write_t serial,const long long data, const size_t size_of_type)
|
||||
M_P(m_serial_return_code_t, m_ser1al_bin, _write_integer, m_serial_write_t serial,const long long data, const size_t size_of_type)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
size_t n;
|
||||
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
@@ -146,9 +146,9 @@ m_ser1al_bin_write_integer(m_serial_write_t serial,const long long data, const s
|
||||
|
||||
/* Write the float 'data' of 'size_of_type' bytes into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_bin_write_float(m_serial_write_t serial, const long double data, const size_t size_of_type)
|
||||
M_P(m_serial_return_code_t, m_ser1al_bin, _write_float, m_serial_write_t serial, const long double data, const size_t size_of_type)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
size_t n;
|
||||
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
@@ -168,9 +168,9 @@ m_ser1al_bin_write_float(m_serial_write_t serial, const long double data, const
|
||||
|
||||
/* Write the null-terminated string 'data'into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_bin_write_string(m_serial_write_t serial, const char data[], size_t length)
|
||||
M_P(m_serial_return_code_t, m_ser1al_bin, _write_string, m_serial_write_t serial, const char data[], size_t length)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
M_ASSERT_SLOW(length == strlen(data) );
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
M_ASSERT(f != NULL && data != NULL);
|
||||
@@ -188,9 +188,9 @@ m_ser1al_bin_write_string(m_serial_write_t serial, const char data[], size_t len
|
||||
Initialize 'local' so that it can be used to serialize the array
|
||||
(local is an unique serialization object of the array).
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_bin_write_array_start(m_serial_local_t local, m_serial_write_t serial, const size_t number_of_elements)
|
||||
M_P(m_serial_return_code_t, m_ser1al_bin, _write_array_start, m_serial_local_t local, m_serial_write_t serial, const size_t number_of_elements)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; //Unused
|
||||
if (number_of_elements == (size_t)-1) return M_SERIAL_FAIL_RETRY;
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
@@ -200,9 +200,9 @@ m_ser1al_bin_write_array_start(m_serial_local_t local, m_serial_write_t serial,
|
||||
|
||||
/* Write an array separator between elements of an array into the serial stream 'serial' if needed.
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_bin_write_array_next(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_bin, _write_array_next, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // Unused
|
||||
(void) serial; // Unused
|
||||
return M_SERIAL_OK_CONTINUE;
|
||||
@@ -210,9 +210,9 @@ m_ser1al_bin_write_array_next(m_serial_local_t local, m_serial_write_t serial)
|
||||
|
||||
/* End the writing of an array into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_bin_write_array_end(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_bin, _write_array_end, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // Unused
|
||||
(void) serial; // Unused
|
||||
return M_SERIAL_OK_CONTINUE;
|
||||
@@ -220,9 +220,9 @@ m_ser1al_bin_write_array_end(m_serial_local_t local, m_serial_write_t serial)
|
||||
|
||||
/* Write a value separator between element of the same pair of a map into the serial stream 'serial' if needed.
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_bin_write_map_value(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_bin, _write_map_value, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // argument not used
|
||||
(void) serial;
|
||||
return M_SERIAL_OK_CONTINUE;
|
||||
@@ -232,9 +232,9 @@ m_ser1al_bin_write_map_value(m_serial_local_t local, m_serial_write_t serial)
|
||||
Initialize 'local' so that it can serial the tuple
|
||||
(local is an unique serialization object of the tuple).
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_bin_write_tuple_start(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_bin, _write_tuple_start, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // argument not used
|
||||
(void) serial;
|
||||
return M_SERIAL_OK_CONTINUE;
|
||||
@@ -242,9 +242,9 @@ m_ser1al_bin_write_tuple_start(m_serial_local_t local, m_serial_write_t serial)
|
||||
|
||||
/* Start writing the field named field_name[index] of a tuple into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_bin_write_tuple_id(m_serial_local_t local, m_serial_write_t serial, const char *const field_name[], const int max, const int index)
|
||||
M_P(m_serial_return_code_t, m_ser1al_bin, _write_tuple_id, m_serial_local_t local, m_serial_write_t serial, const char *const field_name[], const int max, const int index)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // argument not used
|
||||
(void) serial;
|
||||
(void) field_name;
|
||||
@@ -255,9 +255,9 @@ m_ser1al_bin_write_tuple_id(m_serial_local_t local, m_serial_write_t serial, con
|
||||
|
||||
/* End the write of a tuple into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_bin_write_tuple_end(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_bin, _write_tuple_end, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // argument not used
|
||||
(void) serial;
|
||||
return M_SERIAL_OK_DONE;
|
||||
@@ -268,9 +268,9 @@ m_ser1al_bin_write_tuple_end(m_serial_local_t local, m_serial_write_t serial)
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise
|
||||
Otherwise, the field 'field_name[index]' will be filled.
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_bin_write_variant_start(m_serial_local_t local, m_serial_write_t serial, const char *const field_name[], const int max, const int index)
|
||||
M_P(m_serial_return_code_t, m_ser1al_bin, _write_variant_start, m_serial_local_t local, m_serial_write_t serial, const char *const field_name[], const int max, const int index)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) field_name;
|
||||
(void) max;
|
||||
(void) local;
|
||||
@@ -281,9 +281,9 @@ m_ser1al_bin_write_variant_start(m_serial_local_t local, m_serial_write_t serial
|
||||
|
||||
/* End Writing a variant into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_bin_write_variant_end(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_bin, _write_variant_end, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // argument not used
|
||||
(void) serial;
|
||||
return M_SERIAL_OK_DONE;
|
||||
@@ -399,15 +399,15 @@ m_ser1al_bin_read_float(m_serial_read_t serial, long double *r, const size_t siz
|
||||
/* Read from the stream 'serial' a string.
|
||||
Set 's' with the string if succeeds
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_bin_read_string(m_serial_read_t serial, struct m_string_s *s){
|
||||
M_P(m_serial_return_code_t, m_ser1al_bin, _read_string, m_serial_read_t serial, struct m_string_s *s)
|
||||
{
|
||||
FILE *f = (FILE*) serial->data[0].p;
|
||||
M_ASSERT(f != NULL && s != NULL);
|
||||
// First read the number of non null characters
|
||||
size_t length;
|
||||
if (m_ser1al_bin_read_size(f, &length) != true) return m_core_serial_fail();
|
||||
// Use of internal string interface to dimension the string
|
||||
char *p = m_str1ng_fit2size(s, length + 1);
|
||||
char *p = m_str1ng_fit2size M_R(s, length + 1);
|
||||
m_str1ng_set_size(s, length);
|
||||
// Read the characters excluding the final null one.
|
||||
// NOTE: fread supports length == 0.
|
||||
|
||||
+72
-87
@@ -36,9 +36,9 @@ M_BEGIN_PROTECTED_CODE
|
||||
|
||||
/* Write the boolean 'data' into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_write_boolean(m_serial_write_t serial, const bool data)
|
||||
M_P(m_serial_return_code_t, m_ser1al_json, _write_boolean, m_serial_write_t serial, const bool data)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
int n = fprintf(f, "%s", data ? "true" : "false");
|
||||
return n > 0 ? M_SERIAL_OK_DONE : m_core_serial_fail();
|
||||
@@ -46,9 +46,9 @@ m_ser1al_json_write_boolean(m_serial_write_t serial, const bool data)
|
||||
|
||||
/* Write the integer 'data' of 'size_of_type' bytes into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_write_integer(m_serial_write_t serial,const long long data, const size_t size_of_type)
|
||||
M_P(m_serial_return_code_t, m_ser1al_json, _write_integer, m_serial_write_t serial,const long long data, const size_t size_of_type)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) size_of_type; // Ignored
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
int n = fprintf(f, "%lld", data);
|
||||
@@ -57,9 +57,9 @@ m_ser1al_json_write_integer(m_serial_write_t serial,const long long data, const
|
||||
|
||||
/* Write the float 'data' of 'size_of_type' bytes into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_write_float(m_serial_write_t serial, const long double data, const size_t size_of_type)
|
||||
M_P(m_serial_return_code_t, m_ser1al_json, _write_float, m_serial_write_t serial, const long double data, const size_t size_of_type)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) size_of_type; // Ignored
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
int n = fprintf(f, "%Lf", data);
|
||||
@@ -68,9 +68,9 @@ m_ser1al_json_write_float(m_serial_write_t serial, const long double data, const
|
||||
|
||||
/* Write the null-terminated string 'data'into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_write_string(m_serial_write_t serial, const char data[], size_t length)
|
||||
M_P(m_serial_return_code_t, m_ser1al_json, _write_string, m_serial_write_t serial, const char data[], size_t length)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
M_ASSERT(length == (m_str1ng_size_t) length);
|
||||
M_ASSERT_SLOW(length == strlen(data) );
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
@@ -92,9 +92,9 @@ m_ser1al_json_write_string(m_serial_write_t serial, const char data[], size_t le
|
||||
Initialize 'local' so that it can be used to serialize the array
|
||||
(local is an unique serialization object of the array).
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_write_array_start(m_serial_local_t local, m_serial_write_t serial, const size_t number_of_elements)
|
||||
M_P(m_serial_return_code_t, m_ser1al_json, _write_array_start, m_serial_local_t local, m_serial_write_t serial, const size_t number_of_elements)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // argument not used
|
||||
(void) number_of_elements; // Ignored
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
@@ -104,9 +104,9 @@ m_ser1al_json_write_array_start(m_serial_local_t local, m_serial_write_t serial,
|
||||
|
||||
/* Write an array separator between elements of an array into the serial stream 'serial' if needed.
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_write_array_next(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_json, _write_array_next, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // argument not used
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
int n = fprintf(f, ",");
|
||||
@@ -115,9 +115,9 @@ m_ser1al_json_write_array_next(m_serial_local_t local, m_serial_write_t serial)
|
||||
|
||||
/* End the writing of an array into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_write_array_end(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_json, _write_array_end, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // argument not used
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
int n = fprintf(f, "]");
|
||||
@@ -130,9 +130,9 @@ m_ser1al_json_write_array_end(m_serial_local_t local, m_serial_write_t serial)
|
||||
Initialize 'local' so that it can be used to serialize the map
|
||||
(local is an unique serialization object of the map).
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_write_map_start(m_serial_local_t local, m_serial_write_t serial, const size_t number_of_elements)
|
||||
M_P(m_serial_return_code_t, m_ser1al_json, _write_map_start, m_serial_local_t local, m_serial_write_t serial, const size_t number_of_elements)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // argument not used
|
||||
(void) number_of_elements; // Ignored
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
@@ -142,9 +142,9 @@ m_ser1al_json_write_map_start(m_serial_local_t local, m_serial_write_t serial, c
|
||||
|
||||
/* Write a value separator between element of the same pair of a map into the serial stream 'serial' if needed.
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_write_map_value(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_json, _write_map_value, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // argument not used
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
int n = fprintf(f, ":");
|
||||
@@ -153,9 +153,9 @@ m_ser1al_json_write_map_value(m_serial_local_t local, m_serial_write_t serial)
|
||||
|
||||
/* Write a map separator between elements of a map into the serial stream 'serial' if needed.
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_write_map_next(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_json, _write_map_next, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // argument not used
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
int n = fprintf(f, ",");
|
||||
@@ -164,9 +164,9 @@ m_ser1al_json_write_map_next(m_serial_local_t local, m_serial_write_t serial)
|
||||
|
||||
/* End the writing of a map into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_write_map_end(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_json, _write_map_end, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // argument not used
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
int n = fprintf(f, "}");
|
||||
@@ -177,9 +177,9 @@ m_ser1al_json_write_map_end(m_serial_local_t local, m_serial_write_t serial)
|
||||
Initialize 'local' so that it can serial the tuple
|
||||
(local is an unique serialization object of the tuple).
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_write_tuple_start(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_json, _write_tuple_start, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // argument not used
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
int n = fprintf(f, "{");
|
||||
@@ -188,9 +188,9 @@ m_ser1al_json_write_tuple_start(m_serial_local_t local, m_serial_write_t serial)
|
||||
|
||||
/* Start writing the field named field_name[index] of a tuple into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_write_tuple_id(m_serial_local_t local, m_serial_write_t serial, const char *const field_name[], const int max, const int index)
|
||||
M_P(m_serial_return_code_t, m_ser1al_json, _write_tuple_id, m_serial_local_t local, m_serial_write_t serial, const char *const field_name[], const int max, const int index)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // argument not used
|
||||
(void) max; // Ignored
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
@@ -200,9 +200,9 @@ m_ser1al_json_write_tuple_id(m_serial_local_t local, m_serial_write_t serial, co
|
||||
|
||||
/* End the write of a tuple into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_write_tuple_end(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_json, _write_tuple_end, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // argument not used
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
int n = fprintf(f, "}");
|
||||
@@ -214,9 +214,9 @@ m_ser1al_json_write_tuple_end(m_serial_local_t local, m_serial_write_t serial)
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise
|
||||
Otherwise, the field 'field_name[index]' will be filled.
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_write_variant_start(m_serial_local_t local, m_serial_write_t serial, const char *const field_name[], const int max, const int index)
|
||||
M_P(m_serial_return_code_t, m_ser1al_json, _write_variant_start, m_serial_local_t local, m_serial_write_t serial, const char *const field_name[], const int max, const int index)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // argument not used
|
||||
(void) max; // argument not used
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
@@ -233,9 +233,9 @@ m_ser1al_json_write_variant_start(m_serial_local_t local, m_serial_write_t seria
|
||||
|
||||
/* End Writing a variant into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_write_variant_end(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_json, _write_variant_end, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
M_ASSERT_POOL();
|
||||
(void) local; // argument not used
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
int n = fprintf(f, "}");
|
||||
@@ -344,12 +344,12 @@ m_ser1al_json_read_float(m_serial_read_t serial, long double *r, const size_t si
|
||||
/* Read from the stream 'serial' a string.
|
||||
Set 's' with the string if succeeds
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_read_string(m_serial_read_t serial, struct m_string_s *s){
|
||||
M_P(m_serial_return_code_t, m_ser1al_json, _read_string, m_serial_read_t serial, struct m_string_s *s)
|
||||
{
|
||||
FILE *f = (FILE*) serial->data[0].p;
|
||||
int n = m_core_fscanf(f, " "); // Skip any leading spaces.
|
||||
(void) n; // Unused return value.
|
||||
return m_string_in_str(s, f) ? M_SERIAL_OK_DONE : m_core_serial_fail();
|
||||
return m_string_in_str M_R(s, f) ? M_SERIAL_OK_DONE : m_core_serial_fail();
|
||||
}
|
||||
|
||||
/* Start reading from the stream 'serial' an array.
|
||||
@@ -587,40 +587,37 @@ typedef m_serial_read_t m_serial_json_read_t;
|
||||
|
||||
/* Write the boolean 'data' into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_write_boolean(m_serial_write_t serial, const bool data)
|
||||
M_P(m_serial_return_code_t, m_ser1al_str_json, _write_boolean, m_serial_write_t serial, const bool data)
|
||||
{
|
||||
struct m_string_s *f = (struct m_string_s *)serial->data[0].p;
|
||||
int n = m_string_cat_printf(f, "%s", data ? "true" : "false");
|
||||
//TODO: Simplify code.
|
||||
int n = m_string_cat_printf M_R(f, "%s", data ? "true" : "false");
|
||||
return n > 0 ? M_SERIAL_OK_DONE : m_core_serial_fail();
|
||||
}
|
||||
|
||||
/* Write the integer 'data' of 'size_of_type' bytes into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_write_integer(m_serial_write_t serial,const long long data, const size_t size_of_type)
|
||||
M_P(m_serial_return_code_t, m_ser1al_str_json, _write_integer, m_serial_write_t serial, const long long data, const size_t size_of_type)
|
||||
{
|
||||
(void) size_of_type; // Ignored
|
||||
struct m_string_s *f = (struct m_string_s *)serial->data[0].p;
|
||||
int n = m_string_cat_printf(f, "%lld", data);
|
||||
int n = m_string_cat_printf M_R(f, "%lld", data);
|
||||
return n > 0 ? M_SERIAL_OK_DONE : m_core_serial_fail();
|
||||
}
|
||||
|
||||
/* Write the float 'data' of 'size_of_type' bytes into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_write_float(m_serial_write_t serial, const long double data, const size_t size_of_type)
|
||||
M_P(m_serial_return_code_t, m_ser1al_str_json, _write_float, m_serial_write_t serial, const long double data, const size_t size_of_type)
|
||||
{
|
||||
(void) size_of_type; // Ignored
|
||||
struct m_string_s *f = (struct m_string_s *)serial->data[0].p;
|
||||
int n = m_string_cat_printf(f, "%Lf", data);
|
||||
int n = m_string_cat_printf M_R(f, "%Lf", data);
|
||||
return n > 0 ? M_SERIAL_OK_DONE : m_core_serial_fail();
|
||||
}
|
||||
|
||||
/* Write the null-terminated string 'data'into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_write_string(m_serial_write_t serial, const char data[], size_t length)
|
||||
M_P(m_serial_return_code_t, m_ser1al_str_json, _write_string, m_serial_write_t serial, const char data[], size_t length)
|
||||
{
|
||||
M_ASSERT(length == (m_str1ng_size_t) length);
|
||||
M_ASSERT_SLOW(length == strlen(data) );
|
||||
@@ -633,7 +630,7 @@ m_ser1al_str_json_write_string(m_serial_write_t serial, const char data[], size_
|
||||
v2->u.heap.alloc[sizeof(m_str1ng_size_t)-2] = 1;
|
||||
v2->u.heap.alloc[sizeof(m_str1ng_size_t)-1] = 31;
|
||||
v2->u.heap.ptr = (char*)ptr;
|
||||
m_string_get_str(f, v2, true);
|
||||
m_string_get_str M_R(f, v2, true);
|
||||
return M_SERIAL_OK_DONE;
|
||||
}
|
||||
|
||||
@@ -643,35 +640,32 @@ m_ser1al_str_json_write_string(m_serial_write_t serial, const char data[], size_
|
||||
Initialize 'local' so that it can be used to serialize the array
|
||||
(local is an unique serialization object of the array).
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_write_array_start(m_serial_local_t local, m_serial_write_t serial, const size_t number_of_elements)
|
||||
M_P(m_serial_return_code_t, m_ser1al_str_json, _write_array_start, m_serial_local_t local, m_serial_write_t serial, const size_t number_of_elements)
|
||||
{
|
||||
(void) local; // argument not used
|
||||
(void) number_of_elements; // Ignored
|
||||
struct m_string_s *f = (struct m_string_s *)serial->data[0].p;
|
||||
m_string_push_back(f, '[');
|
||||
m_string_push_back M_R(f, '[');
|
||||
return M_SERIAL_OK_CONTINUE;
|
||||
}
|
||||
|
||||
/* Write an array separator between elements of an array into the serial stream 'serial' if needed.
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_write_array_next(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_str_json, _write_array_next, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
(void) local; // argument not used
|
||||
struct m_string_s *f = (struct m_string_s *)serial->data[0].p;
|
||||
m_string_push_back(f, ',');
|
||||
m_string_push_back M_R(f, ',');
|
||||
return M_SERIAL_OK_CONTINUE;
|
||||
}
|
||||
|
||||
/* End the writing of an array into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_write_array_end(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_str_json, _write_array_end, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
(void) local; // argument not used
|
||||
struct m_string_s *f = (struct m_string_s *)serial->data[0].p;
|
||||
m_string_push_back(f, ']');
|
||||
m_string_push_back M_R(f, ']');
|
||||
return M_SERIAL_OK_CONTINUE;
|
||||
}
|
||||
|
||||
@@ -681,46 +675,42 @@ m_ser1al_str_json_write_array_end(m_serial_local_t local, m_serial_write_t seria
|
||||
Initialize 'local' so that it can be used to serialize the map
|
||||
(local is an unique serialization object of the map).
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_write_map_start(m_serial_local_t local, m_serial_write_t serial, const size_t number_of_elements)
|
||||
M_P(m_serial_return_code_t, m_ser1al_str_json, _write_map_start, m_serial_local_t local, m_serial_write_t serial, const size_t number_of_elements)
|
||||
{
|
||||
(void) local; // argument not used
|
||||
(void) number_of_elements; // Ignored
|
||||
struct m_string_s *f = (struct m_string_s *)serial->data[0].p;
|
||||
m_string_push_back(f, '{');
|
||||
m_string_push_back M_R(f, '{');
|
||||
return M_SERIAL_OK_CONTINUE;
|
||||
}
|
||||
|
||||
/* Write a value separator between element of the same pair of a map into the serial stream 'serial' if needed.
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_write_map_value(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_str_json, _write_map_value, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
(void) local; // argument not used
|
||||
struct m_string_s *f = (struct m_string_s *)serial->data[0].p;
|
||||
m_string_push_back(f, ':');
|
||||
m_string_push_back M_R(f, ':');
|
||||
return M_SERIAL_OK_CONTINUE;
|
||||
}
|
||||
|
||||
/* Write a map separator between elements of a map into the serial stream 'serial' if needed.
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_write_map_next(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_str_json, _write_map_next, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
(void) local; // argument not used
|
||||
struct m_string_s *f = (struct m_string_s *)serial->data[0].p;
|
||||
m_string_push_back(f, ',');
|
||||
m_string_push_back M_R(f, ',');
|
||||
return M_SERIAL_OK_CONTINUE;
|
||||
}
|
||||
|
||||
/* End the writing of a map into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_write_map_end(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_str_json, _write_map_end, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
(void) local; // argument not used
|
||||
struct m_string_s *f = (struct m_string_s *)serial->data[0].p;
|
||||
m_string_push_back(f, '}');
|
||||
m_string_push_back M_R(f, '}');
|
||||
return M_SERIAL_OK_CONTINUE;
|
||||
}
|
||||
|
||||
@@ -728,35 +718,32 @@ m_ser1al_str_json_write_map_end(m_serial_local_t local, m_serial_write_t serial)
|
||||
Initialize 'local' so that it can serial the tuple
|
||||
(local is an unique serialization object of the tuple).
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_write_tuple_start(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_str_json, _write_tuple_start, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
(void) local; // argument not used
|
||||
struct m_string_s *f = (struct m_string_s *)serial->data[0].p;
|
||||
m_string_push_back(f, '{');
|
||||
m_string_push_back M_R(f, '{');
|
||||
return M_SERIAL_OK_CONTINUE;
|
||||
}
|
||||
|
||||
/* Start writing the field named field_name[index] of a tuple into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_write_tuple_id(m_serial_local_t local, m_serial_write_t serial, const char *const field_name[], const int max, const int index)
|
||||
M_P(m_serial_return_code_t, m_ser1al_str_json, _write_tuple_id, m_serial_local_t local, m_serial_write_t serial, const char *const field_name[], const int max, const int index)
|
||||
{
|
||||
(void) local; // argument not used
|
||||
(void) max; // Ignored
|
||||
struct m_string_s *f = (struct m_string_s *)serial->data[0].p;
|
||||
int n = m_string_cat_printf(f, "%c\"%s\":", index == 0 ? ' ' : ',', field_name[index]);
|
||||
int n = m_string_cat_printf M_R(f, "%c\"%s\":", index == 0 ? ' ' : ',', field_name[index]);
|
||||
return n > 0 ? M_SERIAL_OK_CONTINUE : m_core_serial_fail();
|
||||
}
|
||||
|
||||
/* End the write of a tuple into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_write_tuple_end(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_str_json, _write_tuple_end, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
(void) local; // argument not used
|
||||
struct m_string_s *f = (struct m_string_s *)serial->data[0].p;
|
||||
m_string_push_back(f, '}');
|
||||
m_string_push_back M_R(f, '}');
|
||||
return M_SERIAL_OK_CONTINUE;
|
||||
}
|
||||
|
||||
@@ -765,8 +752,7 @@ m_ser1al_str_json_write_tuple_end(m_serial_local_t local, m_serial_write_t seria
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise
|
||||
Otherwise, the field 'field_name[index]' will be filled.
|
||||
Return M_SERIAL_OK_CONTINUE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_write_variant_start(m_serial_local_t local, m_serial_write_t serial, const char *const field_name[], const int max, const int index)
|
||||
M_P(m_serial_return_code_t, m_ser1al_str_json, _write_variant_start, m_serial_local_t local, m_serial_write_t serial, const char *const field_name[], const int max, const int index)
|
||||
{
|
||||
(void) local; // argument not used
|
||||
(void) max; // argument not used
|
||||
@@ -774,22 +760,21 @@ m_ser1al_str_json_write_variant_start(m_serial_local_t local, m_serial_write_t s
|
||||
int n;
|
||||
if (index >= 0) {
|
||||
M_ASSERT (index < max);
|
||||
n = m_string_cat_printf(f, "{\"%s\":", field_name[index]);
|
||||
n = m_string_cat_printf M_R(f, "{\"%s\":", field_name[index]);
|
||||
return n > 0 ? M_SERIAL_OK_CONTINUE : m_core_serial_fail();
|
||||
} else {
|
||||
n = m_string_cat_printf(f, "{}");
|
||||
n = m_string_cat_printf M_R(f, "{}");
|
||||
return n > 0 ? M_SERIAL_OK_DONE : m_core_serial_fail();
|
||||
}
|
||||
}
|
||||
|
||||
/* End Writing a variant into the serial stream 'serial'.
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_write_variant_end(m_serial_local_t local, m_serial_write_t serial)
|
||||
M_P(m_serial_return_code_t, m_ser1al_str_json, _write_variant_end, m_serial_local_t local, m_serial_write_t serial)
|
||||
{
|
||||
(void) local; // argument not used
|
||||
struct m_string_s *f = (struct m_string_s *)serial->data[0].p;
|
||||
m_string_push_back(f, '}');
|
||||
m_string_push_back M_R(f, '}');
|
||||
return M_SERIAL_OK_CONTINUE;
|
||||
}
|
||||
|
||||
@@ -933,12 +918,12 @@ m_ser1al_str_json_read_float(m_serial_read_t serial, long double *r, const size_
|
||||
/* Read from the stream 'serial' a string.
|
||||
Set 's' with the string if succeeds
|
||||
Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_read_string(m_serial_read_t serial, struct m_string_s *s){
|
||||
M_P(m_serial_return_code_t, m_ser1al_str_json, _read_string, m_serial_read_t serial, struct m_string_s *s)
|
||||
{
|
||||
const char **f = &serial->data[0].cstr;
|
||||
m_ser1al_str_json_skip(f);
|
||||
const char *e;
|
||||
bool b = m_string_parse_str(s, *f, &e);
|
||||
bool b = m_string_parse_str M_R(s, *f, &e);
|
||||
serial->data[0].cstr = e;
|
||||
return b ? M_SERIAL_OK_DONE : m_core_serial_fail();
|
||||
}
|
||||
|
||||
+6
-5
@@ -1308,8 +1308,8 @@ M_IF_METHOD(OUT_STR, oplist)( extern void M_F(name, _out_str)(FILE *, const shar
|
||||
M_IF_METHOD(IN_STR, oplist)( extern bool M_F(name, _in_str)(shared_t *, FILE *); , ) \
|
||||
M_IF_METHOD(GET_STR, oplist)( extern void M_F(name, _get_str)(m_string_t, const shared_t *, bool); , ) \
|
||||
M_IF_METHOD(PARSE_STR, oplist)( extern bool M_F(name, _parse_str)(shared_t *, const char *, const char **); , ) \
|
||||
M_IF_METHOD(OUT_SERIAL, oplist)( extern m_serial_return_code_t M_F(name, _out_serial)(m_serial_write_t, const shared_t *); , ) \
|
||||
M_IF_METHOD(IN_SERIAL, oplist)( extern m_serial_return_code_t M_F(name, _in_serial)(shared_t *, m_serial_read_t); , ) \
|
||||
M_IF_METHOD(OUT_SERIAL, oplist)( extern m_serial_return_code_t M_F(M_P_EXPAND name, _out_serial)(m_serial_write_t, const shared_t *); , ) \
|
||||
M_IF_METHOD(IN_SERIAL, oplist)( extern m_serial_return_code_t M_F(M_P_EXPAND name, _in_serial)(shared_t *, m_serial_read_t); , ) \
|
||||
|
||||
#define M_SHAR3D_PTR_DEF_IO(name, shared_t, type, oplist, fattr) \
|
||||
M_IF_METHOD(OUT_STR, oplist)( \
|
||||
@@ -1364,12 +1364,13 @@ M_IF_METHOD(PARSE_STR, oplist)( \
|
||||
} \
|
||||
, ) \
|
||||
M_IF_METHOD(OUT_SERIAL, oplist)( \
|
||||
fattr m_serial_return_code_t M_F(name, _out_serial)(m_serial_write_t serial, const shared_t *out) \
|
||||
fattr m_serial_return_code_t M_F(name, _out_serial)(M_P_EXPAND m_serial_write_t serial, const shared_t *out) \
|
||||
{ \
|
||||
M_ASSERT (out != NULL); \
|
||||
M_F(name, _read_lock)(out); \
|
||||
/* FIXME: No exception. Really? */ \
|
||||
m_serial_return_code_t r = M_CALL_OUT_SERIAL(oplist, serial, out->data); \
|
||||
m_volatile m_serial_return_code_t r = M_SERIAL_FAIL; \
|
||||
M_ON_EXCEPTION( M_F(name, _read_unlock)(out) ) \
|
||||
r = M_CALL_OUT_SERIAL(oplist, serial, out->data); \
|
||||
M_F(name, _read_unlock)(out); \
|
||||
return r; \
|
||||
} \
|
||||
|
||||
+10
-16
@@ -1187,7 +1187,6 @@ M_P(int, m_string, _cat_vprintf, m_string_t v, const char format[], va_list args
|
||||
}
|
||||
|
||||
/* Append to the string the formatted string of the given printf format */
|
||||
//FIXME:
|
||||
M_P(int, m_string, _cat_printf, m_string_t v, const char format[], ...)
|
||||
{
|
||||
M_STR1NG_CONTRACT (v);
|
||||
@@ -1633,23 +1632,20 @@ M_P(bool, m_string, _parse_str, m_string_t v, const char str[], const char **end
|
||||
and output it in the given serializer
|
||||
See serialization for return code.
|
||||
*/
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_string_out_serial(m_serial_write_t serial, const m_string_t v)
|
||||
M_P(m_serial_return_code_t, m_string, _out_serial, m_serial_write_t serial, const m_string_t v)
|
||||
{
|
||||
//FIXME: What to do for memory context? Can be passed through serial
|
||||
M_ASSERT (serial != NULL && serial->m_interface != NULL);
|
||||
return serial->m_interface->write_string(serial, m_string_get_cstr(v), m_string_size(v) );
|
||||
return serial->m_interface->write_string M_R(serial, m_string_get_cstr(v), m_string_size(v) );
|
||||
}
|
||||
|
||||
/* Read the formatted string from the serializer
|
||||
and set the converted value in the string 'v'.
|
||||
See serialization for return code.
|
||||
*/
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_string_in_serial(m_string_t v, m_serial_read_t serial)
|
||||
M_P(m_serial_return_code_t, m_string, _in_serial, m_string_t v, m_serial_read_t serial)
|
||||
{
|
||||
M_ASSERT (serial != NULL && serial->m_interface != NULL);
|
||||
return serial->m_interface->read_string(serial, v);
|
||||
return serial->m_interface->read_string M_R(serial, v);
|
||||
}
|
||||
|
||||
/* UTF8 character classification:
|
||||
@@ -2178,7 +2174,7 @@ namespace m_lib {
|
||||
CMP(m_string_cmp), TYPE(m_string_t), GENTYPE(struct m_string_s*), \
|
||||
PARSE_STR(API_0P(m_string_parse_str)), GET_STR(API_0P(m_string_get_str)), \
|
||||
OUT_STR(m_string_out_str), IN_STR(API_0P(m_string_in_str)), \
|
||||
OUT_SERIAL(m_string_out_serial), IN_SERIAL(m_string_in_serial), \
|
||||
OUT_SERIAL(API_0P(m_string_out_serial)), IN_SERIAL(API_0P(m_string_in_serial)), \
|
||||
EXT_ALGO(M_STR1NG_SPLIT), \
|
||||
OOR_EQUAL(m_string_oor_equal_p), OOR_SET(m_string_oor_set) \
|
||||
,SUBTYPE(m_string_unicode_t) \
|
||||
@@ -2695,25 +2691,23 @@ namespace m_lib {
|
||||
return ret; \
|
||||
} \
|
||||
\
|
||||
M_INLINE m_serial_return_code_t \
|
||||
M_F(name, _out_serial)(m_serial_write_t serial, const bounded_t v) \
|
||||
M_P(m_serial_return_code_t, name, _out_serial, m_serial_write_t serial, const bounded_t v) \
|
||||
{ \
|
||||
M_BOUNDED_STR1NG_CONTRACT(v, max_size); \
|
||||
M_ASSERT (serial != NULL && serial->m_interface != NULL); \
|
||||
return serial->m_interface->write_string(serial, v->s, strlen(v->s) ); \
|
||||
return serial->m_interface->write_string M_R(serial, v->s, strlen(v->s) ); \
|
||||
} \
|
||||
\
|
||||
M_INLINE m_serial_return_code_t \
|
||||
M_F(name, _in_serial)(bounded_t v, m_serial_read_t serial) \
|
||||
M_P(m_serial_return_code_t, name, _in_serial, bounded_t v, m_serial_read_t serial) \
|
||||
{ \
|
||||
M_BOUNDED_STR1NG_CONTRACT(v, max_size); \
|
||||
M_ASSERT (serial != NULL && serial->m_interface != NULL); \
|
||||
m_string_t tmp; \
|
||||
/* TODO: Not optimum */ \
|
||||
m_string_init(tmp); \
|
||||
m_serial_return_code_t r = serial->m_interface->read_string(serial, tmp); \
|
||||
m_serial_return_code_t r = serial->m_interface->read_string M_R(serial, tmp); \
|
||||
m_core_strncpy(v->s, max_size+1, m_string_get_cstr(tmp), max_size); \
|
||||
m_string_clear(tmp); \
|
||||
m_string_clear M_R(tmp); \
|
||||
M_BOUNDED_STR1NG_CONTRACT(v, max_size); \
|
||||
return r; \
|
||||
}
|
||||
|
||||
@@ -563,8 +563,7 @@ namespace m_lib {
|
||||
|
||||
/* Define a OUT_SERIAL method by calling the OUT_SERIAL methods for all params */
|
||||
#define M_TUPL3_DEFINE_OUT_SERIAL(name, ...) \
|
||||
M_INLINE m_serial_return_code_t \
|
||||
M_F(name, _out_serial)(m_serial_write_t f, M_F(name,_ct) const el) \
|
||||
M_P(m_serial_return_code_t, name, _out_serial, m_serial_write_t f, M_F(name,_ct) const el) \
|
||||
{ \
|
||||
M_TUPL3_CONTRACT(el); \
|
||||
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||
@@ -575,15 +574,15 @@ namespace m_lib {
|
||||
int index = 0; \
|
||||
m_serial_local_t local; \
|
||||
m_serial_return_code_t ret; \
|
||||
ret = f->m_interface->write_tuple_start(local, f); \
|
||||
ret = f->m_interface->write_tuple_start M_R(local, f); \
|
||||
M_MAP(M_TUPL3_DEFINE_OUT_SERIAL_FUNC , __VA_ARGS__) \
|
||||
M_ASSERT( index == field_max); \
|
||||
ret |= f->m_interface->write_tuple_end(local, f); \
|
||||
ret |= f->m_interface->write_tuple_end M_R(local, f); \
|
||||
return ret & M_SERIAL_FAIL; \
|
||||
}
|
||||
|
||||
#define M_TUPL3_DEFINE_OUT_SERIAL_FUNC(a) \
|
||||
f->m_interface->write_tuple_id(local, f, field_name, field_max, index); \
|
||||
f->m_interface->write_tuple_id M_R(local, f, field_name, field_max, index); \
|
||||
M_TUPL3_CALL_OUT_SERIAL(a, f, el -> M_TUPL3_GET_FIELD a); \
|
||||
index++; \
|
||||
|
||||
|
||||
+4
-5
@@ -690,8 +690,7 @@ M_INLINE void \
|
||||
|
||||
/* Define the OUT_SERIAL function */
|
||||
#define M_VAR1ANT_DEFINE_OUT_SERIAL(name, ...) \
|
||||
M_INLINE m_serial_return_code_t \
|
||||
M_F(name, _out_serial)(m_serial_write_t f, M_F(name,_ct) const el) \
|
||||
M_P(m_serial_return_code_t, name, _out_serial, m_serial_write_t f, M_F(name,_ct) const el) \
|
||||
{ \
|
||||
M_VAR1ANT_CONTRACT(name, el); \
|
||||
const int field_max = M_NARGS(__VA_ARGS__); \
|
||||
@@ -702,18 +701,18 @@ M_INLINE void \
|
||||
m_serial_return_code_t ret; \
|
||||
switch (el->type) { \
|
||||
case M_F(name, _EMPTY): \
|
||||
return f->m_interface->write_variant_start(local, f, field_name, field_max, -1); \
|
||||
return f->m_interface->write_variant_start M_R(local, f, field_name, field_max, -1); \
|
||||
break; \
|
||||
M_MAP2(M_VAR1ANT_DEFINE_OUT_SERIAL_FUNC , name, __VA_ARGS__) \
|
||||
default: M_ASSUME(false); break; \
|
||||
} \
|
||||
ret |= f->m_interface->write_variant_end(local, f); \
|
||||
ret |= f->m_interface->write_variant_end M_R(local, f); \
|
||||
return ret & M_SERIAL_FAIL; \
|
||||
}
|
||||
|
||||
#define M_VAR1ANT_DEFINE_OUT_SERIAL_FUNC(name, a) \
|
||||
case M_C4(name, _, M_VAR1ANT_GET_FIELD a, _value): \
|
||||
ret = f->m_interface->write_variant_start(local, f, field_name, field_max, \
|
||||
ret = f->m_interface->write_variant_start M_R(local, f, field_name, field_max, \
|
||||
M_C4(name, _, M_VAR1ANT_GET_FIELD a, _value) -1); \
|
||||
M_VAR1ANT_CALL_OUT_SERIAL(a, f, el -> value . M_VAR1ANT_GET_FIELD a); \
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user