Skip to content

Commit

Permalink
bump dmds to 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
JieningYu committed Dec 20, 2023
1 parent a177c03 commit a8f43a1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 32 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
37 changes: 21 additions & 16 deletions src/paper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl From<In> for Paper {

impl dmds::Data for Paper {
const DIMS: usize = 2;
const VERSION: u32 = 1;

#[inline]
fn dim(&self, dim: usize) -> u64 {
Expand All @@ -118,22 +119,26 @@ impl dmds::Data for Paper {
}
}

fn decode<B: bytes::Buf>(dims: &[u64], buf: B) -> std::io::Result<Self> {
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<B: bytes::Buf>(version: u32, dims: &[u64], buf: B) -> std::io::Result<Self> {
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<B: bytes::BufMut>(&self, buf: B) -> std::io::Result<()> {
Expand Down
26 changes: 16 additions & 10 deletions src/question.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ impl From<In> for Question {

impl dmds::Data for Question {
const DIMS: usize = 1;
const VERSION: u32 = 1;

fn dim(&self, dim: usize) -> u64 {
match dim {
Expand All @@ -78,16 +79,21 @@ impl dmds::Data for Question {
}
}

fn decode<B: bytes::Buf>(dims: &[u64], buf: B) -> std::io::Result<Self> {
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<B: bytes::Buf>(version: u32, dims: &[u64], buf: B) -> std::io::Result<Self> {
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<B: bytes::BufMut>(&self, buf: B) -> std::io::Result<()> {
Expand Down

0 comments on commit a8f43a1

Please sign in to comment.