Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
fix(binding):overflow of StoreUint64 trait, modify foo_ to inner_foo (#…
Browse files Browse the repository at this point in the history
…251)

* fix overflow of StoreUint64 trait, modify foo_ to inner_foo

* fix ci test

* fix inner_get inner_set io error

* modify all foo_ to inner_foo

* modify foo to safe_foo

* for test

* for test2
  • Loading branch information
cosinlink authored Apr 23, 2020
1 parent 42f0a3d commit 2eeb2ce
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 93 deletions.
12 changes: 6 additions & 6 deletions framework/src/binding/store/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<S: ServiceState, E: FixedCodec> DefaultStoreArray<S, E> {
}
}

fn get_(&self, index: u32) -> ProtocolResult<Option<E>> {
fn inner_get(&self, index: u32) -> ProtocolResult<Option<E>> {
if let Some(k) = self.keys.inner.get(index as usize) {
self.state.borrow().get(k)?.map_or_else(
|| {
Expand All @@ -58,7 +58,7 @@ impl<S: ServiceState, E: FixedCodec> DefaultStoreArray<S, E> {

// TODO(@zhounan): Atomicity of insert(k, v) and insert self.keys to
// ServiceState is not guaranteed for now That must be settled soon after.
fn push_(&mut self, elm: E) -> ProtocolResult<()> {
fn inner_push(&mut self, elm: E) -> ProtocolResult<()> {
let key = Hash::digest(elm.encode_fixed()?);

self.keys.inner.push(key.clone());
Expand All @@ -71,7 +71,7 @@ impl<S: ServiceState, E: FixedCodec> DefaultStoreArray<S, E> {

// TODO(@zhounan): Atomicity of insert(k, v) and insert self.keys to
// ServiceState is not guaranteed for now That must be settled soon after.
fn remove_(&mut self, index: u32) -> ProtocolResult<()> {
fn inner_remove(&mut self, index: u32) -> ProtocolResult<()> {
let key = self.keys.inner.remove(index as usize);
self.state
.borrow_mut()
Expand All @@ -83,17 +83,17 @@ impl<S: ServiceState, E: FixedCodec> DefaultStoreArray<S, E> {

impl<S: ServiceState, E: FixedCodec> StoreArray<E> for DefaultStoreArray<S, E> {
fn get(&self, index: u32) -> Option<E> {
self.get_(index)
self.inner_get(index)
.unwrap_or_else(|e| panic!("StoreArray get value failed: {}", e))
}

fn push(&mut self, elm: E) {
self.push_(elm)
self.inner_push(elm)
.unwrap_or_else(|e| panic!("StoreArray push value failed: {}", e));
}

fn remove(&mut self, index: u32) {
self.remove_(index)
self.inner_remove(index)
.unwrap_or_else(|e| panic!("StoreArray remove value failed: {}", e));
}

Expand Down
14 changes: 7 additions & 7 deletions framework/src/binding/store/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<S: 'static + ServiceState, K: 'static + FixedCodec + PartialEq, V: 'static
Ok(Hash::digest(Bytes::from(name_bytes)))
}

fn get_(&self, key: &K) -> ProtocolResult<Option<V>> {
fn inner_get(&self, key: &K) -> ProtocolResult<Option<V>> {
if self.keys.inner.contains(key) {
let mk = self.get_map_key(key)?;
self.state.borrow().get(&mk)?.map_or_else(
Expand All @@ -69,7 +69,7 @@ impl<S: 'static + ServiceState, K: 'static + FixedCodec + PartialEq, V: 'static

// TODO(@zhounan): Atomicity of insert(k, v) and insert self.keys to
// ServiceState is not guaranteed for now That must be settled soon after.
fn insert_(&mut self, key: K, value: V) -> ProtocolResult<()> {
fn inner_insert(&mut self, key: K, value: V) -> ProtocolResult<()> {
let mk = self.get_map_key(&key)?;

if !self.contains(&key) {
Expand All @@ -84,9 +84,9 @@ impl<S: 'static + ServiceState, K: 'static + FixedCodec + PartialEq, V: 'static

// TODO(@zhounan): Atomicity of insert(k, v) and insert self.keys to
// ServiceState is not guaranteed for now That must be settled soon after.
fn remove_(&mut self, key: &K) -> ProtocolResult<Option<V>> {
fn inner_remove(&mut self, key: &K) -> ProtocolResult<Option<V>> {
if self.contains(key) {
let value: V = self.get_(key)?.expect("value should be existed");
let value: V = self.inner_get(key)?.expect("value should be existed");
self.keys.inner.remove_item(key);
self.state
.borrow_mut()
Expand All @@ -107,17 +107,17 @@ impl<S: 'static + ServiceState, K: 'static + FixedCodec + PartialEq, V: 'static
StoreMap<K, V> for DefaultStoreMap<S, K, V>
{
fn get(&self, key: &K) -> Option<V> {
self.get_(key)
self.inner_get(key)
.unwrap_or_else(|e| panic!("StoreMap get failed: {}", e))
}

fn insert(&mut self, key: K, value: V) {
self.insert_(key, value)
self.inner_insert(key, value)
.unwrap_or_else(|e| panic!("StoreMap insert failed: {}", e));
}

fn remove(&mut self, key: &K) -> Option<V> {
self.remove_(key)
self.inner_remove(key)
.unwrap_or_else(|e| panic!("StoreMap remove failed: {}", e))
}

Expand Down
Loading

0 comments on commit 2eeb2ce

Please sign in to comment.