aboutsummaryrefslogtreecommitdiffstats
path: root/src/kiss.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/kiss.rs')
-rw-r--r--src/kiss.rs23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/kiss.rs b/src/kiss.rs
index 397922d..e9f4703 100644
--- a/src/kiss.rs
+++ b/src/kiss.rs
@@ -1,7 +1,6 @@
// Taken from ax25-rs, which is
// SPDX-License-Identifier: Apache-2.0
use std::io;
-use std::io::prelude::*;
use std::io::{Read, Write};
const FEND: u8 = 0xC0;
@@ -10,12 +9,12 @@ const TFEND: u8 = 0xDC;
const TFESC: u8 = 0xDD;
pub struct KissDecoder<'a> {
- stream: &'a Read,
+ stream: &'a mut Read,
buffer: Vec<u8>
}
impl<'a> KissDecoder<'a> {
- pub fn new<T>(stream: &T) -> io::Result<KissDecoder>
+ pub fn new<T>(stream: &'a mut T) -> io::Result<KissDecoder>
where T: Read
{
Ok(KissDecoder {
@@ -36,22 +35,21 @@ impl<'a> KissDecoder<'a> {
}
}
-/*
-pub struct KissEncoder {
- stream: Write,
- buffer: Vec<u8>
+pub struct KissEncoder<'a> {
+ stream: &'a mut Write,
}
-impl KissEncoder {
- pub fn new(stream: Write) -> io::Result<KissEncoder> {
+impl<'a> KissEncoder<'a> {
+ pub fn new<T>(stream: &'a mut T) -> io::Result<KissEncoder>
+ where T: Write
+ {
Ok(KissEncoder {
stream: stream,
- buffer: Vec::new()
})
}
pub fn send_frame(&mut self, frame: &[u8]) -> io::Result<()> {
- // 0x00 is the KISS command byte, which is two nybbles
+ // 0x00 is the KISS command byte, which is two nibbles
// port = 0
// command = 0 (all following bytes are a data frame to transmit)
self.stream.write(&[FEND, 0x00])?;
@@ -72,7 +70,7 @@ fn make_frame_from_buffer(buffer: &mut Vec<u8>) -> Option<Vec<u8>> {
}
let mut state = Scan::LookingForStartMarker;
let mut final_idx = 0;
-
+
// Check for possible frame read-only until we know we have a complete frame
// If we take one out, clear out buffer up to the final index
for (idx, &c) in buffer.iter().enumerate() {
@@ -180,4 +178,3 @@ fn test_two_frames_double_fend() {
assert_eq!(make_frame_from_buffer(&mut rx), Some(vec![0x03, 0x04]));
assert_eq!(rx, vec![FEND]);
}
-*/