Skip to main content

DemoWriter

Struct DemoWriter 

Source
pub struct DemoWriter<'a, R, W>
where R: BitsReader + MessageReader, W: Write + Seek,
{ /* private fields */ }
Expand description

Demo writer that reads demo messages and writes a rewritten stream.

The writer maintains the parser metadata needed for the registered rewrites, such as serializers, classes, string tables, baselines, and entity state. Output targets must be seekable so the demo header can be patched after writing.

Implementations§

Source§

impl<'a, R, W> DemoWriter<'a, R, W>
where R: BitsReader + MessageReader, W: Write + Seek,

Source

pub fn run(&mut self) -> Result<(), ParserError>

Parses the demo while writing the rewritten stream.

Source§

impl<'a, R, W> DemoWriter<'a, R, W>
where R: BitsReader + MessageReader, W: Write + Seek,

Source

pub fn new(parser: Parser<'a, R>, writer: W) -> Self

Creates a new demo writer from an existing parser and output target.

Source

pub fn add_rewriter<T>(&mut self, rewriter: T) -> Rc<RefCell<T>>
where T: DemoRewriter + 'a,

Adds an already constructed demo rewriter and returns a handle to it.

Use this when the rewriter needs custom constructor state. Rewriters run in registration order; message callbacks see the output of earlier rewriters.

Source

pub fn register_rewriter<T>(&mut self) -> Rc<RefCell<T>>
where T: DemoRewriter + Default + 'a,

Registers a default demo rewriter and returns a handle to it.

This mirrors Parser::register_observer: the writer constructs T::default(), registers it, and returns an Rc<RefCell<T>> so callers can inspect accumulated state after writing.

§Examples
#[derive(Default)]
struct RemoveChat;

#[rewriter]
impl RemoveChat {
    #[rewrite_packet_message]
    fn remove_chat(
        &mut self,
        _message: CDotaUserMsgChatMessage,
    ) -> Result<MessageRewrite, ParserError> {
        Ok(MessageRewrite::Drop)
    }
}

let mut writer = DemoWriter::from_reader(input, output)?;
writer.register_rewriter::<RemoveChat>();
writer.run()?;
Source

pub fn into_parts(self) -> (Parser<'a, R>, W)

Returns the wrapped parser and output target.

Source§

impl<'a, W> DemoWriter<'a, SliceReader<'a>, W>
where W: Write + Seek,

Source

pub fn from_slice(replay: &'a [u8], writer: W) -> Result<Self, ParserError>

Creates a demo writer from replay bytes and an output target.

This is a convenience wrapper around Parser::from_slice and DemoWriter::new.

Source§

impl<S, W> DemoWriter<'static, SeekableReader<S>, W>
where S: Read + Seek, W: Write + Seek,

Source

pub fn from_reader(reader: S, writer: W) -> Result<Self, ParserError>

Creates a demo writer from a seekable reader and an output target.

This is a convenience wrapper around Parser::from_reader and DemoWriter::new.

Auto Trait Implementations§

§

impl<'a, R, W> Freeze for DemoWriter<'a, R, W>
where W: Freeze, R: Freeze,

§

impl<'a, R, W> !RefUnwindSafe for DemoWriter<'a, R, W>

§

impl<'a, R, W> !Send for DemoWriter<'a, R, W>

§

impl<'a, R, W> !Sync for DemoWriter<'a, R, W>

§

impl<'a, R, W> Unpin for DemoWriter<'a, R, W>
where W: Unpin, R: Unpin,

§

impl<'a, R, W> UnsafeUnpin for DemoWriter<'a, R, W>
where W: UnsafeUnpin, R: UnsafeUnpin,

§

impl<'a, R, W> !UnwindSafe for DemoWriter<'a, R, W>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.