Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add incomplete Event Stream support with working Amazon Transcribe example #653

Merged
merged 20 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1b1f13a
Add incomplete Event Stream support with working Amazon Transcribe ex…
jdisanti Aug 9, 2021
30ea274
Make the raw response in SdkError generic
jdisanti Aug 17, 2021
4d5c6c2
Fix XmlBindingTraitSerializerGeneratorTest
jdisanti Aug 17, 2021
4ce410b
Make the build aware of the SMITHYRS_EXPERIMENTAL_EVENTSTREAM switch
jdisanti Aug 17, 2021
ef47f2c
Fix SigV4SigningCustomizationTest
jdisanti Aug 17, 2021
035ee1e
Update changelog
jdisanti Aug 17, 2021
7d2ab92
Fix build when SMITHYRS_EXPERIMENTAL_EVENTSTREAM is not set
jdisanti Aug 17, 2021
7733d47
Add initial unit test for EventStreamUnmarshallerGenerator
jdisanti Aug 18, 2021
982687e
Add event header unmarshalling support
jdisanti Aug 18, 2021
a18429c
Don't pull in event stream dependencies by default
jdisanti Aug 18, 2021
f8b7954
Only add event stream signer to config for services that need it
jdisanti Aug 18, 2021
16aeade
Move event stream inlineables into smithy-eventstream
jdisanti Aug 18, 2021
52643b3
Fix some clippy lints
jdisanti Aug 18, 2021
7045bcc
Transform event stream unions
jdisanti Aug 18, 2021
33c26ed
Merge remote-tracking branch 'upstream/main' into eventstream-codegen
jdisanti Aug 18, 2021
6df5edb
Fix crash in SigV4SigningDecorator
jdisanti Aug 19, 2021
d0b147e
Add test for unmarshalling errors
jdisanti Aug 19, 2021
0aa64e5
Merge remote-tracking branch 'upstream/main' into eventstream-codegen
jdisanti Aug 19, 2021
553aec2
Incorporate CR feedback
jdisanti Aug 20, 2021
23b5244
Merge remote-tracking branch 'upstream/main' into eventstream-codegen
jdisanti Aug 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n
"smithy_http::event_stream"
)

fun eventStreamInlinables(runtimeConfig: RuntimeConfig): RuntimeType =
forInlineDependency(InlineDependency.eventStream(runtimeConfig))

fun jsonErrors(runtimeConfig: RuntimeConfig) =
forInlineDependency(InlineDependency.jsonErrors(runtimeConfig))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class BuilderGenerator(
}
}

// TODO(EventStream): [DX] Update builders to take EventInputStream as Into<EventInputStream>
// TODO(EventStream): [DX] Consider updating builders to take EventInputStream as Into<EventInputStream>
private fun renderBuilderMember(writer: RustWriter, member: MemberShape, memberName: String, memberSymbol: Symbol) {
// builder members are crate-public to enable using them
// directly in serializers/deserializers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ class ResponseBindingGenerator(
) {
// Streaming unions are Event Streams and should be handled separately
val target = model.expectShape(binding.member.target)
if (target.isUnionShape) {
bindEventStreamOutput(operationShape, target as UnionShape)
if (target is UnionShape) {
bindEventStreamOutput(operationShape, target)
} else {
deserializeStreamingBody(binding)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class EventStreamUnmarshallerGenerator(
"Error" to RuntimeType("Error", smithyEventStream, "smithy_eventstream::error"),
"Header" to RuntimeType("Header", smithyEventStream, "smithy_eventstream::frame"),
"HeaderValue" to RuntimeType("HeaderValue", smithyEventStream, "smithy_eventstream::frame"),
"Inlineables" to RuntimeType.eventStreamInlinables(runtimeConfig),
"ExpectFns" to RuntimeType("smithy", smithyEventStream, "smithy_eventstream"),
jdisanti marked this conversation as resolved.
Show resolved Hide resolved
"Message" to RuntimeType("Message", smithyEventStream, "smithy_eventstream::frame"),
"SmithyError" to RuntimeType("Error", CargoDependency.SmithyTypes(runtimeConfig), "smithy_types"),
"UnmarshallMessage" to RuntimeType("UnmarshallMessage", smithyEventStream, "smithy_eventstream::frame"),
Expand Down Expand Up @@ -101,7 +101,7 @@ class EventStreamUnmarshallerGenerator(
) {
rustBlockTemplate(
"""
let response_headers = #{Inlineables}::parse_response_headers(&message)?;
let response_headers = #{ExpectFns}::parse_response_headers(&message)?;
match response_headers.message_type.as_str()
""",
*codegenScope
Expand Down Expand Up @@ -187,14 +187,14 @@ class EventStreamUnmarshallerGenerator(
val memberName = symbolProvider.toMemberName(member)
withBlock("builder = builder.$memberName(", ");") {
when (val target = model.expectShape(member.target)) {
is BooleanShape -> rustTemplate("#{Inlineables}::expect_bool(header)?", *codegenScope)
is ByteShape -> rustTemplate("#{Inlineables}::expect_byte(header)?", *codegenScope)
is ShortShape -> rustTemplate("#{Inlineables}::expect_int16(header)?", *codegenScope)
is IntegerShape -> rustTemplate("#{Inlineables}::expect_int32(header)?", *codegenScope)
is LongShape -> rustTemplate("#{Inlineables}::expect_int64(header)?", *codegenScope)
is BlobShape -> rustTemplate("#{Inlineables}::expect_byte_array(header)?", *codegenScope)
is StringShape -> rustTemplate("#{Inlineables}::expect_string(header)?", *codegenScope)
is TimestampShape -> rustTemplate("#{Inlineables}::expect_timestamp(header)?", *codegenScope)
is BooleanShape -> rustTemplate("#{ExpectFns}::expect_bool(header)?", *codegenScope)
is ByteShape -> rustTemplate("#{ExpectFns}::expect_byte(header)?", *codegenScope)
is ShortShape -> rustTemplate("#{ExpectFns}::expect_int16(header)?", *codegenScope)
is IntegerShape -> rustTemplate("#{ExpectFns}::expect_int32(header)?", *codegenScope)
is LongShape -> rustTemplate("#{ExpectFns}::expect_int64(header)?", *codegenScope)
is BlobShape -> rustTemplate("#{ExpectFns}::expect_byte_array(header)?", *codegenScope)
is StringShape -> rustTemplate("#{ExpectFns}::expect_string(header)?", *codegenScope)
is TimestampShape -> rustTemplate("#{ExpectFns}::expect_timestamp(header)?", *codegenScope)
else -> throw IllegalStateException("unsupported event stream header shape type: $target")
}
}
Expand Down
1 change: 0 additions & 1 deletion rust-runtime/inlineable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ are to allow this crate to be compilable and testable in isolation, no client co
[dependencies]
"bytes" = "1"
"http" = "0.2.1"
"smithy-eventstream" = { path = "../smithy-eventstream" }
"smithy-types" = { path = "../smithy-types" }
"smithy-http" = { path = "../smithy-http" }
"smithy-json" = { path = "../smithy-json" }
Expand Down
1 change: 1 addition & 0 deletions rust-runtime/smithy-eventstream/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
mod buf;
pub mod error;
pub mod frame;
pub mod smithy;
pub mod str_bytes;
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
* SPDX-License-Identifier: Apache-2.0.
*/

use smithy_eventstream::error::Error;
use smithy_eventstream::frame::{Header, HeaderValue, Message};
use smithy_eventstream::str_bytes::StrBytes;
use crate::error::Error;
use crate::frame::{Header, HeaderValue, Message};
use crate::str_bytes::StrBytes;
use smithy_types::{Blob, Instant};

pub struct ResponseHeaders<'a> {
pub content_type: &'a StrBytes,
pub message_type: &'a StrBytes,
pub smithy_type: &'a StrBytes,
}

macro_rules! expect_shape_fn {
(fn $fn_name:ident[$val_typ:ident] -> $result_typ:ident { $val_name:ident -> $val_expr:expr }) => {
pub fn $fn_name(header: &Header) -> Result<$result_typ, Error> {
Expand All @@ -38,6 +32,12 @@ expect_shape_fn!(fn expect_byte_array[ByteArray] -> Blob { bytes -> Blob::new(by
expect_shape_fn!(fn expect_string[String] -> String { value -> value.as_str().into() });
expect_shape_fn!(fn expect_timestamp[Timestamp] -> Instant { value -> *value });

pub struct ResponseHeaders<'a> {
pub content_type: &'a StrBytes,
pub message_type: &'a StrBytes,
pub smithy_type: &'a StrBytes,
}

fn expect_header_str_value<'a>(
header: Option<&'a Header>,
name: &str,
Expand Down Expand Up @@ -87,8 +87,8 @@ pub fn parse_response_headers(message: &Message) -> Result<ResponseHeaders, Erro

#[cfg(test)]
mod tests {
use crate::event_stream::parse_response_headers;
use smithy_eventstream::frame::{Header, HeaderValue, Message};
use super::parse_response_headers;
use crate::frame::{Header, HeaderValue, Message};

#[test]
fn normal_message() {
Expand Down