Implement Serial Json Read tuple
This commit is contained in:
1 parent
4accdc994d
commit
b525723084
3 files changed
+36
-4
No files matched your search
+24
-1
@@ -199,8 +199,31 @@ m_serial_json_read_tuple_id(m_serial_read_t serial, const char *const field_name
|
||||
FILE *f = (FILE*) serial->data[0];
|
||||
int c = m_serial_json_read_skip(f);
|
||||
if (c == '}') return M_SERIAL_OK_DONE;
|
||||
if (c == ',') {
|
||||
// If first call of read_tuple_id, it is a failure
|
||||
if (*id == -1) return M_SERIAL_FAIL;
|
||||
c = m_serial_json_read_skip(f);
|
||||
}
|
||||
if (c != '"') return M_SERIAL_FAIL;
|
||||
|
||||
/* Read the field in the JSON */
|
||||
char field[M_MAX_IDENTIFIER_LENGTH];
|
||||
int n = 0;
|
||||
do {
|
||||
c =fgetc(f);
|
||||
field[n++] = c;
|
||||
} while (n < M_MAX_IDENTIFIER_LENGTH && c != EOF && c != '\"');
|
||||
field[--n] = 0;
|
||||
if (c != '"') return M_SERIAL_FAIL;
|
||||
c =fgetc(f);
|
||||
if (c != ':') return M_SERIAL_FAIL;
|
||||
/* Search for field in field_name */
|
||||
for(n = 0; n < max; n++) {
|
||||
if (strcmp(field, field_name[n]) == 0)
|
||||
break;
|
||||
}
|
||||
if (n == max) return M_SERIAL_FAIL;
|
||||
*id = n;
|
||||
return M_SERIAL_OK_CONTINUE;
|
||||
}
|
||||
|
||||
static inline m_serial_return_code_t m_serial_json_read_variant_start(m_serial_read_t serial, const char *const field_name[], const int max, int*id){ return M_SERIAL_FAIL; }
|
||||
|
||||
Reference in new issue
Block a user