Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full deserialization for range #432

Merged
merged 62 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
4e79054
Remove obsolete iterator feature attr
maurolacy Sep 19, 2021
49e0ece
Add key deserialization to range
maurolacy Sep 16, 2021
6bfb659
Add (Owned) Deserializable trait
maurolacy Sep 17, 2021
7b63bcc
Use our Deserializable trait
maurolacy Sep 17, 2021
4f94644
Add range2 working example / test
maurolacy Sep 17, 2021
6007000
Add String deserialization
maurolacy Sep 17, 2021
70cde49
Implement integer types deserialization
maurolacy Sep 17, 2021
188d637
Rename for consistency
maurolacy Sep 18, 2021
cebd2bb
Implement 2-tuple deserialization
maurolacy Sep 18, 2021
7a1965e
Use NoPrefix for EmptyPrefix marker in Map (range2 too)
maurolacy Sep 18, 2021
8496f98
Implement 3-tuple deserialization
maurolacy Sep 18, 2021
a6dda5e
Implement bytes deserialization
maurolacy Sep 18, 2021
5b417a3
Rename deserialization functions / types for clarity
maurolacy Sep 18, 2021
a957667
Rename range2 to range_de
maurolacy Sep 18, 2021
f2c4ee2
Rename prefix2 to prefix_de
maurolacy Sep 18, 2021
aa205d6
Add full range over composite unit test
maurolacy Sep 18, 2021
b2d6711
Implement keys_de
maurolacy Sep 19, 2021
bb29bad
Fix rebase errors
maurolacy Sep 19, 2021
a2ca62c
Simplify no_prefix_de
maurolacy Sep 19, 2021
dcee286
Revert "Remove obsolete iterator feature attr"
maurolacy Sep 19, 2021
965b6cb
Add iterator feature to new map functionality
maurolacy Sep 19, 2021
af5716f
Implement keys_de
maurolacy Sep 19, 2021
a630143
Fix rebase error
maurolacy Sep 22, 2021
4952e49
Fix rebase errors
maurolacy Sep 23, 2021
257860e
Remove obsolete iterator feature attr
maurolacy Sep 19, 2021
c66a3e7
Add iterator feature to new map functionality
maurolacy Sep 19, 2021
da84d93
Remove obsolete iterator feature attr
maurolacy Sep 19, 2021
0738a97
Add PrimaryKey associated Suffix type
maurolacy Sep 18, 2021
cf483cc
Use Suffix for Map prefix_de
maurolacy Sep 18, 2021
f32ebe7
Add PrimaryKey associated SuperSuffix type
maurolacy Sep 18, 2021
1b8fd59
Satisfy new key trait bounds
maurolacy Sep 18, 2021
6868f38
Use SuperSuffix for Map sub_prefix_de
maurolacy Sep 18, 2021
f5e878e
Remove FIXME
maurolacy Sep 18, 2021
d795053
Add a couple more sub_/prefix_de tests
maurolacy Sep 18, 2021
e2b5eaa
Fix rebase error
maurolacy Sep 19, 2021
cb92ab0
Revert "Remove obsolete iterator feature attr"
maurolacy Sep 19, 2021
c03cdea
Add iterator feature to new map functionality
maurolacy Sep 19, 2021
e7adc00
Remove obsolete iterator feature attr
maurolacy Sep 19, 2021
e8dd404
Consolidate Prefix and Prefix2 functionality
maurolacy Sep 19, 2021
172082b
Use "natural" <K, V> order for Prefix
maurolacy Sep 23, 2021
c45680d
Fix rebase errors (iterator feature attr)
maurolacy Sep 24, 2021
b43a9cc
Get rid of Pair2 entirely
maurolacy Sep 27, 2021
e52886f
Merge branch '198-better-range-prefix' into 198-prefix-consolidation
maurolacy Sep 27, 2021
f002af9
Rename Deserializable to KeyDeserialize
maurolacy Sep 30, 2021
eb97b51
Change K::Output lifetime to 'static
maurolacy Sep 30, 2021
e08ef08
Merge branch 'main' into 198-better-range-prefix
maurolacy Sep 30, 2021
c614ac4
Remove FIXME?
maurolacy Sep 30, 2021
d682a65
Forward impls instead of macros for byte and str types
maurolacy Sep 30, 2021
b760639
Use split_at instead of slice ranges
maurolacy Sep 30, 2021
312cbb8
Reorganize imports
maurolacy Sep 30, 2021
f56f0d6
Merge branch '198-better-range-prefix' into 198-prefix-consolidation
maurolacy Sep 30, 2021
a95f9ca
Merge pull request #439 from CosmWasm/198-prefix-consolidation
maurolacy Sep 30, 2021
af447a0
Add `PrimaryKey` doc-comment
maurolacy Sep 30, 2021
10362c0
Remove unused / useless `KeyDeserialize` impls
maurolacy Oct 1, 2021
09485f5
Change Addr deserialization output type
maurolacy Oct 1, 2021
c721f96
Remove useless defaults
maurolacy Oct 1, 2021
ef27b6e
Add corresponding prefix_range_de
maurolacy Oct 1, 2021
03389ef
Add doc-comments for `PrimaryKey` associated types
maurolacy Oct 1, 2021
168eed7
Fix iterator feature imports
maurolacy Oct 1, 2021
f67cf15
Merge branch 'main' into 198-better-range-prefix
maurolacy Oct 4, 2021
9b68a4c
Add key deserialization unit tests
maurolacy Oct 4, 2021
4dd9b74
Merge branch 'main' into 198-better-range-prefix
maurolacy Oct 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement 2-tuple deserialization
  • Loading branch information
maurolacy committed Sep 24, 2021
commit cebd2bbd657455bfe7656dccb8b22b5d957b35d4
21 changes: 20 additions & 1 deletion packages/storage-plus/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,29 @@ macro_rules! integer_de {
type Output = $t;

fn from_slice(value: &[u8]) -> StdResult<Self::Output> {
Ok(<$t>::from_be_bytes(value.try_into().map_err(|err: TryFromSliceError| StdError::generic_err(err.to_string()))?))
Ok(<$t>::from_be_bytes(value.try_into()
maurolacy marked this conversation as resolved.
Show resolved Hide resolved
// FIXME: Add and use StdError try-from error From helper
.map_err(|err: TryFromSliceError| StdError::generic_err(err.to_string()))?))
}
})*
}
}

integer_de!(for i8, u8, i16, u16, i32, u32, i64, u64, i128, u128);

impl<T: Deserializable, U: Deserializable> Deserializable for (T, U) {
type Output = (T::Output, U::Output);

fn from_slice(value: &[u8]) -> StdResult<Self::Output> {
let t_len = u16::from_be_bytes(
value[..2]
.try_into()
// FIXME: Add and use StdError try-from error From helper
.map_err(|err: TryFromSliceError| StdError::generic_err(err.to_string()))?,
) as usize;
let t = T::from_slice(&value[2..2 + t_len])?;
maurolacy marked this conversation as resolved.
Show resolved Hide resolved
let u = U::from_slice(&value[2 + t_len..])?;
maurolacy marked this conversation as resolved.
Show resolved Hide resolved

Ok((t, u))
}
}
33 changes: 33 additions & 0 deletions packages/storage-plus/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,39 @@ mod test {
}

#[test]
#[cfg(feature = "iterator")]
fn range2_composite_key() {
let mut store = MockStorage::new();

// save and load on three keys, one under different owner
ALLOWANCE
.save(&mut store, (b"owner", b"spender"), &1000)
.unwrap();
ALLOWANCE
.save(&mut store, (b"owner", b"spender2"), &3000)
.unwrap();
ALLOWANCE
.save(&mut store, (b"owner2", b"spender"), &5000)
.unwrap();

// let's try to iterate!
let all: StdResult<Vec<_>> = ALLOWANCE
.range2(&store, None, None, Order::Ascending)
.collect();
let all = all.unwrap();
assert_eq!(3, all.len());
assert_eq!(
all,
vec![
(("owner".to_string(), "spender".to_string()), 1000),
(("owner".to_string(), "spender2".to_string()), 3000),
(("owner2".to_string(), "spender".to_string()), 5000)
]
);
}

#[test]
#[cfg(feature = "iterator")]
fn range_triple_key() {
let mut store = MockStorage::new();

Expand Down