-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from sunsided/feature/corncobs
Add corncobs decoding
- Loading branch information
Showing
4 changed files
with
87 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,52 @@ | ||
use std::ops::{Deref, DerefMut}; | ||
|
||
use array_pool::pool::BorrowingSlice; | ||
|
||
/// A slice of data transmitted over the wire. | ||
pub struct DataSlice { | ||
buffer: BorrowingSlice<u8>, | ||
size: usize, | ||
} | ||
|
||
impl DataSlice { | ||
pub fn new(buffer: BorrowingSlice<u8>, size: usize) -> Self { | ||
assert!(buffer.len() >= size); | ||
Self { buffer, size } | ||
} | ||
|
||
#[allow(unused)] | ||
pub fn len(&self) -> usize { | ||
self.size | ||
} | ||
|
||
#[allow(unused)] | ||
pub fn is_empty(&self) -> bool { | ||
self.len() == 0 | ||
} | ||
} | ||
|
||
impl AsRef<[u8]> for DataSlice { | ||
fn as_ref(&self) -> &[u8] { | ||
&self.buffer[..self.size] | ||
} | ||
} | ||
|
||
impl AsMut<[u8]> for DataSlice { | ||
fn as_mut(&mut self) -> &mut [u8] { | ||
&mut self.buffer[..self.size] | ||
} | ||
} | ||
|
||
impl Deref for DataSlice { | ||
type Target = [u8]; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
self.as_ref() | ||
} | ||
} | ||
|
||
impl DerefMut for DataSlice { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
self.as_mut() | ||
} | ||
} |