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

add serial to json example #80

Merged
merged 1 commit into from
Sep 23, 2023
Merged

Conversation

twpayne
Copy link
Contributor

@twpayne twpayne commented Sep 21, 2023

This example is very similar to the existing stream-requests example, but emits JSON instead of log messages.

This example is particularly useful as a monitor when combined with a JSON tool like jq. For example, to display only heartbeat messages you can do:

$ go run ./examples/serial-to-json | jq 'select(.MessageType == "*minimal.MessageHeartbeat")

@codecov
Copy link

codecov bot commented Sep 21, 2023

Codecov Report

Merging #80 (315224f) into main (f48820d) will decrease coverage by 2.78%.
Report is 33 commits behind head on main.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main      #80      +/-   ##
==========================================
- Coverage   83.76%   80.98%   -2.78%     
==========================================
  Files          24       26       +2     
  Lines        1786     2030     +244     
==========================================
+ Hits         1496     1644     +148     
- Misses        236      299      +63     
- Partials       54       87      +33     

see 17 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@aler9 aler9 left a comment

Choose a reason for hiding this comment

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

Thanks for this example, it's particularly useful since this library currently lacks a storage format, and JSON may be a future storage format, along with binlog (bluenviron/mavp2p#24).

I'm not particularly happy about the fact that the standard JSON library can't handle NaNs, but i think it's a problem that can be handled in a second moment.

Please perform the following changes:

  • add the example to the README
  • replace log.Panic with panic since the latter is used in all other examples and it's the user responsibility to replace panic with his own error logic, without imposing usage of the log package.

@twpayne
Copy link
Contributor Author

twpayne commented Sep 22, 2023

Thanks for the review. PR updated.

I'm not particularly happy about the fact that the standard JSON library can't handle NaNs, but i think it's a problem that can be handled in a second moment.

It's not the standard library which is at fault here: JSON has no way of representing NaNs, indeed there is no string format for NaNs that I know of.

@aler9 aler9 merged commit fb76b0a into bluenviron:main Sep 23, 2023
@twpayne twpayne deleted the serial-to-json branch September 24, 2023 19:17
@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants