1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-03 18:24:05 +02:00

allow creating owned Demo

This commit is contained in:
Robin Appelman 2021-01-11 20:59:40 +01:00
commit 3f4722bfea
2 changed files with 11 additions and 2 deletions

View file

@ -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()),

View file

@ -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>,