mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 10:14:06 +02:00
allow creating owned Demo
This commit is contained in:
parent
6ecb665f33
commit
3f4722bfea
2 changed files with 11 additions and 2 deletions
|
|
@ -18,8 +18,8 @@ pub struct Demo<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Demo<'a> {
|
impl<'a> Demo<'a> {
|
||||||
pub fn new(byes: &'a [u8]) -> Self {
|
pub fn new(bytes: &'a [u8]) -> Self {
|
||||||
let data = Buffer::new(byes, LittleEndian);
|
let data = Buffer::new(bytes, LittleEndian);
|
||||||
let stream = Stream::new(data);
|
let stream = Stream::new(data);
|
||||||
Demo { stream }
|
Demo { stream }
|
||||||
}
|
}
|
||||||
|
|
@ -30,6 +30,14 @@ impl<'a> Demo<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Demo<'static> {
|
||||||
|
pub fn owned(bytes: Vec<u8>) -> Self {
|
||||||
|
let data = Buffer::new_owned(bytes, LittleEndian);
|
||||||
|
let stream = Stream::new(data);
|
||||||
|
Demo { stream }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn handle_utf8_error(error: BitError) -> ReadResult<String> {
|
pub(crate) fn handle_utf8_error(error: BitError) -> ReadResult<String> {
|
||||||
match error {
|
match error {
|
||||||
BitError::Utf8Error(_, _) => Ok("-- Malformed utf8 --".into()),
|
BitError::Utf8Error(_, _) => Ok("-- Malformed utf8 --".into()),
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,7 @@ impl<'a> RawPacketStream<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct DemoTicker<'a, A: MessageHandler> {
|
pub struct DemoTicker<'a, A: MessageHandler> {
|
||||||
handler: DemoHandler<'a, A>,
|
handler: DemoHandler<'a, A>,
|
||||||
packets: RawPacketStream<'a>,
|
packets: RawPacketStream<'a>,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue