pub struct StdfWriter<W> { /* private fields */ }Expand description
STDF Writer
This writer accepts streams that implement Write trait,
and writes STDF records in given byte order.
Multiple APIs are provided to write STDF records, including:
write_recordfor writing parsed STDF V4-2007 records, not including reserved/unknown records.write_stdf_recordfor writing any parsed STDF records.write_stdf_record_viewfor writing any STDF record views.write_rawfor writing any unprocessed STDF records.write_raw_viewfor writing any unprocessed STDF record views.
use rust_stdf::{stdf_file::StdfWriter, ByteOrder, FAR};
let mut far = FAR::new();
far.cpu_type = 2;
far.stdf_ver = 4;
let mut out = Vec::new();
let mut writer = StdfWriter::new(&mut out, ByteOrder::LittleEndian);
writer.write_record(&far).unwrap();
assert_eq!(out, [2, 0, 0, 10, 2, 4]);Implementations§
Source§impl<W: Write> StdfWriter<W>
impl<W: Write> StdfWriter<W>
Sourcepub fn new(writer: W, byte_order: ByteOrder) -> Self
pub fn new(writer: W, byte_order: ByteOrder) -> Self
Create a new writer with the given output stream and byte order.
Sourcepub fn write_record<R: StdfRecordWrite>(
&mut self,
r: &R,
) -> Result<(), StdfError>
pub fn write_record<R: StdfRecordWrite>( &mut self, r: &R, ) -> Result<(), StdfError>
Write a STDF V4-2007 record to the output stream.
Validation will be performed on the record before writing, such as
length check of Cn field, count check for Kx* fields, returns StdfError
if validation fails.
Note: ReservedRec and UnknownRec cannot be written with this method,
use write_stdf_record instead.
Sourcepub fn write_stdf_record(&mut self, r: &StdfRecord) -> Result<(), StdfError>
pub fn write_stdf_record(&mut self, r: &StdfRecord) -> Result<(), StdfError>
Write a STDF V4-2007 record to the output stream, also supports
ReservedRec and UnknownRec.
Validation will be performed on the record before writing.
Note: reserved/unknown record must match the writer’s byte order,
otherwise, error StdfErrorKind::ByteOrderMismatch is returned.
Sourcepub fn write_stdf_record_view(
&mut self,
v: &StdfRecordView<'_>,
) -> Result<(), StdfError>
pub fn write_stdf_record_view( &mut self, v: &StdfRecordView<'_>, ) -> Result<(), StdfError>
Similar to write_stdf_record, but takes a borrowed StdfRecordView.
If known record types have different byte order than the writer, they are re-encoded
via implicit to_owned(). Reserved/unknown views cannot be re-encoded,
so a byte order mismatch returns error
StdfErrorKind::ByteOrderMismatch.
Sourcepub fn write_raw(&mut self, raw: &RawDataElement) -> Result<(), StdfError>
pub fn write_raw(&mut self, raw: &RawDataElement) -> Result<(), StdfError>
Write an unprocessed record RawDataElement to the output stream.
Byte order of the raw record must match the writer’s.
Sourcepub fn write_raw_view(
&mut self,
v: &RawDataElementView<'_>,
) -> Result<(), StdfError>
pub fn write_raw_view( &mut self, v: &RawDataElementView<'_>, ) -> Result<(), StdfError>
Write an unprocessed record view RawDataElementView to the output stream.
Byte order of the raw record must match the writer’s.