Skip to main content

Module datatype

Module datatype 

Source
Expand description

SigMF sample datatypes (core:datatype).

A SigMF datatype string describes how each sample is stored in a .sigmf-data file. It is composed of:

  • a domain prefix: r for real or c for complex (interleaved I/Q),
  • a component type: f32, f64, i32, i16, u32, u16, i8, or u8,
  • for multi-byte components, an endianness suffix: _le or _be.

Examples include cf32_le, ri16_be, and ru8. All 28 core datatypes defined by the SigMF specification are supported; other strings are rejected. Datatype stores the validated string and exposes its parts through SampleDomain, ComponentType, Endianness, and ByteType.

use sigmf::datatype::{ComponentType, Datatype, Endianness, SampleDomain};
use std::str::FromStr;

let datatype = Datatype::from_str("cf32_le")?;
assert!(datatype.is_complex());
assert_eq!(datatype.get_domain(), SampleDomain::Complex);
assert_eq!(datatype.get_dtype(), Some(ComponentType::F32));
assert_eq!(datatype.get_endian(), Some(Endianness::LE));
assert_eq!(datatype.component_bytes(), 4);
assert_eq!(datatype.bytes_per_channel_sample(), 8);
assert_eq!(datatype.to_string(), "cf32_le");

assert!(Datatype::from_str("cf32").is_err()); // missing endianness

Structs§

Datatype
A validated SigMF core:datatype value such as cf32_le or ru8.

Enums§

ByteType
Single-byte component type of a datatype.
ComponentType
Multi-byte component type of a datatype.
Endianness
Byte order of a multi-byte component type.
SampleDomain
Whether samples are real-valued or complex-valued.