Skip to content

Commit a5f357b

Browse files
committed
refactor
1 parent ca65f5a commit a5f357b

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ rustc-hash = "2.0.0"
3333
serde = { version = "1.0.215", optional = true, features = ["derive"] }
3434
tempfile = "3.12.0"
3535
xxhash-rust = { version = "0.8.12", features = ["xxh3"] }
36+
varint-rs = "2.2.0"
3637

3738
[dev-dependencies]
3839
criterion = "0.5.1"

src/coding.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub enum DecodeError {
4343
/// I/O error
4444
Io(std::io::Error),
4545

46+
InvalidVersion,
47+
4648
/// Invalid enum tag
4749
InvalidTag((&'static str, u8)),
4850

@@ -87,10 +89,10 @@ pub trait Encode {
8789

8890
/// Serializes into vector.
8991
#[allow(unused)]
90-
fn encode_into_vec(&self) -> Result<Vec<u8>, EncodeError> {
92+
fn encode_into_vec(&self) -> Vec<u8> {
9193
let mut v = vec![];
92-
self.encode_into(&mut v)?;
93-
Ok(v)
94+
self.encode_into(&mut v).expect("cannot fail");
95+
v
9496
}
9597
}
9698

src/handle.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
// This source code is licensed under both the Apache 2.0 and MIT License
33
// (found in the LICENSE-* files in the repository)
44

5-
use crate::id::SegmentId;
6-
use std::hash::Hash;
5+
use crate::{
6+
coding::{Decode, DecodeError, Encode, EncodeError},
7+
id::SegmentId,
8+
};
9+
use std::{
10+
hash::Hash,
11+
io::{Read, Write},
12+
};
13+
use varint_rs::{VarintReader, VarintWriter};
714

815
/// A value handle points into the value log
916
#[allow(clippy::module_name_repetitions)]
@@ -16,3 +23,19 @@ pub struct ValueHandle {
1623
/// Offset in file
1724
pub offset: u64,
1825
}
26+
27+
impl Encode for ValueHandle {
28+
fn encode_into<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
29+
writer.write_u64_varint(self.offset)?;
30+
writer.write_u64_varint(self.segment_id)?;
31+
Ok(())
32+
}
33+
}
34+
35+
impl Decode for ValueHandle {
36+
fn decode_from<R: Read>(reader: &mut R) -> Result<Self, DecodeError> {
37+
let offset = reader.read_u64_varint()?;
38+
let segment_id = reader.read_u64_varint()?;
39+
Ok(Self { segment_id, offset })
40+
}
41+
}

src/key_range.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::{
1414

1515
/// A key range in the format of [min, max] (inclusive on both sides)
1616
#[derive(Clone, Debug, PartialEq, Eq)]
17+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1718
pub struct KeyRange(UserKey, UserKey);
1819

1920
impl std::fmt::Display for KeyRange {

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@
103103
#![cfg_attr(not(feature = "bytes"), forbid(unsafe_code))]
104104

105105
mod blob_cache;
106-
mod coding;
106+
107+
#[doc(hidden)]
108+
pub mod coding;
109+
107110
mod compression;
108111
mod config;
109112
mod error;

0 commit comments

Comments
 (0)