4 ms·
I was wondering if you've considered having an alternative, human readable encoding (either your own syntax or a JSON-based schema)? I find it quite useful to
by andyferris 3y ago
I was wondering if you've considered having an alternative, human readable encoding (either your own syntax or a JSON-based schema)?
I find it quite useful to be able to inspect data by eye and even hand-editing payloads occassionally, and having a standard syntax for doing so would be nice.
(More generally, it's a shame JSON doesn't support sum types "natively" and I think a human readable format with Typical's data model would be really cool).
- stepchowfun 3y agoIt's a good question! The binary format is completely inscrutable to human eyes and is not designed for manual inspection/editing. However: 1) For Rust, the generated types implement the `Debug` trait, so they can be printed in a textual format that Rust programmers are accustomed to reading. 2) For JavaScript/TypeScript, deserialized messages are simple passive data objects that can be logged or inspected in the developer console. So it's easy to log/inspect deserialized messages in a human-readable format, but there's currently no way to read/edit encoded messages directly. In the future, we may add an option to encode messages as JSON which would match the representation currently used for decoded messages in JavaScript/TypeScript, with sums being encoded as tagged unions.
- andyferris 3y agoThanks. That's a good answer.
- magicalhippo 3y ago> it's a shame JSON doesn't support sum types "natively" You can describe it using JSON Schema though[1], using "oneOf" and "const". Though I prefer the more explicit way of using "oneOf" combined with "required" to select one of a number of keys[2]. [1]: https://www.jsonschemavalidator.net/s/6SCuYNBe https://www.jsonschemavalidator.net/s/6SCuYNBe [2]: https://www.jsonschemavalidator.net/s/tNnQmsTd https://www.jsonschemavalidator.net/s/tNnQmsTd