1mod flag;
15mod create;
16mod close;
17mod data;
18mod frame;
19mod kind;
20mod mapping;
21mod token;
22
23pub use flag::ProtFlag;
24pub use kind::ProtKind;
25pub use create::ProtCreate;
26pub use close::ProtClose;
27pub use data::ProtData;
28pub use mapping::ProtMapping;
29pub use token::ProtToken;
30pub use frame::{ProtFrame, ProtFrameHeader};
31
32use webparse::{Buf, BufMut};
33
34use crate::ProxyResult;
35
36fn read_short_string<T: Buf>(buf: &mut T) -> ProxyResult<String> {
37 if buf.remaining() < 1 {
38 return Err(crate::ProxyError::TooShort);
39 }
40 let len = buf.get_u8() as usize;
41 if buf.remaining() < len {
42 return Err(crate::ProxyError::TooShort);
43 } else if len == 0 {
44 return Ok(String::new());
45 }
46 let s = String::from_utf8_lossy(&buf.chunk()[0..len]).to_string();
47 buf.advance(len);
48 Ok(s)
49}
50
51fn write_short_string<T: Buf + BufMut>(buf: &mut T, val: &str) -> ProxyResult<usize> {
52 let bytes = val.as_bytes();
53 if bytes.len() > 255 {
54 return Err(crate::ProxyError::TooShort);
55 }
56 let mut size = 0;
57 size += buf.put_u8(bytes.len() as u8);
58 size += buf.put_slice(bytes);
59 Ok(size)
60}