Incremental JSON <-> struct encoder for implementing preset saving #45
Conversation
|
ambitious and impressive!
gasp. :) code looks good to me so far. i'll take a second look later today. |
| @@ -132,16 +132,19 @@ void arp_seq_init(arp_seq_t* s) { | |||
| } | |||
|
|
|||
| bool arp_seq_set_state(arp_seq_t *s, arp_seq_state state) { | |||
| #ifndef RUNNING_TESTS | |||
scanner-darkly
May 19, 2019
Member
curious, why is this needed? does it need to be done in other places that use irqs_pause/resume? if so, would it be better to move ifndef to the actual functions?
curious, why is this needed? does it need to be done in other places that use irqs_pause/resume? if so, would it be better to move ifndef to the actual functions?
csboling
May 19, 2019
Author
Contributor
I just found this conversation which leads me to believe that this #ifndef isn't needed on the latest master. This was how I made the tests pass when I first made this branch, I can clean this up.
I just found this conversation which leads me to believe that this #ifndef isn't needed on the latest master. This was how I made the tests pass when I first made this branch, I can clean this up.
scanner-darkly
May 19, 2019
Member
ah right, this rings a bell. i think either way is fine - irqs stuff is not needed for running tests anyway.
ah right, this rings a bell. i think either way is fine - irqs stuff is not needed for running tests anyway.
csboling
May 19, 2019
Author
Contributor
Removed RUNNING_TESTS, realized there was actually an error testing json_read_object_cached, added a make target so that if you have valgrind installed you can run make leaks, and found some leaks in the test code - nothing actually affecting the JSON encoder itself I think.
Removed RUNNING_TESTS, realized there was actually an error testing json_read_object_cached, added a make target so that if you have valgrind installed you can run make leaks, and found some leaks in the test code - nothing actually affecting the JSON encoder itself I think.
|
this is great - super useful to have it be part of libavr32. |
This adds library support for JSON serialization, to be used for saving things like Ansible state to USB disk. For discussion see the lines threads Preset save to USB disk and Serialisation of presets. If this PR is accepted I'll open another to the Ansible repo that uses this encoder to implement the preset save feature.
This code implements an encoder which can convert a JSON document with a known structure to and from a C struct, or do any other kind of processing when recognized pieces of JSON data are found. Tokenizing an incoming JSON document uses a modified version of the jsmn library (forked prior to a recent reorganization of that project), which is included. It has the following features which make it suitable for embedded use and easy extensibility.
Encoding functions for common data types are included, such as a decimal encoder which handles signed values, and a hex encoder for encoding large binary arrays into JSON as hex strings, allowing relatively easy human editability of the resulting document. Parsing/serializing floating point numbers is not currently implemented. Use of the decimal encoding functions does require static allocation of a 12 byte buffer, I believe this is the only static memory allocation required to use the library.