replay
stableA frame recorder that stores sequences of binary frames in memory, with playback and serialization support.
use plugin replay::{Recorder.new, Recorder.from_bytes, record_frame, …} Functions (11)
- Recorder.new Create a new empty recorder
- Recorder.from_bytes Deserialize a recorder from byte data
- record_frame Append a binary frame to the recorder
- frame_count Return the number of recorded frames
- get_frame Retrieve a frame by index
- last_frame Return the most recently recorded frame
- play_range Return a slice of frames as a table
- remove_frame Remove a frame at a given index
- clear Remove all recorded frames
- total_bytes Return total byte size of all frames
- to_bytes Serialize all frames to a byte string
Create a new empty recorder
Creates a new empty Recorder handle. Use this to begin capturing frames for later playback or export.
use plugin replay::{Recorder}
let rec = Recorder.new()
rec.record_frame("frame data 1")
rec.record_frame("frame data 2")
print("frames: {rec.frame_count()}")
Deserialize a recorder from byte data
Deserializes a recorder from a previously serialized byte string (produced by to_bytes). Use this to reload a recording from disk or a network source.
use plugin replay::{Recorder}
let rec = Recorder.new()
rec.record_frame("hello")
rec.record_frame("world")
let serialized = rec.to_bytes()
let rec2 = Recorder.from_bytes(serialized)
print("restored frames: {rec2.frame_count()}")
Append a binary frame to the recorder
Appends a binary frame to the end of the recorder. The data argument is treated as raw bytes.
use plugin replay::{Recorder}
let rec = Recorder.new()
rec.record_frame("tick 1 state")
rec.record_frame("tick 2 state")
Return the number of recorded frames
Returns the number of frames currently stored in the recorder.
use plugin replay::{Recorder}
let rec = Recorder.new()
rec.record_frame("a")
rec.record_frame("b")
print(rec.frame_count()) // 2
Retrieve a frame by index
Returns the frame at the given zero-based index. Errors if the index is out of range.
use plugin replay::{Recorder}
let rec = Recorder.new()
rec.record_frame("snapshot-0")
rec.record_frame("snapshot-1")
let f = rec.get_frame(0)
print(f) // snapshot-0
Return the most recently recorded frame
Returns the most recently appended frame, or nil if the recorder is empty.
use plugin replay::{Recorder}
let rec = Recorder.new()
print(rec.last_frame()) // nil
rec.record_frame("latest")
print(rec.last_frame()) // latest
Return a slice of frames as a table
Returns a table of frames from index start (inclusive) to end (exclusive). Each entry is a {index, bytes} pair. Useful for stepping through a replay window.
use plugin replay::{Recorder}
let rec = Recorder.new()
rec.record_frame("f0")
rec.record_frame("f1")
rec.record_frame("f2")
let window = rec.play_range(1, 3)
print(window[1]) // f1
Remove a frame at a given index
Removes the frame at the given index, shifting subsequent frames down. Errors if the index is out of range.
use plugin replay::{Recorder}
let rec = Recorder.new()
rec.record_frame("keep")
rec.record_frame("remove me")
rec.remove_frame(1)
print(rec.frame_count()) // 1
Remove all recorded frames
Removes all frames from the recorder, resetting it to empty.
use plugin replay::{Recorder}
let rec = Recorder.new()
rec.record_frame("data")
rec.clear()
print(rec.frame_count()) // 0
Return total byte size of all frames
Returns the total number of bytes across all stored frames (excluding framing overhead).
use plugin replay::{Recorder}
let rec = Recorder.new()
rec.record_frame("hello")
rec.record_frame("world")
print(rec.total_bytes()) // 10
Serialize all frames to a byte string
Serializes all frames into a single byte string with length-prefixed framing (4-byte little-endian per frame). Pass the result to Recorder.from_bytes to restore.
use plugin replay::{Recorder}
let rec = Recorder.new()
rec.record_frame("frame A")
rec.record_frame("frame B")
let blob = rec.to_bytes()
print("serialized size: {blob.len()}")