use crate::stdf_error::StdfError;
extern crate smart_default;
use smart_default::SmartDefault;
use std::convert::From;
#[cfg(feature = "serialize")]
use serde::Serialize;
#[cfg(feature = "serialize")]
use struct_field_names_as_array::FieldNamesAsArray;
macro_rules! read_optional {
($var:expr, [$func:ident($raw:expr, $pos:expr)], $min_bytes:expr) => {{
if *$pos + $min_bytes > $raw.len() {
$var = None;
return;
} else {
$var = Some([$func($raw, $pos)]);
}
}};
($var:expr, $func:ident($raw:expr, $pos:expr), $min_bytes:expr) => {{
if *$pos + $min_bytes > $raw.len() {
$var = None;
return;
} else {
$var = Some($func($raw, $pos));
}
}};
($var:expr, $func:ident($raw:expr, $pos:expr, $order:expr), $min_bytes:expr) => {{
if *$pos + $min_bytes > $raw.len() {
$var = None;
} else {
$var = Some($func($raw, $pos, $order));
}
}};
($var:expr, $func:ident($raw:expr, $pos:expr, $order:expr, $cnt:expr), $element_bytes:expr) => {{
if *$pos + $element_bytes * $cnt as usize > $raw.len() {
$var = None;
} else {
$var = Some($func($raw, $pos, $order, $cnt));
}
}};
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ByteOrder {
LittleEndian,
BigEndian,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CompressType {
Uncompressed,
#[cfg(feature = "gzip")]
GzipCompressed,
#[cfg(feature = "bzip")]
BzipCompressed,
#[cfg(feature = "zipfile")]
ZipCompressed,
}
#[derive(SmartDefault, Debug, Clone, Copy, PartialEq, Eq)]
pub struct RecordHeader {
pub len: u16,
pub typ: u8,
pub sub: u8,
}
pub type B1 = [u8; 1];
pub type C1 = char;
pub type U1 = u8;
pub type U2 = u16;
pub type U4 = u32;
pub type U8 = u64;
pub type I1 = i8;
pub type I2 = i16;
pub type I4 = i32;
pub type R4 = f32;
pub type R8 = f64;
pub type Cn = String;
pub type Cf = String;
pub type Sn = String;
pub type Bn = Vec<u8>;
pub type Dn = Vec<u8>;
pub type KxCn = Vec<Cn>;
pub type KxSn = Vec<Sn>;
pub type KxCf = Vec<Cf>;
pub type KxU1 = Vec<U1>;
pub type KxU2 = Vec<U2>;
pub type KxU4 = Vec<U4>;
pub type KxU8 = Vec<U8>;
pub type KxR4 = Vec<R4>;
pub type KxN1 = Vec<U1>;
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub enum KxUf {
#[default]
F1(KxU1),
F2(KxU2),
F4(KxU4),
F8(KxU8),
}
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[derive(Debug, Clone, PartialEq)]
pub enum V1 {
B0,
U1(U1),
U2(U2),
U4(U4),
I1(I1),
I2(I2),
I4(I4),
R4(R4),
R8(R8),
Cn(Cn),
Bn(Bn),
Dn(Dn),
N1(U1),
Invalid,
}
pub type Vn = Vec<V1>;
pub mod stdf_record_type {
use crate::stdf_error::StdfError;
pub const REC_FAR: u64 = 1;
pub const REC_ATR: u64 = 1 << 1;
pub const REC_VUR: u64 = 1 << 2;
pub const REC_MIR: u64 = 1 << 3;
pub const REC_MRR: u64 = 1 << 4;
pub const REC_PCR: u64 = 1 << 5;
pub const REC_HBR: u64 = 1 << 6;
pub const REC_SBR: u64 = 1 << 7;
pub const REC_PMR: u64 = 1 << 8;
pub const REC_PGR: u64 = 1 << 9;
pub const REC_PLR: u64 = 1 << 10;
pub const REC_RDR: u64 = 1 << 11;
pub const REC_SDR: u64 = 1 << 12;
pub const REC_PSR: u64 = 1 << 13;
pub const REC_NMR: u64 = 1 << 14;
pub const REC_CNR: u64 = 1 << 15;
pub const REC_SSR: u64 = 1 << 16;
pub const REC_CDR: u64 = 1 << 17;
pub const REC_WIR: u64 = 1 << 18;
pub const REC_WRR: u64 = 1 << 19;
pub const REC_WCR: u64 = 1 << 20;
pub const REC_PIR: u64 = 1 << 21;
pub const REC_PRR: u64 = 1 << 22;
pub const REC_TSR: u64 = 1 << 23;
pub const REC_PTR: u64 = 1 << 24;
pub const REC_MPR: u64 = 1 << 25;
pub const REC_FTR: u64 = 1 << 26;
pub const REC_STR: u64 = 1 << 27;
pub const REC_BPS: u64 = 1 << 28;
pub const REC_EPS: u64 = 1 << 29;
pub const REC_GDR: u64 = 1 << 30;
pub const REC_DTR: u64 = 1 << 31;
pub const REC_RESERVE: u64 = 1 << 32;
pub const REC_INVALID: u64 = 1 << 33;
#[inline(always)]
pub fn get_typ_sub_from_code(code: u64) -> Result<(u8, u8), StdfError> {
match code {
REC_PTR => Ok((15, 10)),
REC_MPR => Ok((15, 15)),
REC_FTR => Ok((15, 20)),
REC_STR => Ok((15, 30)),
REC_PIR => Ok((5, 10)),
REC_PRR => Ok((5, 20)),
REC_WIR => Ok((2, 10)),
REC_WRR => Ok((2, 20)),
REC_WCR => Ok((2, 30)),
REC_GDR => Ok((50, 10)),
REC_DTR => Ok((50, 30)),
REC_FAR => Ok((0, 10)),
REC_ATR => Ok((0, 20)),
REC_VUR => Ok((0, 30)),
REC_MIR => Ok((1, 10)),
REC_MRR => Ok((1, 20)),
REC_PCR => Ok((1, 30)),
REC_HBR => Ok((1, 40)),
REC_SBR => Ok((1, 50)),
REC_PMR => Ok((1, 60)),
REC_PGR => Ok((1, 62)),
REC_PLR => Ok((1, 63)),
REC_RDR => Ok((1, 70)),
REC_SDR => Ok((1, 80)),
REC_PSR => Ok((1, 90)),
REC_NMR => Ok((1, 91)),
REC_CNR => Ok((1, 92)),
REC_SSR => Ok((1, 93)),
REC_CDR => Ok((1, 94)),
REC_TSR => Ok((10, 30)),
REC_BPS => Ok((20, 10)),
REC_EPS => Ok((20, 20)),
_ => Err(StdfError {
code: 2,
msg: "unknown type constant".to_string(),
}),
}
}
#[inline(always)]
pub fn get_code_from_typ_sub(typ: u8, sub: u8) -> u64 {
match (typ, sub) {
(15, 10) => REC_PTR,
(15, 15) => REC_MPR,
(15, 20) => REC_FTR,
(15, 30) => REC_STR,
(5, 10) => REC_PIR,
(5, 20) => REC_PRR,
(2, 10) => REC_WIR,
(2, 20) => REC_WRR,
(2, 30) => REC_WCR,
(50, 10) => REC_GDR,
(50, 30) => REC_DTR,
(0, 10) => REC_FAR,
(0, 20) => REC_ATR,
(0, 30) => REC_VUR,
(1, 10) => REC_MIR,
(1, 20) => REC_MRR,
(1, 30) => REC_PCR,
(1, 40) => REC_HBR,
(1, 50) => REC_SBR,
(1, 60) => REC_PMR,
(1, 62) => REC_PGR,
(1, 63) => REC_PLR,
(1, 70) => REC_RDR,
(1, 80) => REC_SDR,
(1, 90) => REC_PSR,
(1, 91) => REC_NMR,
(1, 92) => REC_CNR,
(1, 93) => REC_SSR,
(1, 94) => REC_CDR,
(10, 30) => REC_TSR,
(20, 10) => REC_BPS,
(20, 20) => REC_EPS,
(180 | 181, _) => REC_RESERVE,
(_, _) => REC_INVALID,
}
}
#[inline(always)]
pub fn get_rec_name_from_code(rec_type: u64) -> &'static str {
match rec_type {
REC_PTR => "PTR",
REC_MPR => "MPR",
REC_FTR => "FTR",
REC_STR => "STR",
REC_PIR => "PIR",
REC_PRR => "PRR",
REC_WIR => "WIR",
REC_WRR => "WRR",
REC_WCR => "WCR",
REC_GDR => "GDR",
REC_DTR => "DTR",
REC_FAR => "FAR",
REC_ATR => "ATR",
REC_VUR => "VUR",
REC_MIR => "MIR",
REC_MRR => "MRR",
REC_PCR => "PCR",
REC_HBR => "HBR",
REC_SBR => "SBR",
REC_PMR => "PMR",
REC_PGR => "PGR",
REC_PLR => "PLR",
REC_RDR => "RDR",
REC_SDR => "SDR",
REC_PSR => "PSR",
REC_NMR => "NMR",
REC_CNR => "CNR",
REC_SSR => "SSR",
REC_CDR => "CDR",
REC_TSR => "TSR",
REC_BPS => "BPS",
REC_EPS => "EPS",
REC_RESERVE => "ReservedRec",
_ => "InvalidRec",
}
}
#[inline(always)]
pub fn get_code_from_rec_name(rec_name: &str) -> u64 {
match rec_name {
"FAR" => REC_FAR,
"ATR" => REC_ATR,
"VUR" => REC_VUR,
"MIR" => REC_MIR,
"MRR" => REC_MRR,
"PCR" => REC_PCR,
"HBR" => REC_HBR,
"SBR" => REC_SBR,
"PMR" => REC_PMR,
"PGR" => REC_PGR,
"PLR" => REC_PLR,
"RDR" => REC_RDR,
"SDR" => REC_SDR,
"PSR" => REC_PSR,
"NMR" => REC_NMR,
"CNR" => REC_CNR,
"SSR" => REC_SSR,
"CDR" => REC_CDR,
"WIR" => REC_WIR,
"WRR" => REC_WRR,
"WCR" => REC_WCR,
"PIR" => REC_PIR,
"PRR" => REC_PRR,
"TSR" => REC_TSR,
"PTR" => REC_PTR,
"MPR" => REC_MPR,
"FTR" => REC_FTR,
"STR" => REC_STR,
"BPS" => REC_BPS,
"EPS" => REC_EPS,
"GDR" => REC_GDR,
"DTR" => REC_DTR,
_ => REC_INVALID,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum StdfRecord {
FAR(FAR),
ATR(ATR),
VUR(VUR),
MIR(MIR),
MRR(MRR),
PCR(PCR),
HBR(HBR),
SBR(SBR),
PMR(PMR),
PGR(PGR),
PLR(PLR),
RDR(RDR),
SDR(SDR),
PSR(PSR),
NMR(NMR),
CNR(CNR),
SSR(SSR),
CDR(CDR),
WIR(WIR),
WRR(WRR),
WCR(WCR),
PIR(PIR),
PRR(PRR),
TSR(TSR),
PTR(PTR),
MPR(MPR),
FTR(FTR),
STR(STR),
BPS(BPS),
EPS(EPS),
GDR(GDR),
DTR(DTR),
ReservedRec(ReservedRec),
InvalidRec(RecordHeader),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RawDataElement {
pub offset: u64,
pub header: RecordHeader,
pub raw_data: Vec<u8>,
pub byte_order: ByteOrder,
}
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct FAR {
pub cpu_type: U1, pub stdf_ver: U1, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct ATR {
pub mod_tim: U4, pub cmd_line: Cn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct VUR {
pub upd_nam: Cn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct MIR {
pub setup_t: U4, pub start_t: U4, pub stat_num: U1, #[default = ' ']
pub mode_cod: C1, #[default = ' ']
pub rtst_cod: C1, #[default = ' ']
pub prot_cod: C1, #[default = 65535]
pub burn_tim: U2, #[default = ' ']
pub cmod_cod: C1, pub lot_id: Cn, pub part_typ: Cn, pub node_nam: Cn, pub tstr_typ: Cn, pub job_nam: Cn, pub job_rev: Cn, pub sblot_id: Cn, pub oper_nam: Cn, pub exec_typ: Cn, pub exec_ver: Cn, pub test_cod: Cn, pub tst_temp: Cn, pub user_txt: Cn, pub aux_file: Cn, pub pkg_typ: Cn, pub famly_id: Cn, pub date_cod: Cn, pub facil_id: Cn, pub floor_id: Cn, pub proc_id: Cn, pub oper_frq: Cn, pub spec_nam: Cn, pub spec_ver: Cn, pub flow_id: Cn, pub setup_id: Cn, pub dsgn_rev: Cn, pub eng_id: Cn, pub rom_cod: Cn, pub serl_num: Cn, pub supr_nam: Cn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct MRR {
pub finish_t: U4, #[default = ' ']
pub disp_cod: C1, pub usr_desc: Cn, pub exc_desc: Cn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct PCR {
pub head_num: U1, pub site_num: U1, pub part_cnt: U4, #[default = 4_294_967_295]
pub rtst_cnt: U4, #[default = 4_294_967_295]
pub abrt_cnt: U4, #[default = 4_294_967_295]
pub good_cnt: U4, #[default = 4_294_967_295]
pub func_cnt: U4, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct HBR {
pub head_num: U1, pub site_num: U1, pub hbin_num: U2, pub hbin_cnt: U4, #[default = ' ']
pub hbin_pf: C1, pub hbin_nam: Cn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct SBR {
pub head_num: U1, pub site_num: U1, pub sbin_num: U2, pub sbin_cnt: U4, #[default = ' ']
pub sbin_pf: C1, pub sbin_nam: Cn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct PMR {
pub pmr_indx: U2, #[default = 0]
pub chan_typ: U2, pub chan_nam: Cn, pub phy_nam: Cn, pub log_nam: Cn, #[default = 1]
pub head_num: U1, #[default = 1]
pub site_num: U1, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct PGR {
pub grp_indx: U2, pub grp_nam: Cn, pub indx_cnt: U2, pub pmr_indx: KxU2, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct PLR {
pub grp_cnt: U2, pub grp_indx: KxU2, pub grp_mode: KxU2, pub grp_radx: KxU1, pub pgm_char: KxCn, pub rtn_char: KxCn, pub pgm_chal: KxCn, pub rtn_chal: KxCn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct RDR {
pub num_bins: U2, pub rtst_bin: KxU2, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct SDR {
pub head_num: U1, pub site_grp: U1, pub site_cnt: U1, pub site_num: KxU1, pub hand_typ: Cn, pub hand_id: Cn, pub card_typ: Cn, pub card_id: Cn, pub load_typ: Cn, pub load_id: Cn, pub dib_typ: Cn, pub dib_id: Cn, pub cabl_typ: Cn, pub cabl_id: Cn, pub cont_typ: Cn, pub cont_id: Cn, pub lasr_typ: Cn, pub lasr_id: Cn, pub extr_typ: Cn, pub extr_id: Cn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct PSR {
pub cont_flg: B1, pub psr_indx: U2, pub psr_nam: Cn, pub opt_flg: B1, pub totp_cnt: U2, pub locp_cnt: U2, pub pat_bgn: KxU8, pub pat_end: KxU8, pub pat_file: KxCn, pub pat_lbl: KxCn, pub file_uid: KxCn, pub atpg_dsc: KxCn, pub src_id: KxCn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct NMR {
pub cont_flg: B1, pub totm_cnt: U2, pub locm_cnt: U2, pub pmr_indx: KxU2, pub atpg_nam: KxCn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct CNR {
pub chn_num: U2, pub bit_pos: U4, pub cell_nam: Sn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct SSR {
pub ssr_nam: Cn, pub chn_cnt: U2, pub chn_list: KxU2, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct CDR {
pub cont_flg: B1, pub cdr_indx: U2, pub chn_nam: Cn, pub chn_len: U4, pub sin_pin: U2, pub sout_pin: U2, pub mstr_cnt: U1, pub m_clks: KxU2, pub slav_cnt: U1, pub s_clks: KxU2, #[default = 255]
pub inv_val: U1, pub lst_cnt: U2, pub cell_lst: KxSn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct WIR {
pub head_num: U1, #[default = 255]
pub site_grp: U1, pub start_t: U4, pub wafer_id: Cn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct WRR {
pub head_num: U1, #[default = 255]
pub site_grp: U1, pub finish_t: U4, pub part_cnt: U4, #[default = 4_294_967_295]
pub rtst_cnt: U4, #[default = 4_294_967_295]
pub abrt_cnt: U4, #[default = 4_294_967_295]
pub good_cnt: U4, #[default = 4_294_967_295]
pub func_cnt: U4, pub wafer_id: Cn, pub fabwf_id: Cn, pub frame_id: Cn, pub mask_id: Cn, pub usr_desc: Cn, pub exc_desc: Cn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq)]
pub struct WCR {
#[default = 0.0]
pub wafr_siz: R4, #[default = 0.0]
pub die_ht: R4, #[default = 0.0]
pub die_wid: R4, #[default = 0]
pub wf_units: U1, #[default = ' ']
pub wf_flat: C1, #[default(-32768)]
pub center_x: I2, #[default(-32768)]
pub center_y: I2, #[default = ' ']
pub pos_x: C1, #[default = ' ']
pub pos_y: C1, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct PIR {
pub head_num: U1, pub site_num: U1, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct PRR {
pub head_num: U1, pub site_num: U1, pub part_flg: B1, pub num_test: U2, pub hard_bin: U2, #[default = 65535]
pub soft_bin: U2, #[default(-32768)]
pub x_coord: I2, #[default(-32768)]
pub y_coord: I2, #[default = 0]
pub test_t: U4, pub part_id: Cn, pub part_txt: Cn, pub part_fix: Bn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq)]
pub struct TSR {
pub head_num: U1, pub site_num: U1, #[default = ' ']
pub test_typ: C1, pub test_num: U4, #[default = 4_294_967_295]
pub exec_cnt: U4, #[default = 4_294_967_295]
pub fail_cnt: U4, #[default = 4_294_967_295]
pub alrm_cnt: U4, pub test_nam: Cn, pub seq_name: Cn, pub test_lbl: Cn, pub opt_flag: B1, pub test_tim: R4, pub test_min: R4, pub test_max: R4, pub tst_sums: R4, pub tst_sqrs: R4, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq)]
pub struct PTR {
pub test_num: U4, pub head_num: U1, pub site_num: U1, pub test_flg: B1, pub parm_flg: B1, pub result: R4, pub test_txt: Cn, pub alarm_id: Cn, pub opt_flag: Option<B1>, pub res_scal: Option<I1>, pub llm_scal: Option<I1>, pub hlm_scal: Option<I1>, pub lo_limit: Option<R4>, pub hi_limit: Option<R4>, pub units: Option<Cn>, pub c_resfmt: Option<Cn>, pub c_llmfmt: Option<Cn>, pub c_hlmfmt: Option<Cn>, pub lo_spec: Option<R4>, pub hi_spec: Option<R4>, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq)]
pub struct MPR {
pub test_num: U4, pub head_num: U1, pub site_num: U1, pub test_flg: B1, pub parm_flg: B1, pub rtn_icnt: U2, pub rslt_cnt: U2, pub rtn_stat: KxN1, pub rtn_rslt: KxR4, pub test_txt: Cn, pub alarm_id: Cn, pub opt_flag: Option<B1>, pub res_scal: Option<I1>, pub llm_scal: Option<I1>, pub hlm_scal: Option<I1>, pub lo_limit: Option<R4>, pub hi_limit: Option<R4>, pub start_in: Option<R4>, pub incr_in: Option<R4>, pub rtn_indx: Option<KxU2>, pub units: Option<Cn>, pub units_in: Option<Cn>, pub c_resfmt: Option<Cn>, pub c_llmfmt: Option<Cn>, pub c_hlmfmt: Option<Cn>, pub lo_spec: Option<R4>, pub hi_spec: Option<R4>, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct FTR {
pub test_num: U4, pub head_num: U1, pub site_num: U1, pub test_flg: B1, pub opt_flag: B1, pub cycl_cnt: U4, pub rel_vadr: U4, pub rept_cnt: U4, pub num_fail: U4, pub xfail_ad: I4, pub yfail_ad: I4, pub vect_off: I2, pub rtn_icnt: U2, pub pgm_icnt: U2, pub rtn_indx: KxU2, pub rtn_stat: KxN1, pub pgm_indx: KxU2, pub pgm_stat: KxN1, pub fail_pin: Dn, pub vect_nam: Cn, pub time_set: Cn, pub op_code: Cn, pub test_txt: Cn, pub alarm_id: Cn, pub prog_txt: Cn, pub rslt_txt: Cn, #[default = 255]
pub patg_num: U1, pub spin_map: Dn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct STR {
pub cont_flg: B1, pub test_num: U4, pub head_num: U1, pub site_num: U1, pub psr_ref: U2, pub test_flg: B1, pub log_typ: Cn, pub test_txt: Cn, pub alarm_id: Cn, pub prog_txt: Cn, pub rslt_txt: Cn, pub z_val: U1, pub fmu_flg: B1, pub mask_map: Dn, pub fal_map: Dn, pub cyc_cnt_t: U8, pub totf_cnt: U4, pub totl_cnt: U4, pub cyc_base: U8, pub bit_base: U4, pub cond_cnt: U2, pub lim_cnt: U2, pub cyc_size: U1, pub pmr_size: U1, pub chn_size: U1, pub pat_size: U1, pub bit_size: U1, pub u1_size: U1, pub u2_size: U1, pub u3_size: U1, pub utx_size: U1, pub cap_bgn: U2, pub lim_indx: KxU2, pub lim_spec: KxU4, pub cond_lst: KxCn, pub cyc_cnt: U2, pub cyc_ofst: KxUf, pub pmr_cnt: U2, pub pmr_indx: KxUf, pub chn_cnt: U2, pub chn_num: KxUf, pub exp_cnt: U2, pub exp_data: KxU1, pub cap_cnt: U2, pub cap_data: KxU1, pub new_cnt: U2, pub new_data: KxU1, pub pat_cnt: U2, pub pat_num: KxUf, pub bpos_cnt: U2, pub bit_pos: KxUf, pub usr1_cnt: U2, pub usr1: KxUf, pub usr2_cnt: U2, pub usr2: KxUf, pub usr3_cnt: U2, pub usr3: KxUf, pub txt_cnt: U2, pub user_txt: KxCf, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct BPS {
pub seq_name: Cn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct EPS {}
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq)]
pub struct GDR {
pub fld_cnt: U2, pub gen_data: Vn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct DTR {
pub text_dat: Cn, }
#[cfg_attr(
feature = "serialize",
derive(Serialize, FieldNamesAsArray),
serde(rename_all = "UPPERCASE"),
field_names_as_array(rename_all = "UPPERCASE")
)]
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct ReservedRec {
pub raw_data: Vec<u8>, }
impl RecordHeader {
#[inline(always)]
pub fn new() -> Self {
RecordHeader::default()
}
#[inline(always)]
pub fn read_from_bytes(
mut self,
raw_data: &[u8],
order: &ByteOrder,
) -> Result<Self, StdfError> {
match raw_data.len() {
0 => Err(StdfError {
code: 4,
msg: String::from("No bytes to read"),
}),
1..=3 => Err(StdfError {
code: 5,
msg: String::from("Not enough data to construct record header"),
}),
_ => {
let len_bytes = [raw_data[0], raw_data[1]];
self.len = match order {
ByteOrder::LittleEndian => u16::from_le_bytes(len_bytes),
ByteOrder::BigEndian => u16::from_be_bytes(len_bytes),
};
self.typ = raw_data[2];
self.sub = raw_data[3];
Ok(self)
}
}
}
pub fn get_type(&self) -> u64 {
stdf_record_type::get_code_from_typ_sub(self.typ, self.sub)
}
}
impl FAR {
#[inline(always)]
pub fn new() -> Self {
FAR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], _order: &ByteOrder) {
let pos = &mut 0;
self.cpu_type = read_uint8(raw_data, pos);
self.stdf_ver = read_uint8(raw_data, pos);
}
}
impl ATR {
#[inline(always)]
pub fn new() -> Self {
ATR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.mod_tim = read_u4(raw_data, pos, order);
self.cmd_line = read_cn(raw_data, pos);
}
}
impl VUR {
#[inline(always)]
pub fn new() -> Self {
VUR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], _order: &ByteOrder) {
let pos = &mut 0;
self.upd_nam = read_cn(raw_data, pos);
}
}
impl MIR {
#[inline(always)]
pub fn new() -> Self {
MIR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.setup_t = read_u4(raw_data, pos, order);
self.start_t = read_u4(raw_data, pos, order);
self.stat_num = read_uint8(raw_data, pos);
if *pos < raw_data.len() {
self.mode_cod = read_uint8(raw_data, pos) as char;
}
if *pos < raw_data.len() {
self.rtst_cod = read_uint8(raw_data, pos) as char;
}
if *pos < raw_data.len() {
self.prot_cod = read_uint8(raw_data, pos) as char;
}
if *pos + 2 <= raw_data.len() {
self.burn_tim = read_u2(raw_data, pos, order);
}
if *pos < raw_data.len() {
self.cmod_cod = read_uint8(raw_data, pos) as char;
}
self.lot_id = read_cn(raw_data, pos);
self.part_typ = read_cn(raw_data, pos);
self.node_nam = read_cn(raw_data, pos);
self.tstr_typ = read_cn(raw_data, pos);
self.job_nam = read_cn(raw_data, pos);
self.job_rev = read_cn(raw_data, pos);
self.sblot_id = read_cn(raw_data, pos);
self.oper_nam = read_cn(raw_data, pos);
self.exec_typ = read_cn(raw_data, pos);
self.exec_ver = read_cn(raw_data, pos);
self.test_cod = read_cn(raw_data, pos);
self.tst_temp = read_cn(raw_data, pos);
self.user_txt = read_cn(raw_data, pos);
self.aux_file = read_cn(raw_data, pos);
self.pkg_typ = read_cn(raw_data, pos);
self.famly_id = read_cn(raw_data, pos);
self.date_cod = read_cn(raw_data, pos);
self.facil_id = read_cn(raw_data, pos);
self.floor_id = read_cn(raw_data, pos);
self.proc_id = read_cn(raw_data, pos);
self.oper_frq = read_cn(raw_data, pos);
self.spec_nam = read_cn(raw_data, pos);
self.spec_ver = read_cn(raw_data, pos);
self.flow_id = read_cn(raw_data, pos);
self.setup_id = read_cn(raw_data, pos);
self.dsgn_rev = read_cn(raw_data, pos);
self.eng_id = read_cn(raw_data, pos);
self.rom_cod = read_cn(raw_data, pos);
self.serl_num = read_cn(raw_data, pos);
self.supr_nam = read_cn(raw_data, pos);
}
}
impl MRR {
#[inline(always)]
pub fn new() -> Self {
MRR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.finish_t = read_u4(raw_data, pos, order);
if *pos < raw_data.len() {
self.disp_cod = read_uint8(raw_data, pos) as char;
}
self.usr_desc = read_cn(raw_data, pos);
self.exc_desc = read_cn(raw_data, pos);
}
}
impl PCR {
#[inline(always)]
pub fn new() -> Self {
PCR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
self.part_cnt = read_u4(raw_data, pos, order);
if *pos + 4 <= raw_data.len() {
self.rtst_cnt = read_u4(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.abrt_cnt = read_u4(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.good_cnt = read_u4(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.func_cnt = read_u4(raw_data, pos, order);
}
}
}
impl HBR {
#[inline(always)]
pub fn new() -> Self {
HBR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
self.hbin_num = read_u2(raw_data, pos, order);
self.hbin_cnt = read_u4(raw_data, pos, order);
if *pos < raw_data.len() {
self.hbin_pf = read_uint8(raw_data, pos) as char;
}
self.hbin_nam = read_cn(raw_data, pos);
}
}
impl SBR {
#[inline(always)]
pub fn new() -> Self {
SBR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
self.sbin_num = read_u2(raw_data, pos, order);
self.sbin_cnt = read_u4(raw_data, pos, order);
if *pos < raw_data.len() {
self.sbin_pf = read_uint8(raw_data, pos) as char;
}
self.sbin_nam = read_cn(raw_data, pos);
}
}
impl PMR {
#[inline(always)]
pub fn new() -> Self {
PMR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.pmr_indx = read_u2(raw_data, pos, order);
if *pos + 2 <= raw_data.len() {
self.chan_typ = read_u2(raw_data, pos, order);
}
self.chan_nam = read_cn(raw_data, pos);
self.phy_nam = read_cn(raw_data, pos);
self.log_nam = read_cn(raw_data, pos);
if *pos < raw_data.len() {
self.head_num = read_uint8(raw_data, pos)
};
if *pos < raw_data.len() {
self.site_num = read_uint8(raw_data, pos)
};
}
}
impl PGR {
#[inline(always)]
pub fn new() -> Self {
PGR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.grp_indx = read_u2(raw_data, pos, order);
self.grp_nam = read_cn(raw_data, pos);
self.indx_cnt = read_u2(raw_data, pos, order);
self.pmr_indx = read_kx_u2(raw_data, pos, order, self.indx_cnt);
}
}
impl PLR {
#[inline(always)]
pub fn new() -> Self {
PLR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.grp_cnt = read_u2(raw_data, pos, order);
self.grp_indx = read_kx_u2(raw_data, pos, order, self.grp_cnt);
self.grp_mode = read_kx_u2(raw_data, pos, order, self.grp_cnt);
self.grp_radx = read_kx_u1(raw_data, pos, self.grp_cnt);
self.pgm_char = read_kx_cn(raw_data, pos, self.grp_cnt);
self.rtn_char = read_kx_cn(raw_data, pos, self.grp_cnt);
self.pgm_chal = read_kx_cn(raw_data, pos, self.grp_cnt);
self.rtn_chal = read_kx_cn(raw_data, pos, self.grp_cnt);
}
}
impl RDR {
#[inline(always)]
pub fn new() -> Self {
RDR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.num_bins = read_u2(raw_data, pos, order);
self.rtst_bin = read_kx_u2(raw_data, pos, order, self.num_bins);
}
}
impl SDR {
#[inline(always)]
pub fn new() -> Self {
SDR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], _order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
self.site_grp = read_uint8(raw_data, pos);
self.site_cnt = read_uint8(raw_data, pos);
self.site_num = read_kx_u1(raw_data, pos, self.site_cnt as u16);
self.hand_typ = read_cn(raw_data, pos);
self.hand_id = read_cn(raw_data, pos);
self.card_typ = read_cn(raw_data, pos);
self.card_id = read_cn(raw_data, pos);
self.load_typ = read_cn(raw_data, pos);
self.load_id = read_cn(raw_data, pos);
self.dib_typ = read_cn(raw_data, pos);
self.dib_id = read_cn(raw_data, pos);
self.cabl_typ = read_cn(raw_data, pos);
self.cabl_id = read_cn(raw_data, pos);
self.cont_typ = read_cn(raw_data, pos);
self.cont_id = read_cn(raw_data, pos);
self.lasr_typ = read_cn(raw_data, pos);
self.lasr_id = read_cn(raw_data, pos);
self.extr_typ = read_cn(raw_data, pos);
self.extr_id = read_cn(raw_data, pos);
}
}
impl PSR {
#[inline(always)]
pub fn new() -> Self {
PSR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.cont_flg = [read_uint8(raw_data, pos)];
self.psr_indx = read_u2(raw_data, pos, order);
self.psr_nam = read_cn(raw_data, pos);
self.opt_flg = [read_uint8(raw_data, pos)];
self.totp_cnt = read_u2(raw_data, pos, order);
self.locp_cnt = read_u2(raw_data, pos, order);
self.pat_bgn = read_kx_u8(raw_data, pos, order, self.locp_cnt);
self.pat_end = read_kx_u8(raw_data, pos, order, self.locp_cnt);
self.pat_file = read_kx_cn(raw_data, pos, self.locp_cnt);
self.pat_lbl = read_kx_cn(raw_data, pos, self.locp_cnt);
self.file_uid = read_kx_cn(raw_data, pos, self.locp_cnt);
self.atpg_dsc = read_kx_cn(raw_data, pos, self.locp_cnt);
self.src_id = read_kx_cn(raw_data, pos, self.locp_cnt);
}
}
impl NMR {
#[inline(always)]
pub fn new() -> Self {
NMR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.cont_flg = [read_uint8(raw_data, pos)];
self.totm_cnt = read_u2(raw_data, pos, order);
self.locm_cnt = read_u2(raw_data, pos, order);
self.pmr_indx = read_kx_u2(raw_data, pos, order, self.locm_cnt);
self.atpg_nam = read_kx_cn(raw_data, pos, self.locm_cnt);
}
}
impl CNR {
#[inline(always)]
pub fn new() -> Self {
CNR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.chn_num = read_u2(raw_data, pos, order);
self.bit_pos = read_u4(raw_data, pos, order);
self.cell_nam = read_sn(raw_data, pos, order);
}
}
impl SSR {
#[inline(always)]
pub fn new() -> Self {
SSR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.ssr_nam = read_cn(raw_data, pos);
self.chn_cnt = read_u2(raw_data, pos, order);
self.chn_list = read_kx_u2(raw_data, pos, order, self.chn_cnt);
}
}
impl CDR {
#[inline(always)]
pub fn new() -> Self {
CDR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.cont_flg = [read_uint8(raw_data, pos)];
self.cdr_indx = read_u2(raw_data, pos, order);
self.chn_nam = read_cn(raw_data, pos);
self.chn_len = read_u4(raw_data, pos, order);
self.sin_pin = read_u2(raw_data, pos, order);
self.sout_pin = read_u2(raw_data, pos, order);
self.mstr_cnt = read_uint8(raw_data, pos);
self.m_clks = read_kx_u2(raw_data, pos, order, self.mstr_cnt as u16);
self.slav_cnt = read_uint8(raw_data, pos);
self.s_clks = read_kx_u2(raw_data, pos, order, self.slav_cnt as u16);
if *pos < raw_data.len() {
self.inv_val = read_uint8(raw_data, pos);
}
self.lst_cnt = read_u2(raw_data, pos, order);
self.cell_lst = read_kx_sn(raw_data, pos, order, self.lst_cnt);
}
}
impl WIR {
#[inline(always)]
pub fn new() -> Self {
WIR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
if *pos < raw_data.len() {
self.site_grp = read_uint8(raw_data, pos);
}
self.start_t = read_u4(raw_data, pos, order);
self.wafer_id = read_cn(raw_data, pos);
}
}
impl WRR {
#[inline(always)]
pub fn new() -> Self {
WRR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
if *pos < raw_data.len() {
self.site_grp = read_uint8(raw_data, pos);
}
self.finish_t = read_u4(raw_data, pos, order);
self.part_cnt = read_u4(raw_data, pos, order);
if *pos + 4 <= raw_data.len() {
self.rtst_cnt = read_u4(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.abrt_cnt = read_u4(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.good_cnt = read_u4(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.func_cnt = read_u4(raw_data, pos, order);
}
self.wafer_id = read_cn(raw_data, pos);
self.fabwf_id = read_cn(raw_data, pos);
self.frame_id = read_cn(raw_data, pos);
self.mask_id = read_cn(raw_data, pos);
self.usr_desc = read_cn(raw_data, pos);
self.exc_desc = read_cn(raw_data, pos);
}
}
impl WCR {
#[inline(always)]
pub fn new() -> Self {
WCR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.wafr_siz = read_r4(raw_data, pos, order);
self.die_ht = read_r4(raw_data, pos, order);
self.die_wid = read_r4(raw_data, pos, order);
self.wf_units = read_uint8(raw_data, pos);
if *pos < raw_data.len() {
self.wf_flat = read_uint8(raw_data, pos) as char;
}
if *pos + 2 <= raw_data.len() {
self.center_x = read_i2(raw_data, pos, order);
}
if *pos + 2 <= raw_data.len() {
self.center_y = read_i2(raw_data, pos, order);
}
if *pos < raw_data.len() {
self.pos_x = read_uint8(raw_data, pos) as char;
}
if *pos < raw_data.len() {
self.pos_y = read_uint8(raw_data, pos) as char;
}
}
}
impl PIR {
#[inline(always)]
pub fn new() -> Self {
PIR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], _order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
}
}
impl PRR {
#[inline(always)]
pub fn new() -> Self {
PRR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
self.part_flg = [read_uint8(raw_data, pos)];
self.num_test = read_u2(raw_data, pos, order);
self.hard_bin = read_u2(raw_data, pos, order);
if *pos + 2 <= raw_data.len() {
self.soft_bin = read_u2(raw_data, pos, order);
}
if *pos + 2 <= raw_data.len() {
self.x_coord = read_i2(raw_data, pos, order);
}
if *pos + 2 <= raw_data.len() {
self.y_coord = read_i2(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.test_t = read_u4(raw_data, pos, order);
}
self.part_id = read_cn(raw_data, pos);
self.part_txt = read_cn(raw_data, pos);
self.part_fix = read_bn(raw_data, pos);
}
}
impl TSR {
#[inline(always)]
pub fn new() -> Self {
TSR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
if *pos < raw_data.len() {
self.test_typ = read_uint8(raw_data, pos) as char;
}
self.test_num = read_u4(raw_data, pos, order);
if *pos + 4 <= raw_data.len() {
self.exec_cnt = read_u4(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.fail_cnt = read_u4(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.alrm_cnt = read_u4(raw_data, pos, order);
}
self.test_nam = read_cn(raw_data, pos);
self.seq_name = read_cn(raw_data, pos);
self.test_lbl = read_cn(raw_data, pos);
self.opt_flag = [read_uint8(raw_data, pos)];
self.test_tim = read_r4(raw_data, pos, order);
self.test_min = read_r4(raw_data, pos, order);
self.test_max = read_r4(raw_data, pos, order);
self.tst_sums = read_r4(raw_data, pos, order);
self.tst_sqrs = read_r4(raw_data, pos, order);
}
}
impl PTR {
#[inline(always)]
pub fn new() -> Self {
PTR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.test_num = read_u4(raw_data, pos, order);
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
self.test_flg = [read_uint8(raw_data, pos)];
self.parm_flg = [read_uint8(raw_data, pos)];
self.result = read_r4(raw_data, pos, order);
self.test_txt = read_cn(raw_data, pos);
self.alarm_id = read_cn(raw_data, pos);
read_optional!(self.opt_flag, [read_uint8(raw_data, pos)], 1);
read_optional!(self.res_scal, read_i1(raw_data, pos), 1);
read_optional!(self.llm_scal, read_i1(raw_data, pos), 1);
read_optional!(self.hlm_scal, read_i1(raw_data, pos), 1);
read_optional!(self.lo_limit, read_r4(raw_data, pos, order), 4);
read_optional!(self.hi_limit, read_r4(raw_data, pos, order), 4);
read_optional!(self.units, read_cn(raw_data, pos), 1);
read_optional!(self.c_resfmt, read_cn(raw_data, pos), 1);
read_optional!(self.c_llmfmt, read_cn(raw_data, pos), 1);
read_optional!(self.c_hlmfmt, read_cn(raw_data, pos), 1);
read_optional!(self.lo_spec, read_r4(raw_data, pos, order), 4);
read_optional!(self.hi_spec, read_r4(raw_data, pos, order), 4);
}
}
impl MPR {
#[inline(always)]
pub fn new() -> Self {
MPR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.test_num = read_u4(raw_data, pos, order);
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
self.test_flg = [read_uint8(raw_data, pos)];
self.parm_flg = [read_uint8(raw_data, pos)];
self.rtn_icnt = read_u2(raw_data, pos, order);
self.rslt_cnt = read_u2(raw_data, pos, order);
self.rtn_stat = read_kx_n1(raw_data, pos, self.rtn_icnt);
self.rtn_rslt = read_kx_r4(raw_data, pos, order, self.rslt_cnt);
self.test_txt = read_cn(raw_data, pos);
self.alarm_id = read_cn(raw_data, pos);
read_optional!(self.opt_flag, [read_uint8(raw_data, pos)], 1);
read_optional!(self.res_scal, read_i1(raw_data, pos), 1);
read_optional!(self.llm_scal, read_i1(raw_data, pos), 1);
read_optional!(self.hlm_scal, read_i1(raw_data, pos), 1);
read_optional!(self.lo_limit, read_r4(raw_data, pos, order), 4);
read_optional!(self.hi_limit, read_r4(raw_data, pos, order), 4);
read_optional!(self.start_in, read_r4(raw_data, pos, order), 4);
read_optional!(self.incr_in, read_r4(raw_data, pos, order), 4);
read_optional!(
self.rtn_indx,
read_kx_u2(raw_data, pos, order, self.rtn_icnt),
2
);
read_optional!(self.units, read_cn(raw_data, pos), 1);
read_optional!(self.units_in, read_cn(raw_data, pos), 1);
read_optional!(self.c_resfmt, read_cn(raw_data, pos), 1);
read_optional!(self.c_llmfmt, read_cn(raw_data, pos), 1);
read_optional!(self.c_hlmfmt, read_cn(raw_data, pos), 1);
read_optional!(self.lo_spec, read_r4(raw_data, pos, order), 4);
read_optional!(self.hi_spec, read_r4(raw_data, pos, order), 4);
}
}
impl FTR {
#[inline(always)]
pub fn new() -> Self {
FTR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.test_num = read_u4(raw_data, pos, order);
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
self.test_flg = [read_uint8(raw_data, pos)];
self.opt_flag = [read_uint8(raw_data, pos)];
self.cycl_cnt = read_u4(raw_data, pos, order);
self.rel_vadr = read_u4(raw_data, pos, order);
self.rept_cnt = read_u4(raw_data, pos, order);
self.num_fail = read_u4(raw_data, pos, order);
self.xfail_ad = read_i4(raw_data, pos, order);
self.yfail_ad = read_i4(raw_data, pos, order);
self.vect_off = read_i2(raw_data, pos, order);
self.rtn_icnt = read_u2(raw_data, pos, order);
self.pgm_icnt = read_u2(raw_data, pos, order);
self.rtn_indx = read_kx_u2(raw_data, pos, order, self.rtn_icnt);
self.rtn_stat = read_kx_n1(raw_data, pos, self.rtn_icnt);
self.pgm_indx = read_kx_u2(raw_data, pos, order, self.pgm_icnt);
self.pgm_stat = read_kx_n1(raw_data, pos, self.pgm_icnt);
self.fail_pin = read_dn(raw_data, pos, order);
self.vect_nam = read_cn(raw_data, pos);
self.time_set = read_cn(raw_data, pos);
self.op_code = read_cn(raw_data, pos);
self.test_txt = read_cn(raw_data, pos);
self.alarm_id = read_cn(raw_data, pos);
self.prog_txt = read_cn(raw_data, pos);
self.rslt_txt = read_cn(raw_data, pos);
if *pos < raw_data.len() {
self.patg_num = read_uint8(raw_data, pos);
}
self.spin_map = read_dn(raw_data, pos, order);
}
}
impl STR {
#[inline(always)]
pub fn new() -> Self {
STR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.cont_flg = [read_uint8(raw_data, pos)];
self.test_num = read_u4(raw_data, pos, order);
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
self.psr_ref = read_u2(raw_data, pos, order);
self.test_flg = [read_uint8(raw_data, pos)];
self.log_typ = read_cn(raw_data, pos);
self.test_txt = read_cn(raw_data, pos);
self.alarm_id = read_cn(raw_data, pos);
self.prog_txt = read_cn(raw_data, pos);
self.rslt_txt = read_cn(raw_data, pos);
self.z_val = read_uint8(raw_data, pos);
self.fmu_flg = [read_uint8(raw_data, pos)];
self.mask_map = read_dn(raw_data, pos, order);
self.fal_map = read_dn(raw_data, pos, order);
self.cyc_cnt_t = read_u8(raw_data, pos, order);
self.totf_cnt = read_u4(raw_data, pos, order);
self.totl_cnt = read_u4(raw_data, pos, order);
self.cyc_base = read_u8(raw_data, pos, order);
self.bit_base = read_u4(raw_data, pos, order);
self.cond_cnt = read_u2(raw_data, pos, order);
self.lim_cnt = read_u2(raw_data, pos, order);
self.cyc_size = read_uint8(raw_data, pos);
self.pmr_size = read_uint8(raw_data, pos);
self.chn_size = read_uint8(raw_data, pos);
self.pat_size = read_uint8(raw_data, pos);
self.bit_size = read_uint8(raw_data, pos);
self.u1_size = read_uint8(raw_data, pos);
self.u2_size = read_uint8(raw_data, pos);
self.u3_size = read_uint8(raw_data, pos);
self.utx_size = read_uint8(raw_data, pos);
self.cap_bgn = read_u2(raw_data, pos, order);
self.lim_indx = read_kx_u2(raw_data, pos, order, self.lim_cnt);
self.lim_spec = read_kx_u4(raw_data, pos, order, self.lim_cnt);
self.cond_lst = read_kx_cn(raw_data, pos, self.cond_cnt);
self.cyc_cnt = read_u2(raw_data, pos, order);
self.cyc_ofst = read_kx_uf(raw_data, pos, order, self.cyc_cnt, self.cyc_size);
self.pmr_cnt = read_u2(raw_data, pos, order);
self.pmr_indx = read_kx_uf(raw_data, pos, order, self.pmr_cnt, self.pmr_size);
self.chn_cnt = read_u2(raw_data, pos, order);
self.chn_num = read_kx_uf(raw_data, pos, order, self.chn_cnt, self.chn_size);
self.exp_cnt = read_u2(raw_data, pos, order);
self.exp_data = read_kx_u1(raw_data, pos, self.exp_cnt);
self.cap_cnt = read_u2(raw_data, pos, order);
self.cap_data = read_kx_u1(raw_data, pos, self.cap_cnt);
self.new_cnt = read_u2(raw_data, pos, order);
self.new_data = read_kx_u1(raw_data, pos, self.new_cnt);
self.pat_cnt = read_u2(raw_data, pos, order);
self.pat_num = read_kx_uf(raw_data, pos, order, self.pat_cnt, self.pat_size);
self.bpos_cnt = read_u2(raw_data, pos, order);
self.bit_pos = read_kx_uf(raw_data, pos, order, self.bpos_cnt, self.bit_size);
self.usr1_cnt = read_u2(raw_data, pos, order);
self.usr1 = read_kx_uf(raw_data, pos, order, self.usr1_cnt, self.u1_size);
self.usr2_cnt = read_u2(raw_data, pos, order);
self.usr2 = read_kx_uf(raw_data, pos, order, self.usr2_cnt, self.u2_size);
self.usr3_cnt = read_u2(raw_data, pos, order);
self.usr3 = read_kx_uf(raw_data, pos, order, self.usr3_cnt, self.u3_size);
self.txt_cnt = read_u2(raw_data, pos, order);
self.user_txt = read_kx_cf(raw_data, pos, self.txt_cnt, self.utx_size);
}
}
impl BPS {
#[inline(always)]
pub fn new() -> Self {
BPS::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], _order: &ByteOrder) {
let pos = &mut 0;
self.seq_name = read_cn(raw_data, pos);
}
}
impl EPS {
pub fn new() -> Self {
EPS::default()
}
pub fn read_from_bytes(&mut self, _raw_data: &[u8], _order: &ByteOrder) {}
}
impl GDR {
#[inline(always)]
pub fn new() -> Self {
GDR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.fld_cnt = read_u2(raw_data, pos, order);
self.gen_data = read_vn(raw_data, pos, order, self.fld_cnt);
}
}
impl DTR {
#[inline(always)]
pub fn new() -> Self {
DTR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], _order: &ByteOrder) {
let pos = &mut 0;
self.text_dat = read_cn(raw_data, pos);
}
}
impl ReservedRec {
pub fn new() -> Self {
ReservedRec::default()
}
pub fn read_from_bytes(&mut self, raw_data: &[u8], _order: &ByteOrder) {
let mut dataclone = Vec::with_capacity(raw_data.len());
dataclone.extend_from_slice(raw_data);
self.raw_data = dataclone;
}
}
impl StdfRecord {
#[inline(always)]
pub fn new(rec_type: u64) -> Self {
match rec_type {
stdf_record_type::REC_PTR => StdfRecord::PTR(PTR::new()),
stdf_record_type::REC_MPR => StdfRecord::MPR(MPR::new()),
stdf_record_type::REC_FTR => StdfRecord::FTR(FTR::new()),
stdf_record_type::REC_STR => StdfRecord::STR(STR::new()),
stdf_record_type::REC_PIR => StdfRecord::PIR(PIR::new()),
stdf_record_type::REC_PRR => StdfRecord::PRR(PRR::new()),
stdf_record_type::REC_WIR => StdfRecord::WIR(WIR::new()),
stdf_record_type::REC_WRR => StdfRecord::WRR(WRR::new()),
stdf_record_type::REC_WCR => StdfRecord::WCR(WCR::new()),
stdf_record_type::REC_GDR => StdfRecord::GDR(GDR::new()),
stdf_record_type::REC_DTR => StdfRecord::DTR(DTR::new()),
stdf_record_type::REC_FAR => StdfRecord::FAR(FAR::new()),
stdf_record_type::REC_ATR => StdfRecord::ATR(ATR::new()),
stdf_record_type::REC_VUR => StdfRecord::VUR(VUR::new()),
stdf_record_type::REC_MIR => StdfRecord::MIR(MIR::new()),
stdf_record_type::REC_MRR => StdfRecord::MRR(MRR::new()),
stdf_record_type::REC_PCR => StdfRecord::PCR(PCR::new()),
stdf_record_type::REC_HBR => StdfRecord::HBR(HBR::new()),
stdf_record_type::REC_SBR => StdfRecord::SBR(SBR::new()),
stdf_record_type::REC_PMR => StdfRecord::PMR(PMR::new()),
stdf_record_type::REC_PGR => StdfRecord::PGR(PGR::new()),
stdf_record_type::REC_PLR => StdfRecord::PLR(PLR::new()),
stdf_record_type::REC_RDR => StdfRecord::RDR(RDR::new()),
stdf_record_type::REC_SDR => StdfRecord::SDR(SDR::new()),
stdf_record_type::REC_PSR => StdfRecord::PSR(PSR::new()),
stdf_record_type::REC_NMR => StdfRecord::NMR(NMR::new()),
stdf_record_type::REC_CNR => StdfRecord::CNR(CNR::new()),
stdf_record_type::REC_SSR => StdfRecord::SSR(SSR::new()),
stdf_record_type::REC_CDR => StdfRecord::CDR(CDR::new()),
stdf_record_type::REC_TSR => StdfRecord::TSR(TSR::new()),
stdf_record_type::REC_BPS => StdfRecord::BPS(BPS::new()),
stdf_record_type::REC_EPS => StdfRecord::EPS(EPS::new()),
stdf_record_type::REC_RESERVE => StdfRecord::ReservedRec(ReservedRec::new()),
_ => StdfRecord::InvalidRec(RecordHeader::new()),
}
}
#[inline(always)]
pub fn new_from_header(header: RecordHeader) -> Self {
match (header.typ, header.sub) {
(15, 10) => StdfRecord::PTR(PTR::new()),
(15, 15) => StdfRecord::MPR(MPR::new()),
(15, 20) => StdfRecord::FTR(FTR::new()),
(15, 30) => StdfRecord::STR(STR::new()),
(5, 10) => StdfRecord::PIR(PIR::new()),
(5, 20) => StdfRecord::PRR(PRR::new()),
(2, 10) => StdfRecord::WIR(WIR::new()),
(2, 20) => StdfRecord::WRR(WRR::new()),
(2, 30) => StdfRecord::WCR(WCR::new()),
(50, 10) => StdfRecord::GDR(GDR::new()),
(50, 30) => StdfRecord::DTR(DTR::new()),
(0, 10) => StdfRecord::FAR(FAR::new()),
(0, 20) => StdfRecord::ATR(ATR::new()),
(0, 30) => StdfRecord::VUR(VUR::new()),
(1, 10) => StdfRecord::MIR(MIR::new()),
(1, 20) => StdfRecord::MRR(MRR::new()),
(1, 30) => StdfRecord::PCR(PCR::new()),
(1, 40) => StdfRecord::HBR(HBR::new()),
(1, 50) => StdfRecord::SBR(SBR::new()),
(1, 60) => StdfRecord::PMR(PMR::new()),
(1, 62) => StdfRecord::PGR(PGR::new()),
(1, 63) => StdfRecord::PLR(PLR::new()),
(1, 70) => StdfRecord::RDR(RDR::new()),
(1, 80) => StdfRecord::SDR(SDR::new()),
(1, 90) => StdfRecord::PSR(PSR::new()),
(1, 91) => StdfRecord::NMR(NMR::new()),
(1, 92) => StdfRecord::CNR(CNR::new()),
(1, 93) => StdfRecord::SSR(SSR::new()),
(1, 94) => StdfRecord::CDR(CDR::new()),
(10, 30) => StdfRecord::TSR(TSR::new()),
(20, 10) => StdfRecord::BPS(BPS::new()),
(20, 20) => StdfRecord::EPS(EPS::new()),
(180 | 181, _) => StdfRecord::ReservedRec(ReservedRec::new()),
_ => StdfRecord::InvalidRec(header),
}
}
#[inline(always)]
pub fn get_type(&self) -> u64 {
match &self {
StdfRecord::PTR(_) => stdf_record_type::REC_PTR,
StdfRecord::MPR(_) => stdf_record_type::REC_MPR,
StdfRecord::FTR(_) => stdf_record_type::REC_FTR,
StdfRecord::STR(_) => stdf_record_type::REC_STR,
StdfRecord::PIR(_) => stdf_record_type::REC_PIR,
StdfRecord::PRR(_) => stdf_record_type::REC_PRR,
StdfRecord::WIR(_) => stdf_record_type::REC_WIR,
StdfRecord::WRR(_) => stdf_record_type::REC_WRR,
StdfRecord::WCR(_) => stdf_record_type::REC_WCR,
StdfRecord::GDR(_) => stdf_record_type::REC_GDR,
StdfRecord::DTR(_) => stdf_record_type::REC_DTR,
StdfRecord::TSR(_) => stdf_record_type::REC_TSR,
StdfRecord::MIR(_) => stdf_record_type::REC_MIR,
StdfRecord::MRR(_) => stdf_record_type::REC_MRR,
StdfRecord::PCR(_) => stdf_record_type::REC_PCR,
StdfRecord::HBR(_) => stdf_record_type::REC_HBR,
StdfRecord::SBR(_) => stdf_record_type::REC_SBR,
StdfRecord::PMR(_) => stdf_record_type::REC_PMR,
StdfRecord::PGR(_) => stdf_record_type::REC_PGR,
StdfRecord::PLR(_) => stdf_record_type::REC_PLR,
StdfRecord::RDR(_) => stdf_record_type::REC_RDR,
StdfRecord::SDR(_) => stdf_record_type::REC_SDR,
StdfRecord::PSR(_) => stdf_record_type::REC_PSR,
StdfRecord::NMR(_) => stdf_record_type::REC_NMR,
StdfRecord::CNR(_) => stdf_record_type::REC_CNR,
StdfRecord::SSR(_) => stdf_record_type::REC_SSR,
StdfRecord::CDR(_) => stdf_record_type::REC_CDR,
StdfRecord::FAR(_) => stdf_record_type::REC_FAR,
StdfRecord::ATR(_) => stdf_record_type::REC_ATR,
StdfRecord::VUR(_) => stdf_record_type::REC_VUR,
StdfRecord::BPS(_) => stdf_record_type::REC_BPS,
StdfRecord::EPS(_) => stdf_record_type::REC_EPS,
StdfRecord::ReservedRec(_) => stdf_record_type::REC_RESERVE,
StdfRecord::InvalidRec(_) => stdf_record_type::REC_INVALID,
}
}
#[inline(always)]
pub fn is_type(&self, rec_type: u64) -> bool {
(self.get_type() & rec_type) != 0
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
match self {
StdfRecord::PTR(ptr_rec) => ptr_rec.read_from_bytes(raw_data, order),
StdfRecord::MPR(mpr_rec) => mpr_rec.read_from_bytes(raw_data, order),
StdfRecord::FTR(ftr_rec) => ftr_rec.read_from_bytes(raw_data, order),
StdfRecord::STR(str_rec) => str_rec.read_from_bytes(raw_data, order),
StdfRecord::PIR(pir_rec) => pir_rec.read_from_bytes(raw_data, order),
StdfRecord::PRR(prr_rec) => prr_rec.read_from_bytes(raw_data, order),
StdfRecord::WIR(wir_rec) => wir_rec.read_from_bytes(raw_data, order),
StdfRecord::WRR(wrr_rec) => wrr_rec.read_from_bytes(raw_data, order),
StdfRecord::WCR(wcr_rec) => wcr_rec.read_from_bytes(raw_data, order),
StdfRecord::GDR(gdr_rec) => gdr_rec.read_from_bytes(raw_data, order),
StdfRecord::DTR(dtr_rec) => dtr_rec.read_from_bytes(raw_data, order),
StdfRecord::TSR(tsr_rec) => tsr_rec.read_from_bytes(raw_data, order),
StdfRecord::MIR(mir_rec) => mir_rec.read_from_bytes(raw_data, order),
StdfRecord::MRR(mrr_rec) => mrr_rec.read_from_bytes(raw_data, order),
StdfRecord::PCR(pcr_rec) => pcr_rec.read_from_bytes(raw_data, order),
StdfRecord::HBR(hbr_rec) => hbr_rec.read_from_bytes(raw_data, order),
StdfRecord::SBR(sbr_rec) => sbr_rec.read_from_bytes(raw_data, order),
StdfRecord::PMR(pmr_rec) => pmr_rec.read_from_bytes(raw_data, order),
StdfRecord::PGR(pgr_rec) => pgr_rec.read_from_bytes(raw_data, order),
StdfRecord::PLR(plr_rec) => plr_rec.read_from_bytes(raw_data, order),
StdfRecord::RDR(rdr_rec) => rdr_rec.read_from_bytes(raw_data, order),
StdfRecord::SDR(sdr_rec) => sdr_rec.read_from_bytes(raw_data, order),
StdfRecord::PSR(psr_rec) => psr_rec.read_from_bytes(raw_data, order),
StdfRecord::NMR(nmr_rec) => nmr_rec.read_from_bytes(raw_data, order),
StdfRecord::CNR(cnr_rec) => cnr_rec.read_from_bytes(raw_data, order),
StdfRecord::SSR(ssr_rec) => ssr_rec.read_from_bytes(raw_data, order),
StdfRecord::CDR(cdr_rec) => cdr_rec.read_from_bytes(raw_data, order),
StdfRecord::FAR(far_rec) => far_rec.read_from_bytes(raw_data, order),
StdfRecord::ATR(atr_rec) => atr_rec.read_from_bytes(raw_data, order),
StdfRecord::VUR(vur_rec) => vur_rec.read_from_bytes(raw_data, order),
StdfRecord::BPS(bps_rec) => bps_rec.read_from_bytes(raw_data, order),
StdfRecord::EPS(eps_rec) => eps_rec.read_from_bytes(raw_data, order),
StdfRecord::ReservedRec(reserve_rec) => reserve_rec.read_from_bytes(raw_data, order),
StdfRecord::InvalidRec(_) => (),
};
}
#[inline(always)]
pub fn read_from_bytes_with_header(
raw_data: &[u8],
order: &ByteOrder,
) -> Result<StdfRecord, StdfError> {
let header = RecordHeader::new().read_from_bytes(raw_data, order)?;
let expected_end_pos = 4 + header.len as usize;
if raw_data.len() < expected_end_pos {
return Err(StdfError {
code: 5,
msg: format!(
"Length of stdf field data ({} - 4 = {}) is less than what header specified ({})",
raw_data.len(),
raw_data.len() - 4,
header.len
),
});
}
let data_slice = &raw_data[4..expected_end_pos];
let mut rec = StdfRecord::new(header.get_type());
rec.read_from_bytes(data_slice, order);
Ok(rec)
}
}
impl RawDataElement {
#[inline(always)]
pub fn is_type(&self, rec_type: u64) -> bool {
(self.header.get_type() & rec_type) != 0
}
}
impl From<&RawDataElement> for StdfRecord {
#[inline(always)]
fn from(raw_element: &RawDataElement) -> Self {
let mut rec = StdfRecord::new_from_header(raw_element.header);
rec.read_from_bytes(&raw_element.raw_data, &raw_element.byte_order);
rec
}
}
impl From<RawDataElement> for StdfRecord {
#[inline(always)]
fn from(raw_element: RawDataElement) -> Self {
let mut rec = StdfRecord::new_from_header(raw_element.header);
rec.read_from_bytes(&raw_element.raw_data, &raw_element.byte_order);
rec
}
}
macro_rules! read_multi_byte_num {
($num_type:ty, $length:expr, $raw:ident, $pos:expr, $order:expr, $default:expr) => {{
let pos_after_read = *$pos + $length;
if pos_after_read <= $raw.len() {
let mut tmp = [0u8; $length];
tmp.copy_from_slice(&$raw[*$pos..pos_after_read]);
*$pos = pos_after_read;
match $order {
ByteOrder::LittleEndian => <$num_type>::from_le_bytes(tmp),
ByteOrder::BigEndian => <$num_type>::from_be_bytes(tmp),
}
} else {
$default
}
}};
}
macro_rules! read_multi_element {
($count:expr, $default:expr, $func:ident($($arg:tt)+)) => {
{
if $count != 0 {
let mut value = Vec::with_capacity($count as usize);
for _ in 0..$count {
value.push( $func($($arg)+) );
}
value
} else {
vec![$default; 0]
}
}
}
}
#[inline(always)]
pub(crate) fn read_uint8(raw_data: &[u8], pos: &mut usize) -> u8 {
if *pos < raw_data.len() {
let value = (*raw_data)[*pos];
*pos += 1;
value
} else {
0
}
}
#[inline(always)]
pub(crate) fn read_u2(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> U2 {
read_multi_byte_num!(U2, 2, raw_data, pos, order, 0)
}
#[inline(always)]
pub(crate) fn read_u4(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> U4 {
read_multi_byte_num!(U4, 4, raw_data, pos, order, 0)
}
#[inline(always)]
pub(crate) fn read_u8(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> U8 {
read_multi_byte_num!(U8, 8, raw_data, pos, order, 0)
}
#[inline(always)]
pub(crate) fn read_i1(raw_data: &[u8], pos: &mut usize) -> I1 {
if *pos < raw_data.len() {
let value = (*raw_data)[*pos] as I1;
*pos += 1;
value
} else {
0
}
}
#[inline(always)]
pub(crate) fn read_i2(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> I2 {
read_multi_byte_num!(I2, 2, raw_data, pos, order, 0)
}
#[inline(always)]
pub(crate) fn read_i4(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> I4 {
read_multi_byte_num!(I4, 4, raw_data, pos, order, 0)
}
#[inline(always)]
pub(crate) fn read_r4(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> R4 {
read_multi_byte_num!(R4, 4, raw_data, pos, order, 0.0)
}
#[inline(always)]
pub(crate) fn read_r8(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> R8 {
read_multi_byte_num!(R8, 8, raw_data, pos, order, 0.0)
}
#[inline(always)]
pub(crate) fn read_cn(raw_data: &[u8], pos: &mut usize) -> Cn {
let count = read_uint8(raw_data, pos) as usize;
let mut value = String::default();
if count != 0 {
let min_pos = std::cmp::min(*pos + count, raw_data.len());
value = bytes_to_string(&raw_data[*pos..min_pos]);
*pos = min_pos;
}
value
}
#[inline(always)]
pub(crate) fn read_sn(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> Sn {
let count = read_u2(raw_data, pos, order) as usize;
let mut value = String::default();
if count != 0 {
let min_pos = std::cmp::min(*pos + count, raw_data.len());
value = bytes_to_string(&raw_data[*pos..min_pos]);
*pos = min_pos;
}
value
}
#[inline(always)]
pub(crate) fn read_cf(raw_data: &[u8], pos: &mut usize, f: u8) -> Cf {
let mut value = String::default();
if f != 0 {
let pos_after_read = *pos + (f as usize);
if pos_after_read <= raw_data.len() {
value = bytes_to_string(&raw_data[*pos..pos_after_read]);
*pos = pos_after_read;
} else {
value = bytes_to_string(&raw_data[*pos..]);
*pos = raw_data.len();
}
}
value
}
#[inline(always)]
pub(crate) fn read_bn(raw_data: &[u8], pos: &mut usize) -> Bn {
let count = read_uint8(raw_data, pos) as usize;
if count != 0 {
let min_pos = std::cmp::min(*pos + count, raw_data.len());
let data_slice = &raw_data[*pos..min_pos];
*pos = min_pos;
let mut value = vec![0u8; data_slice.len()];
value.copy_from_slice(data_slice);
value
} else {
vec![0u8; 0]
}
}
#[inline(always)]
pub(crate) fn read_dn(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> Dn {
let bitcount = read_u2(raw_data, pos, order) as usize;
let bytecount = bitcount / 8 + bitcount % 8;
if bytecount != 0 {
let min_pos = std::cmp::min(*pos + bytecount, raw_data.len());
let data_slice = &raw_data[*pos..min_pos];
*pos = min_pos;
let mut value = vec![0u8; data_slice.len()];
value.copy_from_slice(data_slice);
value
} else {
vec![0u8; 0]
}
}
#[inline(always)]
pub(crate) fn read_kx_cn(raw_data: &[u8], pos: &mut usize, k: u16) -> KxCn {
read_multi_element!(k, String::new(), read_cn(raw_data, pos))
}
#[inline(always)]
pub(crate) fn read_kx_sn(raw_data: &[u8], pos: &mut usize, order: &ByteOrder, k: u16) -> KxSn {
read_multi_element!(k, String::new(), read_sn(raw_data, pos, order))
}
#[inline(always)]
pub(crate) fn read_kx_cf(raw_data: &[u8], pos: &mut usize, k: u16, f: u8) -> KxCf {
if k != 0 {
let mut value = Vec::with_capacity(k as usize);
for _ in 0..k {
value.push(read_cf(raw_data, pos, f));
}
value
} else {
vec!["".to_string(); 0]
}
}
#[inline(always)]
pub(crate) fn read_kx_u1(raw_data: &[u8], pos: &mut usize, k: u16) -> KxU1 {
read_multi_element!(k, 0, read_uint8(raw_data, pos))
}
#[inline(always)]
pub(crate) fn read_kx_u2(raw_data: &[u8], pos: &mut usize, order: &ByteOrder, k: u16) -> KxU2 {
read_multi_element!(k, 0, read_u2(raw_data, pos, order))
}
#[inline(always)]
pub(crate) fn read_kx_u4(raw_data: &[u8], pos: &mut usize, order: &ByteOrder, k: u16) -> KxU4 {
read_multi_element!(k, 0, read_u4(raw_data, pos, order))
}
#[inline(always)]
pub(crate) fn read_kx_u8(raw_data: &[u8], pos: &mut usize, order: &ByteOrder, k: u16) -> KxU8 {
read_multi_element!(k, 0, read_u8(raw_data, pos, order))
}
#[inline(always)]
pub(crate) fn read_kx_uf(
raw_data: &[u8],
pos: &mut usize,
order: &ByteOrder,
k: u16,
f: u8,
) -> KxUf {
if k != 0 {
match f {
1 => KxUf::F1(read_kx_u1(raw_data, pos, k)),
2 => KxUf::F2(read_kx_u2(raw_data, pos, order, k)),
4 => KxUf::F4(read_kx_u4(raw_data, pos, order, k)),
8 => KxUf::F8(read_kx_u8(raw_data, pos, order, k)),
_ => KxUf::F1(vec![0u8; 0]),
}
} else {
KxUf::F1(vec![0u8; 0])
}
}
#[inline(always)]
pub(crate) fn read_kx_r4(raw_data: &[u8], pos: &mut usize, order: &ByteOrder, k: u16) -> KxR4 {
read_multi_element!(k, 0.0, read_r4(raw_data, pos, order))
}
#[inline(always)]
pub(crate) fn read_kx_n1(raw_data: &[u8], pos: &mut usize, k: u16) -> KxN1 {
if k != 0 {
let bytecount = k / 2 + k % 2; let mut value = Vec::with_capacity(k as usize);
for i in 0..bytecount {
let tmp = read_uint8(raw_data, pos);
value.push(tmp & 0x0F);
if (2 * i + 1) < k {
value.push((tmp & 0xF0) >> 4);
}
}
value
} else {
vec![0u8; 0]
}
}
#[inline(always)]
pub(crate) fn read_v1(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> V1 {
let type_byte = if (*pos as usize) < raw_data.len() {
read_uint8(raw_data, pos)
} else {
0xF
};
match type_byte {
0 => V1::B0,
1 => V1::U1(read_uint8(raw_data, pos)),
2 => V1::U2(read_u2(raw_data, pos, order)),
3 => V1::U4(read_u4(raw_data, pos, order)),
4 => V1::I1(read_i1(raw_data, pos)),
5 => V1::I2(read_i2(raw_data, pos, order)),
6 => V1::I4(read_i4(raw_data, pos, order)),
7 => V1::R4(read_r4(raw_data, pos, order)),
8 => V1::R8(read_r8(raw_data, pos, order)),
10 => V1::Cn(read_cn(raw_data, pos)),
11 => V1::Bn(read_bn(raw_data, pos)),
12 => V1::Dn(read_dn(raw_data, pos, order)),
13 => V1::N1(read_uint8(raw_data, pos) & 0x0F),
_ => V1::Invalid,
}
}
#[inline(always)]
pub(crate) fn read_vn(raw_data: &[u8], pos: &mut usize, order: &ByteOrder, k: u16) -> Vn {
read_multi_element!(k, V1::Invalid, read_v1(raw_data, pos, order))
}
#[inline(always)]
pub(crate) fn bytes_to_string(data: &[u8]) -> String {
data.iter().map(|&x| x as char).collect()
}