turn text and binary protocols into features
This commit is contained in:
parent
1c9f82034f
commit
2337c0497c
3 changed files with 37 additions and 7 deletions
|
|
@ -25,6 +25,11 @@ tower-http = { version = "0.6.1", features = ["fs", "trace"] }
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["text", "binary"]
|
||||||
|
text = []
|
||||||
|
binary = []
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "*"
|
tempfile = "*"
|
||||||
test-case = "*"
|
test-case = "*"
|
||||||
|
|
|
||||||
|
|
@ -14,17 +14,31 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
macro_rules! build_parser_type_enum {
|
macro_rules! build_parser_type_enum {
|
||||||
($($name:ident: $t:ty,)*) => {
|
($($name:ident: $t:ty: $feat:expr,)*) => {
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
enum ParserTypes {
|
pub enum ParserTypes {
|
||||||
$($name($t),)*
|
$(
|
||||||
|
#[cfg(feature = $feat)]
|
||||||
|
$name($t),
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::default::Default for ParserTypes {
|
||||||
|
// add code here
|
||||||
|
fn default() -> Self {
|
||||||
|
$(
|
||||||
|
#[cfg(feature = $feat)]
|
||||||
|
return ParserTypes::$name(<$t>::default());
|
||||||
|
)*
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! match_parser {
|
macro_rules! match_parser {
|
||||||
($pident:ident: $parser:expr => $f:expr) => (
|
($pident:ident: $parser:expr => $f:expr) => (
|
||||||
match &mut $parser {
|
match &mut $parser {
|
||||||
$(
|
$(
|
||||||
|
#[cfg(feature = $feat)]
|
||||||
ParserTypes::$name($pident) => $f,
|
ParserTypes::$name($pident) => $f,
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
|
|
@ -34,8 +48,8 @@ macro_rules! build_parser_type_enum {
|
||||||
}
|
}
|
||||||
|
|
||||||
build_parser_type_enum! {
|
build_parser_type_enum! {
|
||||||
TextParser: TextParser,
|
TextParser: TextParser: "text",
|
||||||
BinaryParser: BinaryParser,
|
BinaryParser: BinaryParser: "binary",
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FlutClient<R, W>
|
pub struct FlutClient<R, W>
|
||||||
|
|
@ -105,8 +119,14 @@ where
|
||||||
|
|
||||||
fn change_protocol(&mut self, protocol: &Protocol) {
|
fn change_protocol(&mut self, protocol: &Protocol) {
|
||||||
match protocol {
|
match protocol {
|
||||||
|
#[cfg(feature="text")]
|
||||||
Protocol::Text => self.parser = ParserTypes::TextParser(TextParser::default()),
|
Protocol::Text => self.parser = ParserTypes::TextParser(TextParser::default()),
|
||||||
|
#[cfg(not(feature="text"))]
|
||||||
|
Protocol::Text => {self.writer.write(b"feature \"text\" is not enabled."); self.writer.flush();}
|
||||||
|
#[cfg(feature = "binary")]
|
||||||
Protocol::Binary => self.parser = ParserTypes::BinaryParser(BinaryParser::default()),
|
Protocol::Binary => self.parser = ParserTypes::BinaryParser(BinaryParser::default()),
|
||||||
|
#[cfg(not(feature = "binary"))]
|
||||||
|
Protocol::Binary => {self.writer.write(b"feature \"binary\" is not enabled."); self.writer.flush();}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,7 +135,7 @@ where
|
||||||
reader: BufReader::new(reader),
|
reader: BufReader::new(reader),
|
||||||
writer: BufWriter::new(writer),
|
writer: BufWriter::new(writer),
|
||||||
grids,
|
grids,
|
||||||
parser: ParserTypes::TextParser(TextParser::default()),
|
parser: ParserTypes::default(),
|
||||||
counter: 0,
|
counter: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use std::{
|
||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
use flurry::{
|
use flurry::{
|
||||||
config::{GRID_LENGTH, HOST, IMAGE_SAVE_INTERVAL, JPEG_UPDATE_INTERVAL},
|
config::{GRID_LENGTH, HOST, IMAGE_SAVE_INTERVAL, JPEG_UPDATE_INTERVAL},
|
||||||
flutclient::FlutClient,
|
flutclient::{FlutClient, },
|
||||||
grid::{self, Flut},
|
grid::{self, Flut},
|
||||||
webapi::WebApiContext,
|
webapi::WebApiContext,
|
||||||
AsyncResult, COUNTER,
|
AsyncResult, COUNTER,
|
||||||
|
|
@ -102,6 +102,11 @@ async fn main() {
|
||||||
let grids: Arc<[Flut<u32>; GRID_LENGTH]> = [grid::Flut::init(800, 600, 0xff_00_ff_ff)].into();
|
let grids: Arc<[Flut<u32>; GRID_LENGTH]> = [grid::Flut::init(800, 600, 0xff_00_ff_ff)].into();
|
||||||
tracing::trace!("created grids");
|
tracing::trace!("created grids");
|
||||||
|
|
||||||
|
#[cfg(feature = "text")]
|
||||||
|
println!("Enabling text");
|
||||||
|
#[cfg(feature = "binary")]
|
||||||
|
println!("Enabling binary");
|
||||||
|
|
||||||
let Ok(flut_listener) = TcpListener::bind(HOST).await else {
|
let Ok(flut_listener) = TcpListener::bind(HOST).await else {
|
||||||
tracing::error!(
|
tracing::error!(
|
||||||
"Was unable to bind to {HOST}, please check if a different process is bound"
|
"Was unable to bind to {HOST}, please check if a different process is bound"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue