Closed djc closed 1 week ago
(The previous run of the integration tests seemed to pass, and they passed locally, too.)
I'm leaving the company where I was working with Temporal, so I probably won't be pushing this forward anymore. Feel free to reuse any of the code here for future changes.
What was changed
So far, the sdk and sdk-core-protos crates have specialized JSON encoding of payloads with the
AsJsonPayloadExt
andFromJsonPayloadExt
traits. Some implementations in the Rust SDK have effectively encoded that in the API so that it is harder or non-intuitive to use any other encoding. This PR interposesEncoder
andDecoder
traits so each type that must be converted into/from aPayload
has to explicitly opt in to this behavior, and gets to chose which encoding is used. AJson
encoding is provided that makes it easy to regain the previous behavior of encoding as JSON.Why?
The Temporal infrastructure/gRPC protocol allows encoding in a number of different ways and this is exposed to the other SDKs. However, the Rust SDK so far has facilitated JSON to the point where it is hard to use anything else. Given Rust's type system, we can do better and make it statically required for types to opt in to a particular encoding, and for the SDK to rely on these implementations to encode to and decode from the
Payload
type.This will also help users of the Rust SDK to implement a type system boundary that makes sure any types used in Temporal workflows/activities must be encrypted, because opting into an encoding is required.
Some previous discussion in this Slack thread: https://temporalio.slack.com/archives/C02MTL0GEKH/p1708568506832879.
Checklist