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

Rfc30/http #2198

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions rust-runtime/aws-smithy-eventstream/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ repository = "https://github.com/awslabs/smithy-rs"

[features]
derive-arbitrary = ["arbitrary", "derive_arbitrary"]
serde-serialize = []
serde-deserialize = []

[dependencies]
derive_arbitrary = { version = "=1.1.6", optional = true } # 1.2.0 requires Rust 1.63 to compile
Expand Down
2 changes: 2 additions & 0 deletions rust-runtime/aws-smithy-eventstream/external-types.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
allowed_external_types = [
"serde::de::Deserialize",
"serde::ser::Serialize",
"aws_smithy_types::*",
"bytes::buf::buf_impl::Buf",
"bytes::buf::buf_mut::BufMut",
Expand Down
11 changes: 11 additions & 0 deletions rust-runtime/aws-smithy-eventstream/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub(crate) enum ErrorKind {
TimestampValueTooLarge(DateTime),
Marshalling(String),
Unmarshalling(String),
DeserializedStream,
}

#[derive(Debug)]
Expand Down Expand Up @@ -51,6 +52,12 @@ impl Error {
kind: ErrorKind::Unmarshalling(message.into()),
}
}

pub const fn deserialized_stream() -> Self {
Self {
kind: ErrorKind::DeserializedStream,
}
}
}

impl From<ErrorKind> for Error {
Expand Down Expand Up @@ -92,6 +99,10 @@ impl fmt::Display for Error {
),
Marshalling(error) => write!(f, "failed to marshall message: {}", error),
Unmarshalling(error) => write!(f, "failed to unmarshall message: {}", error),
DeserializedStream => write!(
f,
"this is a deserialized stream. No message can be sent or be received."
),
}
}
}
2 changes: 2 additions & 0 deletions rust-runtime/aws-smithy-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ repository = "https://github.com/awslabs/smithy-rs"
[features]
rt-tokio = ["tokio/rt", "tokio/fs", "tokio/io-util", "tokio-util/io"]
event-stream = ["aws-smithy-eventstream"]
serde-serialize = ["aws-smithy-eventstream/serde-serialize"]
serde-deserialize = ["aws-smithy-eventstream/serde-deserialize"]

[dependencies]
aws-smithy-eventstream = { path = "../aws-smithy-eventstream", optional = true }
Expand Down
3 changes: 3 additions & 0 deletions rust-runtime/aws-smithy-http/external-types.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
allowed_external_types = [
"serde::de::Deserialize",
"serde::ser::Serialize",

"aws_smithy_types::*",
"bytes::buf::buf_impl::Buf",
"bytes::bytes::Bytes",
Expand Down
5 changes: 5 additions & 0 deletions rust-runtime/aws-smithy-http/src/event_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ use std::error::Error as StdError;
mod receiver;
mod sender;

#[cfg(all(aws_sdk_unstable, feature = "serde-deserialized"))]
mod deserialized_stream;

pub type BoxError = Box<dyn StdError + Send + Sync + 'static>;

#[doc(inline)]
pub use sender::{EventStreamSender, MessageStreamAdapter, MessageStreamError};

#[doc(inline)]
pub use receiver::{RawMessage, Receiver, ReceiverError};

pub use deserialized_stream::*;
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use receiver::{RawMessage, Receiver};

use super::*;
use aws_smithy_eventstream::frame::UnmarshallMessage;
use std::{fmt::Debug, marker::PhantomData};
/// This data is used to fill a field when the users try to deserialize data that has a Receiver in one of the field.
pub struct DeserializedReceiverStream<T, E>(PhantomData<(T, E)>);
impl<T, E> Debug for DeserializedReceiverStream<T, E> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("DeserializedStream")
}
}
impl<T, E> DeserializedReceiverStream<T, E>
where
T: std::fmt::Debug,
E: std::fmt::Debug,
{
/// default value
pub fn create() -> impl UnmarshallMessage<Output = T, Error = E> {
Self(PhantomData::<(T, E)>)
}
}

impl<T, E> UnmarshallMessage for DeserializedReceiverStream<T, E>
where
T: Debug,
E: Debug,
{
type Error = E;
type Output = T;
fn unmarshall(
&self,
_: &aws_smithy_eventstream::frame::Message,
) -> Result<
aws_smithy_eventstream::frame::UnmarshalledMessage<Self::Output, Self::Error>,
aws_smithy_eventstream::error::Error,
> {
Err(aws_smithy_eventstream::error::Error::deserialized_stream())
}
}

/// Error returned from Deserialized Stream.
#[derive(Debug)]
pub struct DeserializedStreamError;

impl StdError for DeserializedStreamError {}
impl std::fmt::Display for DeserializedStreamError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("Stream was deserialized")
}
}