20 lines
734 B
Rust
20 lines
734 B
Rust
use klamath_rs_ext::{basic::encode_real8, records};
|
|
|
|
pub fn record(out: &mut Vec<u8>, tag: u16, data: &[u8]) {
|
|
out.extend_from_slice(&u16::try_from(data.len() + 4).unwrap().to_be_bytes());
|
|
out.extend_from_slice(&tag.to_be_bytes());
|
|
out.extend_from_slice(data);
|
|
}
|
|
|
|
pub fn library_header() -> Vec<u8> {
|
|
let mut bytes = Vec::new();
|
|
record(&mut bytes, records::RTAG_HEADER, &600_i16.to_be_bytes());
|
|
record(&mut bytes, records::RTAG_BGNLIB, &[0; 24]);
|
|
record(&mut bytes, records::RTAG_LIBNAME, b"test");
|
|
let units: Vec<u8> = [0.001, 1e-9]
|
|
.into_iter()
|
|
.flat_map(|v| encode_real8(v).unwrap().to_be_bytes())
|
|
.collect();
|
|
record(&mut bytes, records::RTAG_UNITS, &units);
|
|
bytes
|
|
}
|