rust-stdf
A Rust library for reading and writing STDF V4 and V4-2007 test data logs.
# Cargo.toml
[dependencies]
rust-stdf = "1.1.0"
Features
Available features:
gzip: Read gzip-compressed (.gz) files withflate2.bzip: Read bzip2-compressed (.bz2) files withbzip2.zipfile: Read zip archives withzip.atdf: Read ATDF files and convert STDF to ATDF. This feature is under development.serialize: Serialize STDF records withserde.
[!NOTE]
zipfilecontains unsafe Rust. The reader opens only the first unencrypted file in an archive.
The gzip and bzip features are enabled by default. Disable default features to choose them explicitly:
rust-stdf = { version="1.1.0", default-features = false, features = ["gzip", ...]}
Reading STDF
This example iterates over records in an STDF V4 file. More examples are available in the example folder.
use ;
Choosing an Iterator
StdfReader provides three ways to read records. Each starts at the current file position:
get_record_iter()returns fully parsed, ownedStdfRecordvalues. It implementsIterator.get_rawdata_iter()returns unparsedRawDataElementvalues with owned payloads. It implementsIterator.get_rawdata_view_iter()returns unparsedRawDataElementViewvalues that borrow a reused buffer. It avoids heap allocation, but does not implementIterator; callnext()to advance it.
When you need only a few fields, convert a raw view to a zero-copy StdfRecordView. Its field getters parse data on demand instead of parsing the entire record:
use ;
let mut reader = new.unwrap;
// Read two unparsed records with get_rawdata_iter().
let mut count = 0;
for raw in reader
.get_rawdata_iter
.map
.filter
// Continue reading with get_rawdata_view_iter().
let mut iter = reader.get_rawdata_view_iter;
while let Some = iter.next
Writing STDF
Use StdfWriter from stdf_file to write STDF bytes. Typed records are validated before writing. When using BufWriter, call flush() or drop the writer when finished. See example/stdf_write_example.rs.
StdfWriter provides these methods:
write_record: Writes a validated typed record such asFARorPTR. It does not accept reserved or unknown records.write_stdf_record: Writes any ownedStdfRecord, includingReservedRecandUnknownRec.write_stdf_record_view: Writes any borrowedStdfRecordView. Known records are re-encoded when their byte order differs from the writer's.write_rawandwrite_raw_view: Write an encodedRawDataElementorRawDataElementViewwithout changing its bytes.
use ;
use File;
use BufWriter;
For a byte-exact filter or copy, such as removing selected record types, read borrowed views with get_rawdata_view_iter() and write them with write_raw_view. This avoids decoding and re-encoding. Match err.kind() to handle errors such as ByteOrderMismatch and RecordTooLarge. The following example edits selected records while copying the rest verbatim; see example/stdf_edit_example.rs.
use ;
use File;
use BufWriter;