Skip to content
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

Closed
wants to merge 16 commits into from
Closed

Conversation

smlng
Copy link
Member

@smlng smlng commented Dec 22, 2017

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

@smlng smlng added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Dec 22, 2017
@smlng smlng added this to the Release 2018.01 milestone Dec 22, 2017
@smlng smlng changed the title Adopt/pr2189 Adopt PR #2189 Dec 22, 2017
@smlng smlng changed the title Adopt PR #2189 Adopt PR #2189: a JSON en/decoder Dec 22, 2017
Copy link
Member

@miri64 miri64 left a 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

sys/include/json.h Outdated Show resolved Hide resolved
*/
json_result_t json_write_float(json_write_cookie_t *cookie, float value);

#ifndef MODULE_ATMEGA_COMMON
Copy link
Member

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?

Copy link
Contributor

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.)

Copy link
Member Author

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

Copy link
Member

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.

sys/include/json.h Show resolved Hide resolved
@smlng
Copy link
Member Author

smlng commented Jan 9, 2018

general question: how to proceed with the requested changes? I'd like to retain the original author ship of @Kijewski, but also squashing was needed (already done here) and now need to add the fixes. Just add them as separate commits, what do you think? @miri64

@miri64
Copy link
Member

miri64 commented Jan 9, 2018

general question: how to proceed with the requested changes? I'd like to retain the original author ship of @Kijewski, but also squashing was needed (already done here) and now need to add the fixes. Just add them as separate commits, what do you think? @miri64

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 --author=<author> parameter for git commit to set the authorship for your fixup commits. If there is a significant change (i.e. removing the platform dependency of the API) you can have it as a separate PR with yourself as an author.

@smlng
Copy link
Member Author

smlng commented Jan 9, 2018

If you squash correctly

I'll try that 😉

@smlng
Copy link
Member Author

smlng commented Jan 9, 2018

for now I reverted my initial squashing and made some fixes to documentation and coding style. Still need to look into this atmega stuff.

@smlng
Copy link
Member Author

smlng commented Jan 10, 2018

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 native only.

Any suggestions on that: @RIOT-OS/maintainers ?

@cladmi
Copy link
Contributor

cladmi commented Jan 10, 2018

I would say, put it in a separate test in directly in the tests directory.

@cladmi
Copy link
Contributor

cladmi commented Jan 10, 2018

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.
Pthreads, threads, xtimer also have several tests folders.

@kYc0o
Copy link
Contributor

kYc0o commented Jan 10, 2018

@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.

@biboc
Copy link
Member

biboc commented Jan 11, 2018

What is the difference with pkg/jsmn? Is it necessary to have two json library?

@kaspar030
Copy link
Contributor

What is the difference with pkg/jsmn? Is it necessary to have two json library?

jsmn only offers very basic parsing.

@smlng smlng removed this from the Release 2018.01 milestone Jan 15, 2018
@tcschmidt
Copy link
Member

@smlng @miri64 is this a quick finish?

@smlng
Copy link
Member Author

smlng commented Jul 12, 2018

@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.

@smlng smlng force-pushed the adopt/pr2189 branch 2 times, most recently from dc4ba87 to 155f093 Compare December 1, 2018 17:44
@smlng
Copy link
Member Author

smlng commented Dec 1, 2018

hey @miri64 care to have a look at this one again?

@RIOT-OS RIOT-OS deleted a comment Dec 2, 2018
@miri64
Copy link
Member

miri64 commented Dec 2, 2018

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.

Copy link
Member

@miri64 miri64 left a 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/json/Makefile Outdated Show resolved Hide resolved
sys/json/json_write.c Show resolved Hide resolved
sys/include/json.h Show resolved Hide resolved
/**
* @brief End a JSON serialization stream.
*
* @note An empty stream without any data is invalid.
Copy link
Member

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?

sys/include/json.h Outdated Show resolved Hide resolved
sys/include/json.h Outdated Show resolved Hide resolved
* 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.
Copy link
Member

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?

Copy link
Contributor

@Kijewski Kijewski Dec 19, 2018

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.

sys/include/json.h Outdated Show resolved Hide resolved
sys/include/json.h Outdated Show resolved Hide resolved
* @brief The cookie with all the information needed to deserialize JSON data.
*
* @see json_read_init()
* @see @ref container_of
Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Member

@miri64 miri64 Jan 9, 2019

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 ;-).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smh

@RIOT-OS RIOT-OS deleted a comment Dec 7, 2018
@RIOT-OS RIOT-OS deleted a comment Jan 18, 2019
@stale
Copy link

stale bot commented Aug 29, 2019

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.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Aug 29, 2019
@stale stale bot removed the State: stale State: The issue / PR has no activity for >185 days label Sep 19, 2019
@smlng
Copy link
Member Author

smlng commented Oct 15, 2019

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.

@miri64
Copy link
Member

miri64 commented Oct 15, 2019

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 jsmn we already have a decoder however, that is less fat. On the other hand, as you said, there is definitely some fixing and rework required to get this in. I'd say: your work, your decision :-).

@stale
Copy link

stale bot commented Apr 17, 2020

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.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Apr 17, 2020
@stale stale bot closed this May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR State: stale State: The issue / PR has no activity for >185 days Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants