client-rust
client-rust copied to clipboard
Introduce KeySpace interface for API v2.
Signed-off-by: iosmanthus [email protected]
This pull request is still working in progress, and the interfaces for request encoding are stable. However, lots of the request structs need to implement with these interfaces.
The core interfaces to encode the request are:
/// Abstracts any request sent to a TiKV server.
#[async_trait]
pub trait KvRequest<C>: Request + Sized + Clone + Sync + Send + 'static {
/// The expected response to the request.
type Response: HasKeyErrors + HasLocks + Clone + Send + 'static;
fn encode_request(&self, _codec: &C) -> Cow<Self>;
fn decode_response(&self, _codec: &C, _resp: Self::Response) -> crate::Result<Self::Response>;
}
When the C is bound to RequestCodec, the requests are able to be encoded:
pub trait RequestCodec: Sized + Clone + Sync + Send + 'static {
fn encode_key(&self, key: Vec<u8>) -> Vec<u8> { key }
fn decode_key(&self, key: Vec<u8>) -> Result<Vec<u8>> { Ok(key) }
fn encode_range(&self, start: Vec<u8>, end: Vec<u8>) -> (Vec<u8>, Vec<u8>) { (start, end) }
fn encode_pd_query(&self, key: Vec<u8>) -> Vec<u8> { key }
fn decode_region(&self, region: Region) -> Result<Region> { Ok(region) }
}
TODO:
- [x] Compile pass for API V1
- [x] Fix test for API v1
- [x] Impl V2 codec
- [ ] Write tests for V2 codec.
I am very excited for this!