Skip to main content

SigmfExtension

Derive Macro SigmfExtension 

Source
#[derive(SigmfExtension)]
{
    // Attributes available to this derive:
    #[sigmf]
}
Expand description

Derives extensions::SigmfExtension for a struct of namespaced fields.

Every field needs an explicit #[serde(rename = "namespace:field")] that matches the container’s #[sigmf(namespace = "...")]. The required container attributes are namespace, version, and scope (one of global, capture, annotation, or collection). If the crate is renamed in Cargo.toml, pass its path with crate = "...".

use serde::{Deserialize, Serialize};
use sigmf::SigmfExtension;

#[derive(Serialize, Deserialize, SigmfExtension)]
#[sigmf(namespace = "lab", version = "1.0.0", scope = "capture")]
struct LabGain {
    #[serde(rename = "lab:gain_db")]
    gain_db: f64,
}

use sigmf::extensions::SigmfExtension as _;
assert_eq!(LabGain::FIELDS, ["lab:gain_db"]);

Implements sigmf::extensions::SigmfExtension for a struct.

§Container attributes

#[sigmf(...)] on the struct accepts:

  • namespace = "..." (required): the extension namespace. It must be a non-empty ASCII identifier (letters, digits, _, -) other than core.
  • version = "..." (required): the extension version declared in core:extensions.
  • scope = "..." (required): where the fields live: global, capture, annotation, or collection.
  • crate = "..." (optional): path to the sigmf library if it is renamed in Cargo.toml; defaults to ::sigmf.

§Field requirements

The struct must have named fields, each with an explicit #[serde(rename = "<namespace>:<name>")] that uses the container’s namespace. Serde attributes that change the wire shape (flatten, skip*, with, rename_all, tag, untagged, transparent, …) are rejected so that the generated FIELDS list always matches the serialized keys.

§Example

ⓘ
use serde::{Deserialize, Serialize};
use sigmf::SigmfExtension;

#[derive(Serialize, Deserialize, SigmfExtension)]
#[sigmf(namespace = "lab", version = "1.0.0", scope = "global")]
struct LabReceiver {
    #[serde(rename = "lab:gain_db")]
    gain_db: f64,
    #[serde(rename = "lab:device_id", skip_serializing_if = "Option::is_none")]
    device_id: Option<String>,
}