Skip to content

Conversation

@pmiettinen
Copy link
Contributor

@pmiettinen pmiettinen commented Mar 15, 2019

Sorting is not done by default to avoid decrease in efficiency.

@pmiettinen
Copy link
Contributor Author

@mfine How big task would it be to add similar option to haskell sbp2json? I tried to figure out myself but there's just too much cryptic stuff for a person with near 0 haskell experience.

@mfine
Copy link
Contributor

mfine commented Mar 15, 2019

@pmiettinen there's a module aeson-pretty that can sort the JSON keys on encoding.

But do you need to build it into the utilities? jq will do this for you with -S:

➜  c/tests/data git:(bf2cf4b) cat nmea.sbp | sbp2json  | head -2
{"length":24,"status":0,"preamble":85,"sender":48492,"msg_type":175,"setting":"udp_server1\u0000port\u000055558\u0000","payload":"AHVkcF9zZXJ2ZXIxAHBvcnQANTU1NTgA","crc":29999}
{"length":64,"status":0,"preamble":85,"sender":48492,"msg_type":175,"setting":"udp_client0\u0000mode\u0000Disabled\u0000enum:Disabled,RTCMv3 IN,NMEA OUT,SBP\u0000","payload":"AHVkcF9jbGllbnQwAG1vZGUARGlzYWJsZWQAZW51bTpEaXNhYmxlZCxSVENNdjMgSU4sTk1FQSBPVVQsU0JQAA==","crc":58399}
➜  c/tests/data git:(bf2cf4b) cat nmea.sbp | sbp2json  | head -2 | jq -rcS 
{"crc":29999,"length":24,"msg_type":175,"payload":"AHVkcF9zZXJ2ZXIxAHBvcnQANTU1NTgA","preamble":85,"sender":48492,"setting":"udp_server1\u0000port\u000055558\u0000","status":0}
{"crc":58399,"length":64,"msg_type":175,"payload":"AHVkcF9jbGllbnQwAG1vZGUARGlzYWJsZWQAZW51bTpEaXNhYmxlZCxSVENNdjMgSU4sTk1FQSBPVVQsU0JQAA==","preamble":85,"sender":48492,"setting":"udp_client0\u0000mode\u0000Disabled\u0000enum:Disabled,RTCMv3 IN,NMEA OUT,SBP\u0000","status":0}
➜  c/tests/data git:(bf2cf4b) 

@pmiettinen
Copy link
Contributor Author

@mfine I think jq is enough for my purposes for now. Thanks.

I found the aeson-pretty module also myself but I have too many holes in my understanding of the Haskell syntax (among other things) that I didn't figure out how to use it.

@mfine
Copy link
Contributor

mfine commented Mar 15, 2019

@pmiettinen the SBP2JSON doesn't take options presently (at the time, that was the idea to keep it simple and based on stdin stdout - probably should have added options support). To keep things as they are, you could do a SBP2PRETTYJSON or something, similar to SBP2JSON, but change the encoding to use aseon-pretty:

https://github.com/swift-nav/libsbp/blob/master/haskell/main/SBP2JSON.hs#L28

@pmiettinen pmiettinen force-pushed the pmiettinen/esd-1169-json-sorted branch from c0e9a8b to bd18311 Compare March 15, 2019 16:09
@pmiettinen pmiettinen requested a review from mfine March 15, 2019 16:12
@pmiettinen
Copy link
Contributor Author

@mfine SBP2PRETTYJSON.hs is now added. Please check what you think. I am still thinking of adding the pretty print config as an optional command line argument.

Copy link
Contributor

@mfine mfine left a comment

Choose a reason for hiding this comment

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

Yup, that's the idea - good job!

@pmiettinen pmiettinen force-pushed the pmiettinen/esd-1169-json-sorted branch from a6ef6e9 to bc79542 Compare March 18, 2019 12:39
@pmiettinen pmiettinen changed the title [WIP] Sort JSON by keys [ESD-1169] Sort JSON by keys [ESD-1169] Mar 18, 2019
@silverjam
Copy link
Contributor

Would prefer if we can make this a CLI switch for Haskell somehow and expose the Python option through a switch to (I guess) serial_link.

@mfine
Copy link
Contributor

mfine commented Mar 18, 2019

I'm good with the separate binary for Haskell.

@silverjam
Copy link
Contributor

ok, we'll go with your preference @mfine

@pmiettinen pmiettinen merged commit 6905a89 into master Mar 20, 2019
@pmiettinen pmiettinen deleted the pmiettinen/esd-1169-json-sorted branch March 20, 2019 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants