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:
SigmfExtensiondescribes a Rust type that maps to a set of namespaced fields in oneExtensionScope. Implement it by hand, or with#[derive(SigmfExtension)]when thederivefeature is enabled.- Typed getters and setters read and write those fields:
Metadata::global_extension,Capture::extension,Annotation::extension,CollectionMetadata::extension, and theirset_*/remove_*counterparts. ExtensionRegistryrecords which extensions an application understands so that validation (e.g.Metadata::validate_with_registry) can verify declared extensions and their fields.CropExtensionHandlerlets applications adjust extension fields when a recording is cropped.
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§
- Extension
Registry - The set of extensions, by namespace and version, an application supports.
Enums§
- Extension
Scope - The SigMF object in which an extension’s fields may appear.
Traits§
- Crop
Extension Handler - Transforms application-defined fields while a recording is cropped.
- Sigmf
Extension - 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
instanceagainst the JSON Schemaschema.