Skip to content

Commit 2976ced

Browse files
author
Drew Robinson
committed
Simplify Value deserialization by removing intermediate type
Add SchemaRead derive directly to Value enum and deserialize without the unnecessary WincodeValue intermediate. This reduces code by ~18 lines and makes the implementation more idiomatic.
1 parent 5faa078 commit 2976ced

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

libsql/src/value.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use crate::{Error, Result};
44

55
#[derive(Clone, Debug, PartialEq)]
66
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
7-
#[cfg_attr(feature = "replication", derive(wincode::SchemaWrite))]
7+
#[cfg_attr(
8+
feature = "replication",
9+
derive(wincode::SchemaWrite, wincode::SchemaRead)
10+
)]
811
pub enum Value {
912
Null,
1013
Integer(i64),
@@ -450,24 +453,7 @@ impl TryFrom<&libsql_replication::rpc::proxy::Value> for Value {
450453
type Error = Error;
451454

452455
fn try_from(value: &libsql_replication::rpc::proxy::Value) -> Result<Self> {
453-
#[derive(wincode::SchemaRead)]
454-
pub enum WincodeValue {
455-
Null,
456-
Integer(i64),
457-
Real(f64),
458-
Text(String),
459-
Blob(Vec<u8>),
460-
}
461-
462-
Ok(
463-
match wincode::deserialize::<'_, WincodeValue>(&value.data[..]).map_err(Error::from)? {
464-
WincodeValue::Null => Value::Null,
465-
WincodeValue::Integer(i) => Value::Integer(i),
466-
WincodeValue::Real(x) => Value::Real(x),
467-
WincodeValue::Text(s) => Value::Text(s),
468-
WincodeValue::Blob(b) => Value::Blob(b),
469-
},
470-
)
456+
wincode::deserialize(&value.data[..]).map_err(Error::from)
471457
}
472458
}
473459

0 commit comments

Comments
 (0)