Skip to content

Commit d1e30f6

Browse files
committed
feat(socketioxide): wip: unify non-binary and binary data
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. Closes #276.
1 parent b7e5e24 commit d1e30f6

File tree

5 files changed

+1570
-2
lines changed

5 files changed

+1570
-2
lines changed

socketioxide/src/handler/extract.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ where
140140
fn from_message_parts(
141141
_: &Arc<Socket<A>>,
142142
v: &mut serde_json::Value,
143-
_: &mut Vec<Bytes>,
143+
b: &mut Vec<Bytes>,
144144
_: &Option<i64>,
145145
) -> Result<Self, Self::Error> {
146146
upwrap_array(v);
147-
serde_json::from_value(v.clone()).map(Data)
147+
crate::value::de::from_value::<T>(v.clone(), b).map(Data)
148148
}
149149
}
150150

socketioxide/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,13 @@ pub use engineioxide::TransportType;
275275
pub use errors::{AckError, AdapterError, BroadcastError, DisconnectError, SendError, SocketError};
276276
pub use handler::extract;
277277
pub use io::{SocketIo, SocketIoBuilder, SocketIoConfig};
278+
pub use value::{de::from_value, ser::to_value};
278279

279280
mod client;
280281
mod errors;
281282
mod io;
282283
mod ns;
284+
mod value;
283285

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

0 commit comments

Comments
 (0)