Skip to content

Commit

Permalink
fix: Marker Deserialize & QueryExpr encode use bincode
Browse files Browse the repository at this point in the history
  • Loading branch information
bartliu827 authored and roseboy-liu committed Mar 16, 2023
1 parent 45a8638 commit 4e7cfef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion common/models/src/errors.rs
Expand Up @@ -41,7 +41,7 @@ pub enum Error {
))]
Internal { err: String },

#[snafu(display("Invalid query expr message: {}", err))]
#[snafu(display("IO operator: {}", err))]
IOErrors { err: String },

#[snafu(display("Failed to convert vec to string"))]
Expand Down
14 changes: 5 additions & 9 deletions common/models/src/predicate/domain.rs
Expand Up @@ -180,11 +180,7 @@ impl<'a> Deserialize<'a> for Marker {
where
D: serde::Deserializer<'a>,
{
let mark = deserializer.deserialize_struct(
"ValueEntry",
&["data_type", "value", "bound"],
MarkerVisitor,
)?;
let mark = MarkerSerialize::deserialize(deserializer)?;

Ok(mark.into())
}
Expand Down Expand Up @@ -1201,16 +1197,16 @@ pub struct QueryExpr {

impl QueryExpr {
pub fn encode(option: &QueryExpr) -> Result<Vec<u8>> {
let bytes = serde_json::to_vec(option).map_err(|err| Error::InvalidQueryExprMsg {
err: err.to_string(),
let bytes = bincode::serialize(option).map_err(|e| Error::InvalidQueryExprMsg {
err: format!("encode error {}", e),
})?;

Ok(bytes)
}

pub fn decode(buf: &[u8]) -> Result<QueryExpr> {
serde_json::from_slice::<QueryExpr>(buf).map_err(|err| Error::InvalidQueryExprMsg {
err: err.to_string(),
bincode::deserialize::<QueryExpr>(buf).map_err(|e| Error::InvalidQueryExprMsg {
err: format!("decode error {}", e),
})
}
}
Expand Down

0 comments on commit 4e7cfef

Please sign in to comment.