The undefined number of element value of serial _array_start

is now (size_t)-1 and no longer 0.
Moreoever, a serialization interface may refuse outputting data
if it doesn't know the number of elements.
In which case, the container shall explictly compute the number
of elements and recall the serial object _array_start method.
This commit is contained in:
Patrick Pelissier committed 2023-04-27 00:01:50 +02:00
1 parent a913d0947c
commit 0a39a17d36
3 files changed
+10 -4

No files matched your search

+3 -2
View File
@@ -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.
+2 -1
View File
@@ -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)
+5 -1
View File
@@ -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); \