-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 유연함을 위해 encoding / decoding 동작 분리
- Loading branch information
1 parent
6674a34
commit 2b6d3a7
Showing
3 changed files
with
81 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use crate::errors::{predule::WALError, RRDBError}; | ||
|
||
use super::types::WALEntry; | ||
|
||
pub trait WALEncoder<T>: Clone { | ||
fn encode(&self, entry: &T) -> Result<Vec<u8>, RRDBError>; | ||
} | ||
|
||
pub trait WALDecoder<T>: Clone { | ||
fn decode(&self, data: &[u8]) -> Result<T, RRDBError>; | ||
} | ||
|
||
|
||
#[derive(Clone)] | ||
pub struct WALEncodeImpl {} | ||
|
||
impl WALEncoder<Vec<WALEntry>> for WALEncodeImpl { | ||
fn encode(&self, entry: &Vec<WALEntry>) -> Result<Vec<u8>, RRDBError> { | ||
Ok(bitcode::encode(entry)) | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct WALDecodeImpl {} | ||
|
||
impl WALDecoder<Vec<WALEntry>> for WALDecodeImpl { | ||
fn decode(&self, data: &[u8]) -> Result<Vec<WALEntry>, RRDBError> { | ||
Ok(bitcode::decode(data).map_err(|e| WALError::wrap(e.to_string()))?) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod manager; | ||
pub mod types; | ||
pub mod types; | ||
pub mod endec; |