Skip to content

Commit

Permalink
Avoid opaque byte fields/containers (#35)
Browse files Browse the repository at this point in the history
This PR deprecates the `bytes coroutine_state` field on `Poll{,Result}`
in favor of a `google.protobuf.Any` field. The additional type URL will
help systems introspecting the state; they would otherwise have to guess
what the opaque bytes represent.

This PR also adds a wrapper message for
[pickled](https://docs.python.org/3/library/pickle.html) Python values,
so that the Python SDK can attach a type URL to Python
[inputs](https://github.com/dispatchrun/dispatch-proto/blob/e74123286e7a74baa9f9e64321fceca89242ad04/dispatch/sdk/v1/call.proto#L34),
[outputs](https://github.com/dispatchrun/dispatch-proto/blob/e74123286e7a74baa9f9e64321fceca89242ad04/dispatch/sdk/v1/call.proto#L56)
and now `state`. Previously we were using the built-in
[`BytesValue`](https://github.com/protocolbuffers/protobuf/blob/4a5660c889ef9eb4161dded5c2e91c46f0c30924/src/google/protobuf/wrappers.proto#L120)
message, and so elsewhere had to guess what the opaque bytes represent.
  • Loading branch information
chriso authored Jun 12, 2024
2 parents e741232 + 62e5f53 commit 547fc5b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 3 additions & 1 deletion buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ deps:
- buf.build/bufbuild/protovalidate
breaking:
use:
- FILE
- WIRE_JSON
except:
- FIELD_SAME_ONEOF
lint:
use:
- DEFAULT
10 changes: 10 additions & 0 deletions dispatch/sdk/python/v1/pickled.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";

package dispatch.sdk.python.v1;

// Pickled is a wrapper for a value that was serialized with
// the Python pickle package.
message Pickled {
// Pickled representation of a value.
bytes pickled_value = 1;
}
11 changes: 9 additions & 2 deletions dispatch/sdk/v1/poll.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ package dispatch.sdk.v1;
import "buf/validate/validate.proto";
import "dispatch/sdk/v1/call.proto";
import "dispatch/sdk/v1/error.proto";
import "google/protobuf/any.proto";
import "google/protobuf/duration.proto";

// Poll is a directive to make asynchronous calls and join on their results.
message Poll {
// Snapshot of the coroutine state that will be used in the next run to
// resume the function.
bytes coroutine_state = 1;
oneof state {
bytes coroutine_state = 1;
google.protobuf.Any typed_coroutine_state = 6;
}

// Calls to make asynchronously.
repeated Call calls = 2;
Expand Down Expand Up @@ -45,7 +49,10 @@ message Poll {
message PollResult {
// The coroutine state that was recorded by the coroutine when it was last
// paused.
bytes coroutine_state = 1;
oneof state {
bytes coroutine_state = 1;
google.protobuf.Any typed_coroutine_state = 4;
}

// The list of results from calls that were made by the coroutine and
// completed during the poll.
Expand Down

0 comments on commit 547fc5b

Please sign in to comment.