-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use stored state for apply-pending-commit (#229)
* Use stored state for apply-pending-commit * Bump version * Make serialization of Sanapshot backwards compatible * Fixup * Fixup * Make snapshot backwards compatible * Fixup * Fixup * Fixup --------- Co-authored-by: Marta Mularczyk <[email protected]> Co-authored-by: Tom Leavy <[email protected]>
- Loading branch information
1 parent
158a9d3
commit 66d6717
Showing
17 changed files
with
562 additions
and
188 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
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,45 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// Copyright by contributors to this project. | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
|
||
use crate::{MlsDecode, MlsEncode, MlsSize}; | ||
use alloc::vec::Vec; | ||
|
||
impl MlsSize for bool { | ||
fn mls_encoded_len(&self) -> usize { | ||
1 | ||
} | ||
} | ||
|
||
impl MlsEncode for bool { | ||
fn mls_encode(&self, writer: &mut Vec<u8>) -> Result<(), crate::Error> { | ||
writer.push(*self as u8); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl MlsDecode for bool { | ||
fn mls_decode(reader: &mut &[u8]) -> Result<Self, crate::Error> { | ||
MlsDecode::mls_decode(reader).map(|i: u8| i != 0) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
#[cfg(target_arch = "wasm32")] | ||
use wasm_bindgen_test::wasm_bindgen_test as test; | ||
|
||
use crate::{MlsDecode, MlsEncode}; | ||
|
||
use alloc::vec; | ||
|
||
#[test] | ||
fn round_trip() { | ||
assert_eq!(false.mls_encode_to_vec().unwrap(), vec![0]); | ||
assert_eq!(true.mls_encode_to_vec().unwrap(), vec![1]); | ||
|
||
let vec = vec![true, true, false]; | ||
let bytes = vec.mls_encode_to_vec().unwrap(); | ||
assert_eq!(vec, Vec::mls_decode(&mut &*bytes).unwrap()) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ pub mod byte_vec; | |
|
||
pub mod iter; | ||
|
||
mod bool; | ||
mod cow; | ||
mod map; | ||
mod option; | ||
|
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
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
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
Oops, something went wrong.