Expand description
§iceoryx2 userland - record and replay
Provides building blocks to record and replay data from and into iceoryx2. The library itself does not capture the data, this has to be implemented by the user.
§Example
§Record Data
The individual types used by ServiceTypes can be acquired
from the StaticConfig of a
Service. For publish subscribe one can call for instance
publish_subscribe::StaticConfig::message_type_details()
use iceoryx2::prelude::*;
use iceoryx2_userland_record_and_replay::prelude::*;
use iceoryx2::service::static_config::message_type_details::{TypeDetail, TypeName};
use iceoryx2::service::static_config::message_type_details::TypeVariant;
use core::time::Duration;
let service_types = ServiceTypes {
payload: TypeDetail::new::<u64>(TypeVariant::FixedSize),
user_header: TypeDetail::new::<()>(TypeVariant::FixedSize),
system_header: TypeDetail::new::<u64>(TypeVariant::FixedSize),
};
// create the file recorder
let mut recorder = RecorderBuilder::new(&service_types)
.data_representation(DataRepresentation::HumanReadable)
.messaging_pattern(MessagingPattern::PublishSubscribe)
.create(&FilePath::new(b"recorded_data.iox2")?, &ServiceName::new("my-service")?)?;
// add some recorded data
recorder.write(RawRecord {
timestamp: Duration::ZERO,
system_header: &[0u8; 8],
user_header: &[0u8; 0],
payload: &[0u8; 8]
})?;
§Load Recorded Data Into Memory Buffer (Small Payload)
The whole recorded file is loaded into memory. Useful, when the data is not that large.
use iceoryx2::service::static_config::message_type_details::{TypeDetail, TypeName};
use iceoryx2::service::static_config::message_type_details::TypeVariant;
use iceoryx2::prelude::*;
use iceoryx2_userland_record_and_replay::prelude::*;
let replay = ReplayerOpener::new(&FilePath::new(b"recorded_data.iox2")?)
.data_representation(DataRepresentation::HumanReadable)
.open()?;
let record_header = replay.header().clone();
let buffer = replay.read_into_buffer().unwrap();
println!("record header of service types {record_header:?}");
for record in buffer {
println!("payload: {:?}", record.payload);
println!("user_header: {:?}", record.user_header);
println!("system_header: {:?}", record.system_header);
println!("timestamp: {:?}", record.timestamp);
}
§Read Record One-By-One (Large Payload)
The recorded file is opened and the records are read one-by-one.
use iceoryx2::service::static_config::message_type_details::{TypeDetail, TypeName};
use iceoryx2::service::static_config::message_type_details::TypeVariant;
use iceoryx2::prelude::*;
use iceoryx2_userland_record_and_replay::prelude::*;
let mut replayer = ReplayerOpener::new(&FilePath::new(b"recorded_data.iox2")?)
.data_representation(DataRepresentation::HumanReadable)
.open()?;
println!("record header of service types {:?}", replayer.header());
while let Some(record) = replayer.next_record()? {
println!("payload: {:?}", record.payload);
println!("user_header: {:?}", record.user_header);
println!("system_header: {:?}", record.system_header);
println!("timestamp: {:?}", record.timestamp);
}
Modules§
- hex_
conversion - Free functions to convert bytes to a hex string and back.
- prelude
- Loads a meaningful subset.
- record
- Contains the
RecordandRawRecordwhich represent a single entry that is added to the file. - record_
header - The header of the record file which contains all necessary type information.
- recorder
- Contains the
Recorderto write captured payload into a file. - replayer
- Contains the
Replayerto read captured payload from a file.