Unwrap a `ClientResponsePayload` as a `ReadResults`, returning a `Protocol { InvalidResponse }` error for any other variant. Centralises the match so both `get_with_consistency` and `get_multi_with_consistency` share identical error semantics, and so the logic can be unit-tested without standing up a full Raft channel.
(result: Option<ClientResponsePayload>)
| 99 | /// `get_multi_with_consistency` share identical error semantics, and so |
| 100 | /// the logic can be unit-tested without standing up a full Raft channel. |
| 101 | fn extract_read_payload(result: Option<ClientResponsePayload>) -> ClientApiResult<ReadResults> { |
| 102 | match result { |
| 103 | Some(ClientResponsePayload::Read(r)) => Ok(r), |
| 104 | Some(ClientResponsePayload::Write(_)) => Err(ClientApiError::Protocol { |
| 105 | code: ErrorCode::InvalidResponse, |
| 106 | message: "expected ReadData payload, got WriteResult".to_string(), |
| 107 | supported_versions: None, |
| 108 | }), |
| 109 | None => Err(ClientApiError::Protocol { |
| 110 | code: ErrorCode::InvalidResponse, |
| 111 | message: "expected ReadData payload, got None".to_string(), |
| 112 | supported_versions: None, |
| 113 | }), |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /// Zero-overhead KV client for embedded mode. |
| 118 | /// |
no outgoing calls