pub struct ExtensionRegistry { /* private fields */ }Expand description
A registry for extension field handlers per RFC 7822.
This allows applications to register custom handlers for non-NTS extension field types. The registry dispatches incoming extension fields to the appropriate handler based on field type.
§Examples
use ntp_proto::extension::{ExtensionRegistry, ExtensionHandler, ExtensionField};
use std::io;
// Define a custom handler
struct MyHandler;
impl ExtensionHandler for MyHandler {
fn field_type(&self) -> u16 {
0x4000 // Custom field type
}
fn handle(&self, value: &[u8]) -> io::Result<()> {
println!("Received extension field with {} bytes", value.len());
Ok(())
}
}
// Create registry and register handler
let mut registry = ExtensionRegistry::new();
registry.register(Box::new(MyHandler));
// Dispatch an extension field
let field = ExtensionField {
field_type: 0x4000,
value: vec![1, 2, 3, 4],
};
registry.dispatch(&field).unwrap();Implementations§
Source§impl ExtensionRegistry
impl ExtensionRegistry
Sourcepub fn new() -> ExtensionRegistry
pub fn new() -> ExtensionRegistry
Create a new empty extension field registry.
Sourcepub fn register(&mut self, handler: Box<dyn ExtensionHandler>)
pub fn register(&mut self, handler: Box<dyn ExtensionHandler>)
Register a handler for a specific extension field type.
If a handler for this field type is already registered, it will be replaced.
Sourcepub fn dispatch(&self, field: &ExtensionField) -> Result<(), Error>
pub fn dispatch(&self, field: &ExtensionField) -> Result<(), Error>
Dispatch an extension field to the registered handler.
Returns Ok(()) if a handler was found and successfully processed the
field. Returns an error if no handler is registered for this field type
or if the handler returns an error.
Sourcepub fn dispatch_all(
&self,
fields: &[ExtensionField],
require_handlers: bool,
) -> Result<(), Error>
pub fn dispatch_all( &self, fields: &[ExtensionField], require_handlers: bool, ) -> Result<(), Error>
Dispatch all extension fields in a list.
Processes each field in sequence. Stops and returns an error on the
first failure. Ignores fields with no registered handler unless
require_handlers is true.
Sourcepub fn has_handler(&self, field_type: u16) -> bool
pub fn has_handler(&self, field_type: u16) -> bool
Check if a handler is registered for the given field type.