Skip to content

Commit 7325bfb

Browse files
committed
Add protocol, clean code
1 parent 824ebfd commit 7325bfb

File tree

8 files changed

+66
-8
lines changed

8 files changed

+66
-8
lines changed

body-plz/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
#![allow(warnings)]
21
pub mod body_struct;
32
pub mod reader;

header-plz/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//#![allow(warnings)]
21
pub mod abnf;
32
pub mod body_headers;
43
pub mod const_headers;

mime-plz/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//#![feature(test)]
2-
31
mod content_type;
4-
mod mime_type;
52
pub use content_type::*;
3+
mod mime_type;

mime-plz/src/main.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.

protocol-plz/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "protocol_plz"
3+
version = "0.0.1"
4+
authors = ["darkseid", "sytten <emile@caido.io>"]
5+
description = "Protocol for the ParsePlz ecosystem"
6+
repository = "https://github.com/parseplz/primitives"
7+
license = "MIT"
8+
edition = "2024"
9+
10+
[dependencies]
11+
buffer-plz = { path = "../buffer-plz", version = "0.0.1" }
12+
bytes = { workspace = true }

protocol-plz/src/frame.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use bytes::BytesMut;
2+
3+
// Trait to convert frame to bytesmut
4+
pub trait Frame {
5+
fn into_data(self) -> BytesMut;
6+
}

protocol-plz/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mod frame;
2+
pub use frame::Frame;
3+
mod step;
4+
pub use step::Step;

protocol-plz/src/step.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use buffer::Event;
2+
3+
use crate::frame::Frame;
4+
5+
/* Description:
6+
* Trait to read a frame.
7+
*
8+
* Methods:
9+
* next()
10+
* Description : Process the event generated by IO to proceed with
11+
* the next step.
12+
* Args : Event
13+
* Returns : Self
14+
* Errors : StateError
15+
*
16+
* is_ended()
17+
* Description : Check if a frame has been read.
18+
* Returns : bool
19+
*
20+
* get_frame()
21+
* Description : Consumes the state machine and returns the frame.
22+
* Returns : T
23+
* Errors : FrameError
24+
*
25+
* Implementation:
26+
* OneOneState
27+
*/
28+
29+
pub trait Step<T>
30+
where
31+
T: Frame,
32+
{
33+
type StateError;
34+
type FrameError;
35+
36+
fn next(self, event: Event) -> Result<Self, Self::StateError>
37+
where
38+
Self: Sized;
39+
40+
fn is_ended(&self) -> bool;
41+
42+
fn into_frame(self) -> Result<T, Self::FrameError>;
43+
}

0 commit comments

Comments
 (0)