From a8f43a16800e76c444189bf94cd5c021c1cbd789 Mon Sep 17 00:00:00 2001 From: Yjn024 <61787533+JieningYu@users.noreply.github.com> Date: Wed, 20 Dec 2023 21:56:53 +0800 Subject: [PATCH] bump dmds to 0.2 --- Cargo.lock | 8 ++++---- Cargo.toml | 4 ++-- src/paper.rs | 37 +++++++++++++++++++++---------------- src/question.rs | 26 ++++++++++++++++---------- 4 files changed, 43 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1a3fb24..dec87bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -252,9 +252,9 @@ dependencies = [ [[package]] name = "dmds" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4af1766a337392440cba2e9716800e411acba9f3790fad295108407b91f861a8" +checksum = "765f1f13a4c262d59979ed04d24790a7776be4854f5b0e8cc169ba1dac53a13e" dependencies = [ "async-lock", "async-trait", @@ -266,9 +266,9 @@ dependencies = [ [[package]] name = "dmds-tokio-fs" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "981ca5a3128aac81d7ee7449735330079602a4f04d63793b5eb97d56b597f6ec" +checksum = "dd8ed854a5d73c95b951344d433f0ba3f04f0c41a550e44cf401e815c68cca8f" dependencies = [ "async-trait", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 2b105ef..b315f53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,8 +7,8 @@ edition = "2021" [dependencies] axum = "0.7" -dmds = "0.1" -dmds-tokio-fs = "0.1" +dmds = "0.2" +dmds-tokio-fs = "0.2" tokio = { version = "1.35", features = ["full"] } tracing = "0.1" tracing-subscriber = "0.3" diff --git a/src/paper.rs b/src/paper.rs index a64613d..02a3fcd 100644 --- a/src/paper.rs +++ b/src/paper.rs @@ -108,6 +108,7 @@ impl From for Paper { impl dmds::Data for Paper { const DIMS: usize = 2; + const VERSION: u32 = 1; #[inline] fn dim(&self, dim: usize) -> u64 { @@ -118,22 +119,26 @@ impl dmds::Data for Paper { } } - fn decode(dims: &[u64], buf: B) -> std::io::Result { - let inner: Store = bincode::deserialize_from(buf.reader()) - .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?; - - Ok(Self { - name: inner.name, - info: inner.info, - email: inner.email, - time: inner.time, - pid: dims[0], - status: if dims[1] as u8 == Status::Pending as u8 { - Status::Pending - } else { - Status::Approved - }, - }) + fn decode(version: u32, dims: &[u64], buf: B) -> std::io::Result { + match version { + 1 => { + let inner: Store = bincode::deserialize_from(buf.reader()) + .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?; + Ok(Self { + name: inner.name, + info: inner.info, + email: inner.email, + time: inner.time, + pid: dims[0], + status: if dims[1] as u8 == Status::Pending as u8 { + Status::Pending + } else { + Status::Approved + }, + }) + } + _ => unreachable!(), + } } fn encode(&self, buf: B) -> std::io::Result<()> { diff --git a/src/question.rs b/src/question.rs index 0da2357..320cc81 100644 --- a/src/question.rs +++ b/src/question.rs @@ -70,6 +70,7 @@ impl From for Question { impl dmds::Data for Question { const DIMS: usize = 1; + const VERSION: u32 = 1; fn dim(&self, dim: usize) -> u64 { match dim { @@ -78,16 +79,21 @@ impl dmds::Data for Question { } } - fn decode(dims: &[u64], buf: B) -> std::io::Result { - let inner: Store = bincode::deserialize_from(buf.reader()) - .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?; - Ok(Self { - name: inner.name, - info: inner.info, - email: inner.email, - pid: dims[0], - time: inner.time, - }) + fn decode(version: u32, dims: &[u64], buf: B) -> std::io::Result { + match version { + 1 => { + let inner: Store = bincode::deserialize_from(buf.reader()) + .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?; + Ok(Self { + name: inner.name, + info: inner.info, + email: inner.email, + pid: dims[0], + time: inner.time, + }) + } + _ => unreachable!(), + } } fn encode(&self, buf: B) -> std::io::Result<()> {