|
1 | 1 | use anyhow::Result; |
2 | | -use epoxy_protocol::protocol; |
| 2 | +use epoxy_protocol::{PROTOCOL_VERSION, protocol, versioned}; |
3 | 3 | use serde::{Deserialize, Serialize}; |
4 | 4 | use universaldb::prelude::*; |
5 | 5 | use universaldb::tuple::Versionstamp; |
6 | | - |
7 | | -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] |
8 | | -pub struct CommittedValue { |
9 | | - // NOTE: An empty value may exist for cached entries to denote the value was not found on any datacenter |
10 | | - // and cached as such. |
11 | | - pub value: Vec<u8>, |
12 | | - pub version: u64, |
13 | | - pub mutable: bool, |
14 | | -} |
| 6 | +use vbare::OwnedVersionedData; |
15 | 7 |
|
16 | 8 | /// In-flight accepted proposal state stored under `kv/{key}/accepted`. |
17 | 9 | /// |
@@ -44,14 +36,15 @@ impl KvValueKey { |
44 | 36 | } |
45 | 37 |
|
46 | 38 | impl FormalKey for KvValueKey { |
47 | | - type Value = CommittedValue; |
| 39 | + type Value = protocol::CommittedValue; |
48 | 40 |
|
49 | 41 | fn deserialize(&self, raw: &[u8]) -> Result<Self::Value> { |
50 | | - serde_bare::from_slice(raw).map_err(Into::into) |
| 42 | + versioned::CommittedValue::deserialize_with_embedded_version(raw) |
51 | 43 | } |
52 | 44 |
|
53 | 45 | fn serialize(&self, value: Self::Value) -> Result<Vec<u8>> { |
54 | | - serde_bare::to_vec(&value).map_err(Into::into) |
| 46 | + versioned::CommittedValue::wrap_latest(value) |
| 47 | + .serialize_with_embedded_version(PROTOCOL_VERSION) |
55 | 48 | } |
56 | 49 | } |
57 | 50 |
|
@@ -260,14 +253,14 @@ impl KvOptimisticCacheKey { |
260 | 253 | } |
261 | 254 |
|
262 | 255 | impl FormalKey for KvOptimisticCacheKey { |
263 | | - type Value = CommittedValue; |
| 256 | + type Value = protocol::CachedValue; |
264 | 257 |
|
265 | 258 | fn deserialize(&self, raw: &[u8]) -> Result<Self::Value> { |
266 | | - serde_bare::from_slice(raw).map_err(Into::into) |
| 259 | + versioned::CachedValue::deserialize_with_embedded_version(raw) |
267 | 260 | } |
268 | 261 |
|
269 | 262 | fn serialize(&self, value: Self::Value) -> Result<Vec<u8>> { |
270 | | - serde_bare::to_vec(&value).map_err(Into::into) |
| 263 | + versioned::CachedValue::wrap_latest(value).serialize_with_embedded_version(PROTOCOL_VERSION) |
271 | 264 | } |
272 | 265 | } |
273 | 266 |
|
|
0 commit comments