Skip to content

Commit

Permalink
feat(socketioxide): wip: unify non-binary and binary data
Browse files Browse the repository at this point in the history
This allows users to create a payload struct (that implements
Serialize/Deserialize) that has any binary payload data embedded in the
struct directly, rather than needing to look in a "side" Vec of payload
data, and have to guess what order the binary payloads fit into their
data model.

To accomplish this, there are new Serializer and Deserializer
implementations that mostly wrap the Ser/Deser impls provided for
serde_json::Value.  Unfortunately serde_json doesn't expose everything
necessary to do this in a truly simple way; some duplication of
serde_json's functionality is needed.

NB: due to difficulties with lifetimes, the deserializer has to
currently clone the Vec of binary payloads as they get passed around to
sub-deserializers.  While this isn't the worst thing (cloning Bytes is
cheap), it's not free, and this needs to be revisited and fixed.

Closes Totodore#276.
  • Loading branch information
kelnos committed Mar 15, 2024
1 parent b7e5e24 commit 3a795d1
Show file tree
Hide file tree
Showing 5 changed files with 1,565 additions and 2 deletions.
4 changes: 2 additions & 2 deletions socketioxide/src/handler/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ where
fn from_message_parts(
_: &Arc<Socket<A>>,
v: &mut serde_json::Value,
_: &mut Vec<Bytes>,
b: &mut Vec<Bytes>,
_: &Option<i64>,
) -> Result<Self, Self::Error> {
upwrap_array(v);
serde_json::from_value(v.clone()).map(Data)
crate::value::de::from_value::<T>(v.clone(), b).map(Data)
}
}

Expand Down
2 changes: 2 additions & 0 deletions socketioxide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,13 @@ pub use engineioxide::TransportType;
pub use errors::{AckError, AdapterError, BroadcastError, DisconnectError, SendError, SocketError};
pub use handler::extract;
pub use io::{SocketIo, SocketIoBuilder, SocketIoConfig};
pub use value::{de::from_value, ser::to_value};

mod client;
mod errors;
mod io;
mod ns;
mod value;

/// Socket.IO protocol version.
/// It is accessible with the [`Socket::protocol`](socket::Socket) method or as an extractor
Expand Down
Loading

0 comments on commit 3a795d1

Please sign in to comment.