diff --git a/README.md b/README.md index 38d2e9f2..5014c407 100644 --- a/README.md +++ b/README.md @@ -6851,7 +6851,7 @@ wanted serialization. * data: a table of M\_SERIAL\_MAX\_DATA\_SIZE of C types (Boolean, integer, size or pointer). This data is used to store the needed data for the methods. -This is pretty much like a pure virtual interface object in C++. The interface has to defines +This is pretty much like a pure virtual interface object in C++. The interface has to define the following fields with the following definition: * read\_boolean: @@ -6872,11 +6872,12 @@ the following fields with the following definition: Return M\_SERIAL\_OK\_DONE if it succeeds, M\_SERIAL\_FAIL otherwise * read\_array\_start: Start reading from the stream 'serial' an array (which is defined as a sequential collection of object). - Set '*num' with the number of elements, or 0 if it is not known. + Set '*num' with the number of elements, or (size\_t)-1 if it is not known. Initialize the object 'local' so that it can be used by the serialization object to serialize the array. ('local' is an unique local serialization object of the array). Return M\_SERIAL\_OK\_CONTINUE if it succeeds and the parsing of the array can continue (the array is not empty), M\_SERIAL\_OK\_DONE if it succeeds and the array ends (the array is empty), + M\_SERIAL\_FAIL\_RETRY if it doesn't support unkown number of elements, M\_SERIAL\_FAIL otherwise. * read\_array\_next: Continue reading from the stream 'serial' an array using 'local' to load / save data if needed. diff --git a/m-core.h b/m-core.h index d7577677..31e5cd92 100644 --- a/m-core.h +++ b/m-core.h @@ -4881,9 +4881,10 @@ 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) */ typedef enum m_serial_return_code_e { - M_SERIAL_OK_DONE = 0, M_SERIAL_OK_CONTINUE = 1, M_SERIAL_FAIL = 2 + M_SERIAL_OK_DONE = 0, M_SERIAL_OK_CONTINUE = 1, M_SERIAL_FAIL = 2, M_SERIAL_FAIL_RETRY = 4 } m_serial_return_code_t; #if defined(__cplusplus) diff --git a/m-list.h b/m-list.h index 26fdcc84..9323bfda 100644 --- a/m-list.h +++ b/m-list.h @@ -789,7 +789,11 @@ m_serial_return_code_t ret; \ m_serial_local_t local; \ bool first_done = false; \ - ret = f->m_interface->write_array_start(local, f, 0); \ + ret = f->m_interface->write_array_start(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); \ + } \ it_t it; \ for (M_F(name, _it)(it, list) ; \ !M_F(name, _end_p)(it); \