Add metaframe methods to `ProtocolWrite`

next
Sayan Nandan 2 years ago
parent 2bb7555e4e
commit 9c15e100c8
No known key found for this signature in database
GPG Key ID: 8BC07A0A4D41DD52

@ -47,6 +47,8 @@ pub trait ProtocolCharset {
const TSYMBOL_ARRAY: u8; const TSYMBOL_ARRAY: u8;
const TSYMBOL_FLAT_ARRAY: u8; const TSYMBOL_FLAT_ARRAY: u8;
const LF: u8 = b'\n'; const LF: u8 = b'\n';
const SIMPLE_QUERY_HEADER: &'static [u8];
const PIPELINED_QUERY_FIRST_BYTE: u8;
const TYPE_TYPED_ARRAY_ELEMENT_NULL: &'static [u8]; const TYPE_TYPED_ARRAY_ELEMENT_NULL: &'static [u8];
} }
@ -224,10 +226,27 @@ where
Strm: Stream, Strm: Stream,
P: ProtocolSpec, P: ProtocolSpec,
{ {
// utility (intentionally underscored to avoid direct access)
fn _get_raw_stream(&mut self) -> &mut BufWriter<Strm> { fn _get_raw_stream(&mut self) -> &mut BufWriter<Strm> {
self.get_mut_stream() self.get_mut_stream()
} }
// metaframe methods
async fn write_simple_query_header(&mut self) -> IoResult<()> {
self.get_mut_stream()
.write_all(P::SIMPLE_QUERY_HEADER)
.await
}
async fn write_pipelined_query_header(&mut self, qcount: usize) -> IoResult<()> {
self.get_mut_stream()
.write_all(&[P::PIPELINED_QUERY_FIRST_BYTE])
.await?;
self.get_mut_stream()
.write_all(&Integer64::from(qcount))
.await?;
self.get_mut_stream().write_all(&[P::LF]).await
}
// monoelements // monoelements
/// serialize and write an `&str` to the stream /// serialize and write an `&str` to the stream
async fn write_string(&mut self, string: &str) -> IoResult<()>; async fn write_string(&mut self, string: &str) -> IoResult<()>;

@ -45,6 +45,8 @@ impl ProtocolCharset for Skyhash2 {
const TSYMBOL_ARRAY: u8 = b'&'; const TSYMBOL_ARRAY: u8 = b'&';
const TSYMBOL_FLAT_ARRAY: u8 = b'_'; const TSYMBOL_FLAT_ARRAY: u8 = b'_';
const TYPE_TYPED_ARRAY_ELEMENT_NULL: &'static [u8] = b"\0"; const TYPE_TYPED_ARRAY_ELEMENT_NULL: &'static [u8] = b"\0";
const SIMPLE_QUERY_HEADER: &'static [u8] = b"*";
const PIPELINED_QUERY_FIRST_BYTE: u8 = b'$';
} }
impl ProtocolSpec for Skyhash2 { impl ProtocolSpec for Skyhash2 {

Loading…
Cancel
Save