Skip to main content

Module extensions

Module extensions 

Source
Expand description

Typed access to SigMF extension namespaces.

SigMF lets applications add fields to the global, captures, annotations, and collection objects under their own namespace prefix (for example antenna:gain), declaring each namespace and version in core:extensions. This crate preserves such fields as untyped JSON; this module adds a typed layer on top:

With the schema feature, extension_schema and validate_json_schema generate and apply JSON Schemas for extension types.

Setting extension fields does not modify core:extensions; declare the extension separately, e.g. with SigmfExtension::declaration.

§Example

use serde::{Deserialize, Serialize};
use sigmf::capture::Capture;
use sigmf::extensions::{ExtensionScope, SigmfExtension};

#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct Antenna {
    #[serde(rename = "antenna:port")]
    port: u8,
}

impl SigmfExtension for Antenna {
    const NAMESPACE: &'static str = "antenna";
    const VERSION: &'static str = "1.0.0";
    const SCOPE: ExtensionScope = ExtensionScope::Capture;
    const FIELDS: &'static [&'static str] = &["antenna:port"];
}

let mut capture = Capture::new(0);
capture.set_extension(&Antenna { port: 2 })?;
assert_eq!(capture.extra_fields()["antenna:port"], 2);
assert_eq!(capture.extension::<Antenna>()?, Antenna { port: 2 });

capture.remove_extension::<Antenna>()?;
assert!(capture.extra_fields().get("antenna:port").is_none());

Structs§

ExtensionRegistry
The set of extensions, by namespace and version, an application supports.

Enums§

ExtensionScope
The SigMF object in which an extension’s fields may appear.

Traits§

CropExtensionHandler
Transforms application-defined fields while a recording is cropped.
SigmfExtension
A typed view of one SigMF extension’s fields within a single scope.

Functions§

extension_schema
Generates the JSON Schema for extension type T.
validate_json_schema
Validates instance against the JSON Schema schema.