Skip to main content

sim_lib_stream_file/
cassette.rs

1use sim_kernel::{Expr, Result};
2use sim_lib_stream_core::{
3    StreamCassette, StreamGoldenFixtureReport, StreamValue, TransportProfile,
4};
5
6/// Records a stream into a cassette using the given transport profile.
7pub fn stream_to_cassette(
8    stream: &StreamValue,
9    profile: TransportProfile,
10) -> Result<StreamCassette> {
11    StreamCassette::from_stream_value(stream, profile)
12}
13
14/// Records a stream into a cassette and encodes it as an expression.
15pub fn stream_to_cassette_expr(stream: &StreamValue, profile: TransportProfile) -> Result<Expr> {
16    Ok(stream_to_cassette(stream, profile)?.to_expr())
17}
18
19/// Decodes a cassette expression and replays it as a stream.
20pub fn cassette_expr_to_stream(expr: &Expr) -> Result<StreamValue> {
21    StreamCassette::from_expr(expr)?.replay_stream_value()
22}
23
24/// Replays a recorded cassette back into a stream.
25pub fn cassette_to_stream(cassette: &StreamCassette) -> Result<StreamValue> {
26    cassette.replay_stream_value()
27}
28
29/// Validates a cassette against a golden fixture file at `path`.
30pub fn validate_cassette_fixture_path(
31    cassette: &StreamCassette,
32    path: &str,
33) -> Result<StreamGoldenFixtureReport> {
34    cassette.validate_golden_fixture(path)
35}