ChimeHQ / JSONRPC

Swift library for JSON-RPC
BSD 3-Clause "New" or "Revised" License
28 stars 8 forks source link

Implement `JSONValue` Decoder #3

Closed jscheid closed 1 year ago

jscheid commented 1 year ago

Here is a new feature that allows decoding a JSONValue into a Decodable.

Its primary purpose is to allow casting an AnyJSONRPCNotification, or its payload, into a more specific type. This is useful when a type can be derived from partial notification data. For example, the notification might be a subscription update containing a subscription ID, which can be used to look up the expected payload type.

There might be other use cases as well, for instance polymorphic responses.

Decoding JSON first to JSONValue, then from JSONValue to the final type is somewhat inefficient compared to directly decoding to the target type. However, direct decoding can be relatively complicated depending on the use case and sacrifices flexibility. Since JSON-RPC already isn't the most efficient RPC format out there I think it's a trade-off worth making, what do you think?

mattmassicotte commented 1 year ago

This is a fascinating concept! I think I could use something like this.

mattmassicotte commented 1 year ago

@jscheid did you notice the comments here? I'm never quite sure what I'm doing with PR reviews.

jscheid commented 1 year ago

Hmm no sorry, don't see any comments. Just the one where you said you could use something like it, but didn't think it needed a response.

Perhaps you've started a review and didn't finish it. If you don't finish it the comments will just stay in limbo and only you can see them. If you did finish it, can you point me at one comment using its URL?

jscheid commented 1 year ago

Ah there they are 😄 Thanks, I'll have a look later today.