New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adopt PR #2189: a JSON en/decoder #8312
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preliminary review up until the end of json.h
*/ | ||
json_result_t json_write_float(json_write_cookie_t *cookie, float value); | ||
|
||
#ifndef MODULE_ATMEGA_COMMON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this hardware dependent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ATMEGA did not support int64_t values at all. (In 2014, maybe my toolchain was to blame for that.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will check and adapt as needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case I would prefer a NOP or error message instead of excluding this function completely from the API.
If you squash correctly, @Kijewski's authorship is retained (since ideally his commits are the base commits of your squash commits). If you want to make sure the authorship is retained, you can even use the |
I'll try that 😉 |
for now I reverted my initial squashing and made some fixes to documentation and coding style. Still need to look into this atmega stuff. |
a major problem encountered by Murdock is, that the JSON unittest increase the unittests binary size by >640K (bc it uses a JSON test suite with lots of (really large) tests strings). Thus, rendering most boards incompatible because of low FLASH/ROM size - basically we could change from blacklisting boards to whitelist Any suggestions on that: @RIOT-OS/maintainers ? |
I would say, put it in a separate test in directly in the |
Hmm, it may also be too big for one test alone, so maybe split it into different tests types, tests float, tests strings, tests arrays, tests dicts, and one with mixed data types. |
@smlng what's the current size of this feature? When I reviewed the code of the former PR I found it extremely large, a lot of code for something "simple" especially the encoding. For decoding I agree it might need more lines of code. |
What is the difference with pkg/jsmn? Is it necessary to have two json library? |
jsmn only offers very basic parsing. |
@tcschmidt code-wise: yes, otherwise not so much, because this PR adds unittests for json which are rather huge - meaning that no board can handle the complete unittests binary anymore. There is already a (yet inconclusive) discussion in #8941 (split unittests) on this matter. I can either split of the json unittests right away or wait for consensus in #8941. |
dc4ba87
to
155f093
Compare
hey @miri64 care to have a look at this one again? |
Is there a way maybe to have this PR less than 6000 additions? Maybe split it up in encoder and decoder? Also, I still question the necessaty of changing embunit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review on some build system stuff and the first half of the documentation. While reviewing I tried to look at the code as little as possible for now, since I wanted to understand the API for now before digging into the code.
sys/include/json.h
Outdated
/** | ||
* @brief End a JSON serialization stream. | ||
* | ||
* @note An empty stream without any data is invalid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the stream in this context? What I mean is: How is this note to be understood? Can't I do e.g.
json_write_init(&cookie, _write);
json_write_finish(&cookie);
without crashing?
* JSON does not differentiate between integers and floating point numbers. | ||
* | ||
* @warning The number must be finite, i.e. it must not be NaN, +Inf or -Inf. | ||
* Illegal inputs are not caught but the stream will be broken. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to write those regardless?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In JSON as of RFC 7159 § 6 it is not possible:
Numeric values that cannot be represented in the grammar below (such
as Infinity and NaN) are not permitted.
* @brief The cookie with all the information needed to deserialize JSON data. | ||
* | ||
* @see json_read_init() | ||
* @see @ref container_of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this reference here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll most likely use this struct as a member of your own struct to keep track of it's state. If struct json_write_cookie
is the first member, then you could simply cast the pointer, but if not you'll have to use the macro. If you think that's already obvious, then the reference may be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think such behavior should not be encouraged, so it should be removed. See also this talk ;-).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
smh
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
do we (still) want this in or not? I would squash and make changes if necessary to make it work, but wouldn't "waste" more time on this for restructuring and fixing some not so nice handling. I adopted bc it looked like a nice addition. An open point that I would address is to move the tests out of unittests bc its very big. |
TBH, I'm not really sure. On one hand it would be nice to have a JSON encoder (though one could also do that by hand). With |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
Contribution description
I adopted PR #2189 to get it merged, as IMHO the original contribution is still valuable to RIOT but @Kijewski (original author) hasn't found the time to work on it (no blame for that 😉). I rebased to current master and squashed reasonably, authorship was retained to stay with @Kijewski.
The original PR also included a minor adaption to embUnit, which still is a separate commit and can be dropped, if someone objects.
Otherwise this PR (was and) is in good shape and hence ready to merge.
Issues/PRs references
Adopts sys: add JSON serialization and deserialization module #2189
Requires (and includes) tests: adapt embunit TEST_ASSERT_EQUAL_STRING #10538