@@ -8,28 +8,12 @@ use serde::{Deserialize, Serialize};
88/// The JSON payload for a `get` operation response.
99#[ derive( Serialize , Deserialize , Debug ) ]
1010pub struct GetResultPayload {
11- pub value : String ,
12- }
13-
14- /// The result of a `get` operation.
15- #[ derive( Debug ) ]
16- pub struct GetResult {
17- /// The retrieved value.
1811 pub value : Vec < u8 > ,
1912}
2013
21- /// An item in the result of a `query` operation. For internal use.
14+ /// An item in the result of a `query` operation.
2215#[ derive( Serialize , Deserialize , Debug ) ]
2316pub struct QueryResultItemPayload {
24- /// The key of the item (base64 encoded).
25- pub key : String ,
26- /// The value of the item (base64 encoded).
27- pub value : String ,
28- }
29-
30- /// An item in the result of a `query` operation.
31- #[ derive( Debug ) ]
32- pub struct QueryResultItem {
3317 /// The key of the item.
3418 pub key : Vec < u8 > ,
3519 /// The value of the item.
@@ -42,13 +26,6 @@ pub struct QueryResultPayload {
4226 pub results : Vec < QueryResultItemPayload > ,
4327}
4428
45- /// The result of a `query` operation.
46- #[ derive( Debug ) ]
47- pub struct QueryResult {
48- /// A list of key-value pairs.
49- pub results : Vec < QueryResultItem > ,
50- }
51-
5229/// A client for interacting with the key-value store.
5330#[ derive( Clone ) ]
5431pub struct Client {
@@ -90,7 +67,7 @@ impl Client {
9067 /// Retrieves a value from the store by its key.
9168 ///
9269 /// If the key does not exist, `Ok(None)` is returned.
93- pub async fn get ( & self , key : & [ u8 ] ) -> Result < Option < GetResult > , Error > {
70+ pub async fn get ( & self , key : & [ u8 ] ) -> Result < Option < GetResultPayload > , Error > {
9471 let key_b64 = general_purpose:: STANDARD . encode ( key) ;
9572 let url = format ! ( "{}/store/{}" , self . client. base_url, key_b64) ;
9673 let mut headers = reqwest:: header:: HeaderMap :: new ( ) ;
@@ -116,9 +93,8 @@ impl Client {
11693 }
11794
11895 let payload: GetResultPayload = res. json ( ) . await ?;
119- let value = general_purpose:: STANDARD . decode ( payload. value ) ?;
12096
121- Ok ( Some ( GetResult { value } ) )
97+ Ok ( Some ( payload ) )
12298 }
12399
124100 /// Queries for a range of key-value pairs.
@@ -133,7 +109,7 @@ impl Client {
133109 start : Option < & [ u8 ] > ,
134110 end : Option < & [ u8 ] > ,
135111 limit : Option < usize > ,
136- ) -> Result < QueryResult , Error > {
112+ ) -> Result < QueryResultPayload , Error > {
137113 let mut url = format ! ( "{}/store?" , self . client. base_url) ;
138114 if let Some ( start) = start {
139115 let start_b64 = general_purpose:: STANDARD . encode ( start) ;
@@ -166,14 +142,7 @@ impl Client {
166142 }
167143
168144 let payload: QueryResultPayload = res. json ( ) . await ?;
169- let mut results = Vec :: new ( ) ;
170- for item in payload. results {
171- results. push ( QueryResultItem {
172- key : general_purpose:: STANDARD . decode ( item. key ) ?,
173- value : general_purpose:: STANDARD . decode ( item. value ) ?,
174- } ) ;
175- }
176145
177- Ok ( QueryResult { results } )
146+ Ok ( payload )
178147 }
179148}
0 commit comments