-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
extern crate alloc; | ||
|
||
mod clientbound; | ||
mod sansio; | ||
mod serverbound; | ||
|
||
pub use clientbound::*; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//! A WIP sans-io implementation of the firmware protocol. | ||
//! | ||
//! sans-io means that it performs no io and can be used in async or non async code. | ||
mod serialization; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/// A simpler alternative to [`SerializeExact`], which will serialize without needing an | ||
/// exact buffer size. | ||
pub trait Serialize { | ||
type Error; | ||
/// Serializes into `buf`, returning the number of bytes written, or an error. | ||
/// Note that this must not return `Ok` if only part of `self` was actually serialized. | ||
fn serialize(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>; | ||
} | ||
|
||
/// Serializes directly into a buffer, such as directly into the tcp/udp buffers with no | ||
/// the exact size known. | ||
pub trait SerializeExact { | ||
type Error; | ||
/// Serializes the packet into the provided buffer. Implementations may choose to steal | ||
/// `self`, or perform a copy, or they may have already serialized into bytes preemptively | ||
/// (such as with flatbuffers). | ||
/// | ||
/// # Panics | ||
/// May panic if `f` returns an Ok variant with a buffer that is not the exact size as | ||
/// `f`'s argument. | ||
fn serialize_exact<'a, 'b>( | ||
&'a mut self, | ||
f: impl FnOnce(usize) -> nb::Result<&'b mut [u8], Self::Error>, // TODO: This might not work | ||
) -> nb::Result<(), Self::Error>; | ||
} |