1use cita_cloud_proto::client::{InterceptedSvc, StorageClientTrait};
16use cita_cloud_proto::retry::RetryClient;
17use cita_cloud_proto::status_code::StatusCodeEnum;
18use cita_cloud_proto::storage::storage_service_client::StorageServiceClient;
19use cita_cloud_proto::storage::{Content, ExtKey};
20
21pub async fn store_data(
22 client: RetryClient<StorageServiceClient<InterceptedSvc>>,
23 region: u32,
24 key: Vec<u8>,
25 value: Vec<u8>,
26) -> StatusCodeEnum {
27 let content = Content { region, key, value };
28 match client.store(content.clone()).await {
29 Ok(code) => StatusCodeEnum::from(code),
30 Err(e) => {
31 warn!("store_data({:?}) failed: {}", content, e.to_string());
32 StatusCodeEnum::StorageServerNotReady
33 }
34 }
35}
36
37pub async fn load_data(
38 client: RetryClient<StorageServiceClient<InterceptedSvc>>,
39 region: u32,
40 key: Vec<u8>,
41) -> Result<Vec<u8>, StatusCodeEnum> {
42 let ext_key = ExtKey { region, key };
43 let value = client.load(ext_key.clone()).await.map_err(|e| {
44 warn!("load_data({:?}) failed: {}", ext_key, e.to_string());
45 StatusCodeEnum::StorageServerNotReady
46 })?;
47
48 StatusCodeEnum::from(value.status.ok_or(StatusCodeEnum::NoneStatusCode)?).is_success()?;
49 Ok(value.value)
50}