feat(proto): add frontend message writer
This commit is contained in:
parent
225f9e43d3
commit
67af05ea42
2 changed files with 41 additions and 1 deletions
40
proto/src/writer/frontend.rs
Normal file
40
proto/src/writer/frontend.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
use crate::message::frontend::FrontendMessage;
|
||||||
|
use crate::writer::oneway::OneWayProtoWriter;
|
||||||
|
use async_trait::async_trait;
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
pub trait FrontendProtoWriter: OneWayProtoWriter<FrontendMessage> {}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl<W> FrontendProtoWriter for W where W: OneWayProtoWriter<FrontendMessage> {}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::message::frontend::QueryData;
|
||||||
|
use crate::writer::protowriter::ProtoWriter;
|
||||||
|
use tokio::io::BufWriter;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_message_sequence() {
|
||||||
|
let writer = BufWriter::new(Vec::new());
|
||||||
|
let mut writer = ProtoWriter::new(writer);
|
||||||
|
|
||||||
|
writer
|
||||||
|
.write_proto(FrontendMessage::Query(QueryData {
|
||||||
|
query: "SLIME".into(),
|
||||||
|
}))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
writer
|
||||||
|
.write_proto(FrontendMessage::Terminate)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
writer.inner.buffer(),
|
||||||
|
vec![b'Q', 0, 0, 0, 10, b'S', b'L', b'I', b'M', b'E', 0, b'X', 0, 0, 0, 4]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
|
|
||||||
pub mod backend;
|
pub mod backend;
|
||||||
|
pub mod frontend;
|
||||||
pub mod oneway;
|
pub mod oneway;
|
||||||
pub mod protowriter;
|
pub mod protowriter;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue