Skip to content
This repository was archived by the owner on Aug 15, 2021. It is now read-only.

Commit 5f3fa08

Browse files
committed
Fix roundtrip of f64 field.
1 parent 848b811 commit 5f3fa08

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

src/de.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,11 @@ where
732732
0xf8 => Err(self.error(ErrorCode::UnassignedCode)),
733733
0xf9 => {
734734
let value = self.parse_f16()?;
735-
visitor.visit_f32(value)
735+
visitor.visit_f64(value as f64)
736736
}
737737
0xfa => {
738738
let value = self.parse_f32()?;
739-
visitor.visit_f32(value)
739+
visitor.visit_f64(value as f64)
740740
}
741741
0xfb => {
742742
let value = self.parse_f64()?;

tests/roundtrip.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
extern crate serde_derive;
33

44
use serde_cbor;
5-
use serde_cbor::de;
65

76
#[derive(Serialize, Deserialize, Debug, PartialEq)]
87
struct MyStuff {
@@ -12,19 +11,15 @@ struct MyStuff {
1211

1312
#[derive(Serialize, Deserialize, Debug, PartialEq)]
1413
enum MyStuffType {
15-
ver1 {
16-
x: f64,
17-
},
18-
ver2
14+
Ver1 { x: f64, y: f32 },
15+
Ver2,
1916
}
2017

2118
#[test]
2219
/// Test roundtrip operation on a serde data structure.
2320
fn test_roundtrip() {
2421
let stuff1 = MyStuff {
25-
data: MyStuffType::ver1 {
26-
x: 2.5
27-
}
22+
data: MyStuffType::Ver1 { x: 2.5, y: 2.5 },
2823
};
2924
let data_bytes = serde_cbor::to_vec(&stuff1).unwrap();
3025
let stuff2 = serde_cbor::from_slice(&data_bytes).unwrap();

0 commit comments

Comments
 (0)