Skip to content

Commit

Permalink
feat: storage
Browse files Browse the repository at this point in the history
  • Loading branch information
rise0chen committed Nov 21, 2023
1 parent 7efa0ed commit fe3dcfc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,22 @@ pub mod lebai_sdk {
self.0.add_signal(index, value).await
}

// Storage
#[classmethod]
pub async fn set_item(&self, key: String, value: String) -> Result<()> {
self.0.set_item(key, value).await
}
#[classmethod]
#[cmod::tags(ret)]
pub async fn get_item(&self, key: String) -> Result<proto::lebai::storage::Item> {
self.0.get_item(key).await
}
#[classmethod]
#[cmod::tags(ret)]
pub async fn get_items(&self, prefix: String) -> Result<Vec<proto::lebai::storage::Item>> {
self.0.get_items(prefix).await
}

//TASK
#[classmethod]
#[cmod::tags(args(params))]
Expand Down
1 change: 1 addition & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod motion;
pub mod posture;
pub mod serial;
pub mod signal;
pub mod storage;
pub mod system;
pub mod task;

Expand Down
21 changes: 21 additions & 0 deletions src/rpc/storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use super::Robot;
use cmod::Result;
use proto::lebai::storage::*;

impl Robot {
pub(crate) async fn set_item(&self, key: String, value: String) -> Result<()> {
let req = Item { key, value };
let _ = self.c.set_item(Some(req)).await.map_err(|e| e.to_string())?;
Ok(())
}
pub(crate) async fn get_item(&self, key: String) -> Result<Item> {
let req = ItemIndex { key };
let resp = self.c.get_item(Some(req)).await.map_err(|e| e.to_string())?;
Ok(resp)
}
pub(crate) async fn get_items(&self, prefix: String) -> Result<Vec<Item>> {
let req = GetItemsRequest { prefix };
let resp = self.c.get_items(Some(req)).await.map_err(|e| e.to_string())?;
Ok(resp.items)
}
}

0 comments on commit fe3dcfc

Please sign in to comment.