Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a9a6a98

Browse files
committed
addressing PR comments
1 parent a2430bc commit a9a6a98

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/binary/rkyv.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use rkyv::api::high::{HighSerializer, HighValidator};
33
use rkyv::de::Pool;
44
use rkyv::rancor::Strategy;
55
use rkyv::ser::allocator::ArenaHandle;
6+
pub use rkyv::util::AlignedVec;
67
use rkyv::{bytecheck, rancor, Archive, Deserialize, Serialize};
78
use std::error::Error;
89
use std::sync::Arc;
9-
pub use rkyv::util::AlignedVec;
1010

1111
/// A codec that relies on `rkyv` to encode data in the msgpack format.
1212
///
@@ -15,13 +15,13 @@ pub struct RkyvCodec;
1515

1616
impl<T> Encoder<T> for RkyvCodec
1717
where
18-
T: for<'a> Serialize<HighSerializer<AlignedVec, ArenaHandle<'a>, rancor::Error>>,
18+
T: for<'a> Serialize<HighSerializer<Vec<u8>, ArenaHandle<'a>, rancor::Error>>,
1919
{
2020
type Error = rancor::Error;
21-
type Encoded = AlignedVec;
21+
type Encoded = Vec<u8>;
2222

2323
fn encode(val: &T) -> Result<Self::Encoded, Self::Error> {
24-
rkyv::api::high::to_bytes_in(val, AlignedVec::new())
24+
rkyv::api::high::to_bytes_in(val, Vec::new())
2525
}
2626
}
2727

@@ -33,16 +33,17 @@ where
3333
+ Deserialize<T, Strategy<Pool, rancor::Error>>,
3434
{
3535
type Error = Arc<dyn Error>;
36-
type Encoded = AlignedVec;
36+
type Encoded = [u8];
3737

3838
fn decode(val: &Self::Encoded) -> Result<T, Self::Error> {
39-
rkyv::from_bytes::<T, rancor::Error>(val).map_err(|e| Arc::new(e) as Arc<dyn Error>)
39+
let mut aligned = AlignedVec::<16>::with_capacity(val.len());
40+
aligned.extend_from_slice(val);
41+
rkyv::from_bytes::<T, rancor::Error>(&aligned).map_err(|e| Arc::new(e) as Arc<dyn Error>)
4042
}
4143
}
4244

4345
#[cfg(test)]
4446
mod tests {
45-
use rkyv::util::AlignedVec;
4647
use super::*;
4748

4849
#[test]

0 commit comments

Comments
 (0)