implement schema-serde event streams#641
implement schema-serde event streams#641lucix-aws wants to merge 1 commit intofeat-serde2-eventstreamfrom
Conversation
|
relates #458 |
| inner := c.Codec.Serializer() | ||
| ss := NewShapeSerializer(&msg, inner) | ||
|
|
||
| v.Serialize(ss) |
There was a problem hiding this comment.
Some dummy question: what's inside v.Serialize(ss) here? From first glance SerializeEventMessage just encodes payload passed from inner protocol serializer impl and sends that to the wire io.Writer, it's a little obscured to understand what happens inside the Serialize() without an implementation/test for now
There was a problem hiding this comment.
What I understand here is input v contains the payload that will be serialized/encoded to eventmessage/http request, the runtime serialize workflow is decided by the type of v
| DeserializeResponse(ctx context.Context, schema *smithy.OperationSchema, types *smithy.TypeRegistry, resp *Response, out smithy.Deserializable) error | ||
|
|
||
| // event stream APIs | ||
| HasInitialMessages() bool |
There was a problem hiding this comment.
I understand what this means, but from the ClientProtocol interface it's weird to read "HasInitialMessage" since yeah, there are some messages that are "initial". Maybe something like HasInitialEventMessage would make it way more clear that this just event stream related
| } | ||
|
|
||
| // String returns the IDL microformat for the shape ID. | ||
| func (s *ShapeID) String() string { |
There was a problem hiding this comment.
any reason to not make this a pointer receiver?
| Symbol opEventStreamConstructor, | ||
| Symbol opEventStreamSymbol) { | ||
|
|
||
| // For v2 (early-return) event streams, we must: |
| // DeserializeInitialResponse reads the first event stream message and | ||
| // deserializes it as the operation output. | ||
| func (c *Codec) DeserializeInitialResponse(schema *smithy.Schema, r io.Reader, out smithy.Deserializable) error { | ||
| c.payloadBuf = c.payloadBuf[0:0] |
| } | ||
|
|
||
| func (d *ShapeDeserializer) ReadString(s *smithy.Schema, v *string) error { | ||
| if d.inBindings { |
There was a problem hiding this comment.
mostly a question for me, but why inBindings mean look into event stream stuff?
| if d.inBindings && isEventHeader(s) { | ||
| return readEventHeaderInt(d, s, v) | ||
| } | ||
| return d.inner.ReadInt8(s, v) |
There was a problem hiding this comment.
should we do any bounds check?
| var unionSymbol = symbolProvider.toSymbol(union); | ||
| var implName = StringUtils.uncapitalize(union.getId().getName(serviceShape)) + "Reader"; | ||
| var ifaceName = getEventStreamReaderInterfaceName(serviceShape, union); | ||
| var members = union.members().stream() |
There was a problem hiding this comment.
throw a sorted when iterating through members, I noticed that our current code generation basically iterates this at random, so we generate a lot more releases of protocol test than we should https://github.com/aws/aws-sdk-go-v2/commits/main/internal/protocoltest/awsrestjson/deserializers.go
|
|
||
| output, ok := out.Result.($output:P) | ||
| if out.Result != nil && !ok { | ||
| return out, md, $fmtErrorf:T("unexpected output result type: %T", out.Result) |
There was a problem hiding this comment.
Should we also add "Expected type X got Y"?
implements schema-serde event stream support for aws-framed protocols (i.e. all of them)
https://smithy.io/2.0/aws/amazon-eventstream.html#amazon-eventstream
This is fundamentally the exact same thing that we had before, with all of the pieces of event stream wireup split out to allow for schema-serde. If you open up an existing generated event stream body, e.g. https://github.com/aws/aws-sdk-go-v2/blob/main/service/transcribestreaming/eventstream.go, you will see how things sort of map out in the new runtime. I made a point of preserving the structure of the old code as much as possible.
at a glance:
example of generated type adapter:
I did manual e2e tests w/ transcribestreaming,bedrockruntime, and cloudwatchlogs.