Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upCan bincode be used to serialize and deserialize data which is meant to be sent and received using a socket? #257
Comments
|
The issue is not in those functions that I shared above. I have several structs that depend on the same |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm trying to send several types using sockets. So, to encode these several types, I am using bincode in conjunction with serde. I'm using rustc 1.30.1, bincode 1.0, serde_derive 1.0 and serde = 1.0.
The function I am using to send data using a socket can be found here. As you can see, I am actually trying to send a
Msg<T>, whereMsgis an enum, which contains a value that I want to send of typeT. You can see the definition of the enum here.The function I am using to receive data from the socket can be found here. As you can see, I am also trying to return a
Msg<T>from this function.Now, the problem is the following. If
Tis af32, e.g. say 2.0, I am actually receiving 1073741824 inside the field of the enum value, in the receiving function. I have checked using the following code:And, apparently, 1073741824 is the unsigned representation of 2.0. If I do the same with a
char, that is, ifTis achar, e.g.'a', I receive 97, which, again, after checking it withunsafe { std::mem::transmute::<u32, char>(97) }, is the unsigned representation of'a'.Btw, I have the following bounds on
T, in theimplof the generic struct overT:T: Serialize + DeserializeOwned + Copy + Clone + Debug.Questions
So, what's the problem with my code above? How can I receive a float and a char from a socket using bincode and serde?
Furthermore, if
Tis a tuple, say,(2, 1), I only receive the first element of the tuple, i.e. 2. So, what's going on here? How can I receive any type that has the boundsT: Serialize + DeserializeOwned + Copy + Clone + Debug?Notes
Note: I am able to receive u32, i32 and usize values correctly.
Summary of the problems
Comments
Entity, it still works as expected. So, the problem may be related to the usage of sockets to send and receive data?