-
Notifications
You must be signed in to change notification settings - Fork 99
Add roundtrip example test case. #169
base: master
Are you sure you want to change the base?
Conversation
Btw, I tried let txt = serde_json::to_string(&stuff1).unwrap();
let stuff2 = serde_json::from_str(&txt).unwrap(); |
This is an instance of #144 Basically don't use |
Any clue yet on how this should be fixed? I'm not into serde, so I do not yet grasp how it should work. Also, the issue is more about the enum tag being improperly handled right? In this example, it's a field inside the flattened enum which behaves weird. Should this be fixed in serde_cbor, or in serde itself? |
No, no idea. That it works with |
I found a solution to this issue. The solution was to always visit the f64 variant, since the cbor encoding is smart, and tries to use a compact value as possible, depending on the bits of the floating point number. This deserialization now starts to visit the f64 case (most bits), this will work onto f32 as well. Please have a look at this, whether this makes sense or not. |
Code fails to compile because of warnings. I am not sure that this change will work as some code actually needs a f32 and not a f64. I recall that there was a similar issue in the past but I can't find the id right now. |
I added a field in the roundtrip test case with of type f32 to test this. Is there a sort of stress test for rountripping all serde types available? |
Excuse me for the many commits, please squash merge if merging this work. |
@pyfisch what do you think about this change? Is it good / bad? I had some second thoughts about the packing / unpacking logic of floating point values. I noticed that if a I think this probably is counter intuitive in one of the following ways:
|
@windelbouwman Isn't using this patch use |
@pickfire I do not understand what you mean. Is there a |
That is in another pull request #103 like I mentioned. |
@pyfisch what do you think of this change? Does it make sense? |
As discussed in #179 serde-cbor will be rewritten and I don't want to maintain it in the future. Therefore I am no longer reviewing patches for new features and minor bugs. While this change fixes the problem you encounter other users may depend on an f32 and their code would be broken (I think). |
Okay, thanks for the heads up! |
Hi, I was wondering whether this testcase should work or not? What am I doing wrong in this case, or is this a bug?
The error message seems to indicate that we got a floating point, but we wanted a f64 value, this must be possible right?
This example serializes a data structure, and then again de-serializes the structure.