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

json diagnostic #1091

Merged
merged 2 commits into from
Oct 11, 2024
Merged

json diagnostic #1091

merged 2 commits into from
Oct 11, 2024

Conversation

JssDWt
Copy link
Contributor

@JssDWt JssDWt commented Sep 28, 2024

Serialize the diagnostic data into a single json document.

In this PR also an attempt to serialize Vec<u8> as hex. It works, but became a bit of a giant cumbersome project. See the commit message for more information.

Copy link
Contributor

@ok300 ok300 left a comment

Choose a reason for hiding this comment

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

Until someone finds a better way, this is IMO good enough.

It's very useful to have byte arrays pretty-printed as hex.

Copy link
Member

@roeierez roeierez left a comment

Choose a reason for hiding this comment

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

As a temporary solution I think we can go with it. We can also open an issue in cln grpc to add an attribute for the binary vectors to be serialized as hex and then get rid of the custom serialization.

serde_json has no simple way to serialize specific field types as hex,
until specialization is merged. This commit contains a hack to serialize
all Vec<u8> fields as hex anyway. It is impossible to check the type of
a generic type parameter at runtime. So all values are first serialized,
then attempted to deserialize into a Vec<u8>. If that works, the found
vector will be serialized as a hex string, rather than an array of
numbers. This is not a performant machanism, but it gets the job done.
As long as it is only used for dev commands and diagnostic data it
should be fine. At least all those number arrays in the diagnostic data
are now gone, without having to duplicate every struct definition just
for serialization.

Note that the 'Value' serialization is a copy of the real one.
@JssDWt JssDWt merged commit ce23e32 into main Oct 11, 2024
9 checks passed
@ok300 ok300 deleted the jssdwt-json-diagnostic branch October 13, 2024 19:23
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