* Add length param for seralization write_string

to increase a little bit the performance for big strings.
* Change the format of storing strings for serial-bin.
This commit is contained in:
Patrick Pelissier committed 2020-06-13 17:26:07 +02:00
1 parent 89b6e1aac0
commit cb4b43e2e8
6 files changed
+108 -24

No files matched your search

+6 -4
View File
@@ -63,14 +63,16 @@ m_serial_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 */
static inline m_serial_return_code_t
m_serial_json_write_string(m_serial_write_t serial, const char data[])
m_serial_json_write_string(m_serial_write_t serial, const char data[], size_t length)
{
STRINGI_ASSUME(length == strlen(data) );
FILE *f = (FILE *)serial->data[0].p;
/* Build dummy string to reuse string_out_str */
assert(f != NULL && data != NULL);
/* HACK: Build dummy string to reuse string_out_str */
string_t v2;
uintptr_t ptr = (uintptr_t) data;
v2->u.heap.size = strlen(data);
v2->u.heap.alloc = v2->u.heap.size + 1;
v2->u.heap.size = length;
v2->u.heap.alloc = length + 1;
v2->ptr = (char*)ptr;
string_out_str(f, v2);
return M_SERIAL_OK_DONE;