2019-10-03 22:54:37 +08:00
|
|
|
use rkv::Value;
|
2019-10-03 23:33:15 +08:00
|
|
|
use crate::{update::UpdateResult, MResult};
|
2019-10-03 22:13:09 +08:00
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
pub struct UpdatesResults {
|
|
|
|
pub(crate) updates_results: rkv::SingleStore,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UpdatesResults {
|
|
|
|
pub fn put_update_result(
|
|
|
|
&self,
|
|
|
|
writer: &mut rkv::Writer,
|
|
|
|
update_id: u64,
|
|
|
|
update_result: &UpdateResult,
|
2019-10-03 23:33:15 +08:00
|
|
|
) -> MResult<()>
|
2019-10-03 22:13:09 +08:00
|
|
|
{
|
2019-10-03 22:54:37 +08:00
|
|
|
let update_id_bytes = update_id.to_be_bytes();
|
2019-10-03 23:33:15 +08:00
|
|
|
let update_result = bincode::serialize(&update_result)?;
|
2019-10-03 22:54:37 +08:00
|
|
|
let blob = Value::Blob(&update_result);
|
2019-10-03 23:33:15 +08:00
|
|
|
self.updates_results.put(writer, update_id_bytes, &blob)?;
|
|
|
|
Ok(())
|
2019-10-03 22:13:09 +08:00
|
|
|
}
|
|
|
|
|
2019-10-04 16:21:09 +08:00
|
|
|
pub fn update_result(
|
2019-10-03 22:54:37 +08:00
|
|
|
&self,
|
2019-10-04 16:21:09 +08:00
|
|
|
reader: &impl rkv::Readable,
|
2019-10-03 22:13:09 +08:00
|
|
|
update_id: u64,
|
2019-10-03 23:33:15 +08:00
|
|
|
) -> MResult<Option<UpdateResult>>
|
2019-10-03 22:13:09 +08:00
|
|
|
{
|
2019-10-03 22:54:37 +08:00
|
|
|
let update_id_bytes = update_id.to_be_bytes();
|
|
|
|
|
|
|
|
match self.updates_results.get(reader, update_id_bytes)? {
|
|
|
|
Some(Value::Blob(bytes)) => {
|
2019-10-03 23:33:15 +08:00
|
|
|
let update_result = bincode::deserialize(&bytes)?;
|
2019-10-03 22:54:37 +08:00
|
|
|
Ok(Some(update_result))
|
|
|
|
},
|
|
|
|
Some(value) => panic!("invalid type {:?}", value),
|
|
|
|
None => Ok(None),
|
|
|
|
}
|
2019-10-03 22:13:09 +08:00
|
|
|
}
|
|
|
|
}
|