Define a Deserializer from JS values#2985
Conversation
eeca254 to
aa8249c
Compare
| // We expect a canonical representation of a sum value in JS to be | ||
| // `{ tag: "foo", value: a_value_for_foo }` | ||
| // with special convenience for optionals | ||
| // where we also accept `null`, `undefined` and an object without `tag`. |
There was a problem hiding this comment.
It feels mildly footgun-ey that putting a tag within an object breaks using the convenience representation, and therefore that Option<enum { Foo, Bar }> must be represented as { "tag": "Some", "value": { "tag": "Foo" } }. I think we probably should require that optionals be null | undefined | bare_value, never the "regular sum" representation.
There was a problem hiding this comment.
I think we probably should require that optionals be
null | undefined | bare_value, never the "regular sum" representation.
If we want to remove the special case, I'd rather opt for always using the "regular sum" repr, as otherwise, you cannot represent Some(None), which is possible in both Rust and C# modules. This will make things slightly less convenient for the module author, but we can add some convenience functions on the TS bindings side.
(See also #2996 (comment).)
Description of Changes
Defines
Deserializer, which can deserialize av8::Valueto SATS values.API and ABI breaking changes
None
Expected complexity level and risk
Doesn't interact with existing code.
Testing
Roundtrip tests will be added in the next PR which will define
Serializer.