summaryrefslogtreecommitdiff
path: root/src/i3bar_protocol.rs
diff options
context:
space:
mode:
authorMax Verevkin <maxxverrr@gmail.com>2022-04-25 00:51:49 +0300
committerMax Verevkin <maxxverrr@gmail.com>2022-04-25 00:51:49 +0300
commitabf0b9c47613f17fcc9b5b9dbb4c186621f05bd1 (patch)
tree4a8c88aff8105e8fe10babeda25d64101e020c38 /src/i3bar_protocol.rs
parent7a9325b7dfb7a2a2285ed459465b58f540a1f11f (diff)
downloadi3bar-mango-abf0b9c47613f17fcc9b5b9dbb4c186621f05bd1.tar.gz
throw an error if protocol version is unsupported
Diffstat (limited to 'src/i3bar_protocol.rs')
-rw-r--r--src/i3bar_protocol.rs22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/i3bar_protocol.rs b/src/i3bar_protocol.rs
index ef0a933..54ebd93 100644
--- a/src/i3bar_protocol.rs
+++ b/src/i3bar_protocol.rs
@@ -94,16 +94,20 @@ impl Protocol {
/// Extract new data from `bytes`, return unused bytes.
pub fn process_new_bytes<'a>(&mut self, bytes: &'a [u8]) -> Result<&'a [u8]> {
match self {
- Self::Unknown => {
- if let Ok((Some(header), rem)) = de_first_json::<JsonHeader>(bytes) {
- if header.version == 1 {
- *self = Self::JsonNotStarted(header);
- return self.process_new_bytes(rem);
- }
+ Self::Unknown => match de_first_json::<JsonHeader>(bytes) {
+ Ok((Some(header), rem)) if header.version == 1 => {
+ *self = Self::JsonNotStarted(header);
+ self.process_new_bytes(rem)
}
- *self = Self::PlainText { line: None };
- self.process_new_bytes(bytes)
- }
+ Ok((Some(header), _)) => Err(Error::new(
+ ErrorKind::Other,
+ format!("Protocol version {} is not supported", header.version),
+ )),
+ _ => {
+ *self = Self::PlainText { line: None };
+ self.process_new_bytes(bytes)
+ }
+ },
Self::PlainText { line } => {
if let Some((new_line, rem)) = last_line(bytes) {
*line = Some(String::from_utf8_lossy(new_line).into());