1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
use std::time::{Duration, SystemTime};

use crate::app::attr::*;
use crate::app::measurement::*;
use crate::app::variations::Variation;
use crate::app::*;

use crate::decode::DecodeLevel;
use crate::link::EndpointAddress;
use crate::master::association::AssociationConfig;
use crate::master::error::{AssociationError, CommandError, PollError, TaskError, TimeSyncError};
use crate::master::messages::{AssociationMsg, AssociationMsgType, MasterMsg, Message};
use crate::master::poll::{PollHandle, PollMsg};
use crate::master::request::{CommandHeaders, CommandMode, ReadRequest, TimeSyncProcedure};
use crate::master::tasks::command::CommandTask;
use crate::master::tasks::deadbands::WriteDeadBandsTask;
use crate::master::tasks::empty_response::EmptyResponseTask;
use crate::master::tasks::file_read::{FileReadTask, FileReaderType};
use crate::master::tasks::get_file_info::GetFileInfoTask;
use crate::master::tasks::read::SingleReadTask;
use crate::master::tasks::restart::{RestartTask, RestartType};
use crate::master::tasks::time::TimeSyncTask;
use crate::master::tasks::{NonReadTask, Task};
use crate::master::{
    DeadBandHeader, DirReadConfig, DirectoryReader, FileCredentials, FileError, FileInfo,
    FileReadConfig, FileReader, Headers, WriteError,
};
use crate::util::channel::Sender;
use crate::util::session::Enabled;

/// Handle to a master communication channel. This handle controls
/// a task running on the Tokio Runtime.
///
/// It provides a uniform API for all of the various types of communication channels supported
/// by the library.
#[derive(Debug, Clone)]
pub struct MasterChannel {
    sender: Sender<Message>,
}

/// Handle used to make requests against a particular outstation associated with the master channel
#[derive(Clone, Debug)]
pub struct AssociationHandle {
    address: EndpointAddress,
    master: MasterChannel,
}

/// Configuration for a MasterChannel
#[derive(Copy, Clone, Debug)]
pub struct MasterChannelConfig {
    /// Local DNP3 master address
    pub master_address: EndpointAddress,
    /// Decode-level for DNP3 objects
    pub decode_level: DecodeLevel,
    /// TX buffer size
    ///
    /// Must be at least 249.
    pub tx_buffer_size: BufferSize<249, 2048>,
    /// RX buffer size
    ///
    /// Must be at least 2048.
    pub rx_buffer_size: BufferSize<2048, 2048>,
}

impl MasterChannelConfig {
    /// Create a configuration with default buffer sizes, no decoding, and a default timeout of 5 seconds
    pub fn new(master_address: EndpointAddress) -> Self {
        Self {
            master_address,
            decode_level: DecodeLevel::nothing(),
            tx_buffer_size: BufferSize::default(),
            rx_buffer_size: BufferSize::default(),
        }
    }
}

impl MasterChannel {
    pub(crate) fn new(sender: Sender<Message>) -> Self {
        Self { sender }
    }

    /// enable communications
    pub async fn enable(&mut self) -> Result<(), Shutdown> {
        self.send_master_message(MasterMsg::EnableCommunication(Enabled::Yes))
            .await?;
        Ok(())
    }

    /// disable communications
    pub async fn disable(&mut self) -> Result<(), Shutdown> {
        self.send_master_message(MasterMsg::EnableCommunication(Enabled::No))
            .await?;
        Ok(())
    }

    /// Set the decoding level used by this master
    pub async fn set_decode_level(&mut self, decode_level: DecodeLevel) -> Result<(), Shutdown> {
        self.send_master_message(MasterMsg::SetDecodeLevel(decode_level))
            .await?;
        Ok(())
    }

    /// Get the current decoding level used by this master
    pub async fn get_decode_level(&mut self) -> Result<DecodeLevel, Shutdown> {
        let (tx, rx) = tokio::sync::oneshot::channel::<Result<DecodeLevel, Shutdown>>();
        self.send_master_message(MasterMsg::GetDecodeLevel(Promise::OneShot(tx)))
            .await?;
        rx.await?
    }

    /// Create a new association:
    /// * `address` is the DNP3 link-layer address of the outstation
    /// * `config` controls the behavior of the master for this outstation
    /// * `handler` is a callback trait invoked when events occur for this outstation
    pub async fn add_association(
        &mut self,
        address: EndpointAddress,
        config: AssociationConfig,
        read_handler: Box<dyn ReadHandler>,
        assoc_handler: Box<dyn AssociationHandler>,
        assoc_information: Box<dyn AssociationInformation>,
    ) -> Result<AssociationHandle, AssociationError> {
        let (tx, rx) = tokio::sync::oneshot::channel::<Result<(), AssociationError>>();
        self.send_master_message(MasterMsg::AddAssociation(
            address,
            config,
            read_handler,
            assoc_handler,
            assoc_information,
            Promise::OneShot(tx),
        ))
        .await?;
        rx.await?
            .map(|_| (AssociationHandle::new(address, self.clone())))
    }

    /// Remove an association
    /// * `address` is the DNP3 link-layer address of the outstation
    pub async fn remove_association(&mut self, address: EndpointAddress) -> Result<(), Shutdown> {
        self.send_master_message(MasterMsg::RemoveAssociation(address))
            .await?;
        Ok(())
    }

    async fn send_master_message(&mut self, msg: MasterMsg) -> Result<(), Shutdown> {
        self.sender.send(Message::Master(msg)).await?;
        Ok(())
    }

    async fn send_association_message(
        &mut self,
        address: EndpointAddress,
        msg: AssociationMsgType,
    ) -> Result<(), Shutdown> {
        self.sender
            .send(Message::Association(AssociationMsg {
                address,
                details: msg,
            }))
            .await
    }
}

impl AssociationHandle {
    /// constructor only used in the FFI
    #[doc(hidden)]
    #[cfg(feature = "ffi")]
    pub fn create(address: EndpointAddress, master: MasterChannel) -> Self {
        Self::new(address, master)
    }

    pub(crate) fn new(address: EndpointAddress, master: MasterChannel) -> Self {
        Self { address, master }
    }

    /// retrieve the outstation address of the association
    pub fn address(&self) -> EndpointAddress {
        self.address
    }

    /// Add a poll to the association
    /// * `request` defines what data is being requested
    /// * `period` defines how often the READ operation is performed
    pub async fn add_poll(
        &mut self,
        request: ReadRequest,
        period: Duration,
    ) -> Result<PollHandle, PollError> {
        let (tx, rx) = tokio::sync::oneshot::channel::<Result<PollHandle, PollError>>();
        self.send_poll_message(PollMsg::AddPoll(
            self.clone(),
            request,
            period,
            Promise::OneShot(tx),
        ))
        .await?;
        rx.await?
    }

    /// Remove the association from the master
    pub async fn remove(mut self) -> Result<(), Shutdown> {
        self.master
            .send_master_message(MasterMsg::RemoveAssociation(self.address))
            .await?;
        Ok(())
    }

    /// Perform an asynchronous READ request
    ///
    /// If successful, the [ReadHandler](crate::master::ReadHandler) will process the received measurement data
    pub async fn read(&mut self, request: ReadRequest) -> Result<(), TaskError> {
        let (tx, rx) = tokio::sync::oneshot::channel::<Result<(), TaskError>>();
        let task = SingleReadTask::new(request, Promise::OneShot(tx));
        self.send_task(task.wrap().wrap()).await?;
        rx.await?
    }

    /// Perform an asynchronous request with the specified function code and object headers
    ///
    /// This is useful for constructing various types of WRITE and FREEZE operations where
    /// an empty response is expected from the outstation, and the only indication of success
    /// are bits in IIN.2
    pub async fn send_and_expect_empty_response(
        &mut self,
        function: FunctionCode,
        headers: Headers,
    ) -> Result<(), WriteError> {
        let (tx, rx) = tokio::sync::oneshot::channel::<Result<(), WriteError>>();
        let task = EmptyResponseTask::new(function, headers, Promise::OneShot(tx));
        self.send_task(task.wrap().wrap()).await?;
        rx.await?
    }

    /// Perform an asynchronous READ request with a custom read handler
    ///
    /// If successful, the custom [ReadHandler](crate::master::ReadHandler) will process the received measurement data
    pub async fn read_with_handler(
        &mut self,
        request: ReadRequest,
        handler: Box<dyn ReadHandler>,
    ) -> Result<(), TaskError> {
        let (tx, rx) = tokio::sync::oneshot::channel::<Result<(), TaskError>>();
        let task = SingleReadTask::new_with_custom_handler(request, handler, Promise::OneShot(tx));
        self.send_task(task.wrap().wrap()).await?;
        rx.await?
    }

    /// Perform an asynchronous operate request
    ///
    /// The actual function code used depends on the value of the [CommandMode](crate::master::CommandMode).
    pub async fn operate(
        &mut self,
        mode: CommandMode,
        headers: CommandHeaders,
    ) -> Result<(), CommandError> {
        let (tx, rx) = tokio::sync::oneshot::channel::<Result<(), CommandError>>();
        let task = CommandTask::from_mode(mode, headers, Promise::OneShot(tx));
        self.send_task(task.wrap().wrap()).await?;
        rx.await?
    }

    /// Perform a WARM_RESTART operation
    ///
    /// Returns the delay from the outstation's response as a [Duration](std::time::Duration)
    pub async fn warm_restart(&mut self) -> Result<Duration, TaskError> {
        let (tx, rx) = tokio::sync::oneshot::channel::<Result<Duration, TaskError>>();
        let task = RestartTask::new(RestartType::WarmRestart, Promise::OneShot(tx));
        self.send_task(task.wrap().wrap()).await?;
        rx.await?
    }

    /// Perform a COLD_RESTART operation
    ///
    /// Returns the delay from the outstation's response as a [Duration](std::time::Duration)
    pub async fn cold_restart(&mut self) -> Result<Duration, TaskError> {
        let (tx, rx) = tokio::sync::oneshot::channel::<Result<Duration, TaskError>>();
        let task = RestartTask::new(RestartType::ColdRestart, Promise::OneShot(tx));
        self.send_task(task.wrap().wrap()).await?;
        rx.await?
    }

    /// Perform the specified time synchronization operation
    pub async fn synchronize_time(
        &mut self,
        procedure: TimeSyncProcedure,
    ) -> Result<(), TimeSyncError> {
        let (tx, rx) = tokio::sync::oneshot::channel::<Result<(), TimeSyncError>>();
        let task = TimeSyncTask::get_procedure(procedure, Promise::OneShot(tx));
        self.send_task(task.wrap().wrap()).await?;
        rx.await?
    }

    /// Perform write one or more headers of analog input dead-bands to the outstation
    pub async fn write_dead_bands(
        &mut self,
        headers: Vec<DeadBandHeader>,
    ) -> Result<(), WriteError> {
        let (tx, rx) = tokio::sync::oneshot::channel::<Result<(), WriteError>>();
        let task = WriteDeadBandsTask::new(headers, Promise::OneShot(tx));
        self.send_task(task.wrap().wrap()).await?;
        rx.await?
    }

    /// Trigger the master to issue a REQUEST_LINK_STATUS function in advance of the link status timeout
    ///
    /// This function is provided for testing purposes. Using the configured link status timeout
    /// is the preferred so that the master automatically issues these requests.
    ///
    /// If a [`TaskError::UnexpectedResponseHeaders`] is returned, the link might be alive
    /// but it didn't answer with the expected `LINK_STATUS`.
    pub async fn check_link_status(&mut self) -> Result<(), TaskError> {
        let (tx, rx) = tokio::sync::oneshot::channel::<Result<(), TaskError>>();
        self.send_task(Task::LinkStatus(Promise::OneShot(tx)))
            .await?;
        rx.await?
    }

    /// Start an operation to READ a file from the outstation using a [`FileReader`] to receive data
    pub async fn read_file<T: ToString>(
        &mut self,
        remote_file_path: T,
        config: FileReadConfig,
        reader: Box<dyn FileReader>,
        credentials: Option<FileCredentials>,
    ) -> Result<(), Shutdown> {
        let task = FileReadTask::start(
            remote_file_path.to_string(),
            config,
            FileReaderType::from_reader(reader),
            credentials,
        );
        self.send_task(Task::NonRead(NonReadTask::FileRead(task)))
            .await
    }

    /// Read a file directory
    pub async fn read_directory<T: ToString>(
        &mut self,
        dir_path: T,
        config: DirReadConfig,
        credentials: Option<FileCredentials>,
    ) -> Result<Vec<FileInfo>, FileError> {
        let (promise, rx) = Promise::one_shot();
        let reader = Box::new(DirectoryReader::new(promise));
        self.read_file(dir_path, config.into(), reader, credentials)
            .await?;
        rx.await?
    }

    /// Get information about a file
    pub async fn get_file_info<T: ToString>(
        &mut self,
        file_path: T,
    ) -> Result<FileInfo, FileError> {
        let (promise, reply) = Promise::one_shot();
        let task = GetFileInfoTask::new(file_path.to_string(), promise);
        self.send_task(Task::NonRead(NonReadTask::GetFileInfo(task)))
            .await?;
        reply.await?
    }

    async fn send_task(&mut self, task: Task) -> Result<(), Shutdown> {
        self.master
            .send_association_message(self.address, AssociationMsgType::QueueTask(task))
            .await
    }

    pub(crate) async fn send_poll_message(&mut self, msg: PollMsg) -> Result<(), Shutdown> {
        self.master
            .send_association_message(self.address, AssociationMsgType::Poll(msg))
            .await
    }
}

/// A generic callback type that must be invoked once and only once.
/// The user can select to implement it using FnOnce or a
/// one-shot reply channel
pub(crate) enum Promise<T> {
    /// nothing happens when the promise is completed
    None,
    /// one-shot reply channel is consumed when the promise is completed
    OneShot(tokio::sync::oneshot::Sender<T>),
}

impl<T> Promise<T> {
    pub(crate) fn one_shot() -> (Self, tokio::sync::oneshot::Receiver<T>) {
        let (tx, rx) = tokio::sync::oneshot::channel();
        (Self::OneShot(tx), rx)
    }

    pub(crate) fn complete(self, value: T) {
        match self {
            Promise::None => {}
            Promise::OneShot(s) => {
                s.send(value).ok();
            }
        }
    }
}

/// Task types used in [`AssociationInformation`]
#[cfg_attr(not(feature = "ffi"), non_exhaustive)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum TaskType {
    /// User-defined read request
    UserRead,
    /// Periodic poll task
    PeriodicPoll,
    /// Startup integrity scan
    StartupIntegrity,
    /// Automatic event scan caused by `RESTART` IIN bit detection
    AutoEventScan,
    /// Command request
    Command,
    /// Clear `RESTART` IIN bit
    ClearRestartBit,
    /// Enable unsolicited startup request
    EnableUnsolicited,
    /// Disable unsolicited startup request
    DisableUnsolicited,
    /// Time synchronisation task
    TimeSync,
    /// Cold or warm restart task
    Restart,
    /// Write dead-bands
    WriteDeadBands,
    /// Generic task which
    GenericEmptyResponse(FunctionCode),
    /// Read a file from the outstation
    FileRead,
    /// Get information about a file
    GetFileInfo,
}

/// callbacks associated with a single master to outstation association
pub trait AssociationHandler: Send + Sync {
    /// Retrieve the system time used for time synchronization
    fn get_current_time(&self) -> Option<Timestamp> {
        Timestamp::try_from_system_time(SystemTime::now())
    }
}

/// Informational callbacks that can be used to monitor master communication
/// to a particular outstation. Useful for assessing communication health.
pub trait AssociationInformation: Send + Sync {
    /// Called when a new task is started
    fn task_start(&mut self, _task_type: TaskType, _fc: FunctionCode, _seq: Sequence) {}
    /// Called when a task successfully completes
    fn task_success(&mut self, _task_type: TaskType, _fc: FunctionCode, _seq: Sequence) {}
    /// Called when a task fails
    fn task_fail(&mut self, _task_type: TaskType, _error: TaskError) {}

    /// Called when an unsolicited response is received
    fn unsolicited_response(&mut self, _is_duplicate: bool, _seq: Sequence) {}
}

pub(crate) struct NullAssociationInformation;

impl AssociationInformation for NullAssociationInformation {}

/// Information about the object header and specific variation
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct HeaderInfo {
    /// underlying variation in the response
    pub variation: Variation,
    /// qualifier code used in the response
    pub qualifier: QualifierCode,
    /// true if the received variation is an event type, false otherwise
    pub is_event: bool,
    /// true if a flags byte is present on the underlying variation, false otherwise
    pub has_flags: bool,
}

impl HeaderInfo {
    pub(crate) fn new(
        variation: Variation,
        qualifier: QualifierCode,
        is_event: bool,
        has_flags: bool,
    ) -> Self {
        Self {
            variation,
            qualifier,
            is_event,
            has_flags,
        }
    }
}

/// Describes the source of a read event
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ReadType {
    /// Startup integrity poll
    StartupIntegrity,
    /// Unsolicited message
    Unsolicited,
    /// Single poll requested by the user
    SinglePoll,
    /// Periodic poll configured by the user
    PeriodicPoll,
}

/// Trait used to process measurement data received from an outstation
pub trait ReadHandler: Send + Sync {
    /// Called as the first action before any of the type-specific handle methods are invoked
    ///
    /// `read_type` provides information about what triggered the call, e.g. response vs unsolicited
    /// `header` provides the full response header
    ///
    /// Note: The operation may or may not be async depending
    #[allow(unused_variables)]
    fn begin_fragment(&mut self, read_type: ReadType, header: ResponseHeader) -> MaybeAsync<()> {
        MaybeAsync::ready(())
    }

    /// Called as the last action after all of the type-specific handle methods have been invoked
    ///
    /// `read_type` provides information about what triggered the call, e.g. response vs unsolicited
    /// `header` provides the full response header
    ///
    /// Note: The operation may or may not be async depending. A typical use case for using async
    /// here would be to publish a message to an async MPSC.
    #[allow(unused_variables)]
    fn end_fragment(&mut self, read_type: ReadType, header: ResponseHeader) -> MaybeAsync<()> {
        MaybeAsync::ready(())
    }

    /// Process an object header of `BinaryInput` values
    #[allow(unused_variables)]
    fn handle_binary_input(
        &mut self,
        info: HeaderInfo,
        iter: &mut dyn Iterator<Item = (BinaryInput, u16)>,
    ) {
    }

    /// Process an object header of `DoubleBitBinaryInput` values
    #[allow(unused_variables)]
    fn handle_double_bit_binary_input(
        &mut self,
        info: HeaderInfo,
        iter: &mut dyn Iterator<Item = (DoubleBitBinaryInput, u16)>,
    ) {
    }

    /// Process an object header of `BinaryOutputStatus` values
    #[allow(unused_variables)]
    fn handle_binary_output_status(
        &mut self,
        info: HeaderInfo,
        iter: &mut dyn Iterator<Item = (BinaryOutputStatus, u16)>,
    ) {
    }

    /// Process an object header of `Counter` values
    #[allow(unused_variables)]
    fn handle_counter(&mut self, info: HeaderInfo, iter: &mut dyn Iterator<Item = (Counter, u16)>) {
    }

    /// Process an object header of `FrozenCounter` values
    #[allow(unused_variables)]
    fn handle_frozen_counter(
        &mut self,
        info: HeaderInfo,
        iter: &mut dyn Iterator<Item = (FrozenCounter, u16)>,
    ) {
    }

    /// Process an object header of `AnalogInput` values
    #[allow(unused_variables)]
    fn handle_analog_input(
        &mut self,
        info: HeaderInfo,
        iter: &mut dyn Iterator<Item = (AnalogInput, u16)>,
    ) {
    }

    /// Process an object header of `FrozenAnalogInput` values
    #[allow(unused_variables)]
    fn handle_frozen_analog_input(
        &mut self,
        info: HeaderInfo,
        iter: &mut dyn Iterator<Item = (FrozenAnalogInput, u16)>,
    ) {
    }

    /// Process an object header of `AnalogInputDeadBand` values
    #[allow(unused_variables)]
    fn handle_analog_input_dead_band(
        &mut self,
        info: HeaderInfo,
        iter: &mut dyn Iterator<Item = (AnalogInputDeadBand, u16)>,
    ) {
    }

    /// Process an object header of `AnalogOutputStatus` values
    #[allow(unused_variables)]
    fn handle_analog_output_status(
        &mut self,
        info: HeaderInfo,
        iter: &mut dyn Iterator<Item = (AnalogOutputStatus, u16)>,
    ) {
    }

    /// Process an object header of octet string values
    #[allow(unused_variables)]
    fn handle_octet_string<'a>(
        &mut self,
        info: HeaderInfo,
        iter: &'a mut dyn Iterator<Item = (&'a [u8], u16)>,
    ) {
    }

    /// Process a device attribute
    #[allow(unused_variables)]
    fn handle_device_attribute(&mut self, info: HeaderInfo, attr: AnyAttribute) {}
}

pub(crate) fn handle_attribute(
    var: Variation,
    qualifier: QualifierCode,
    attr: &Option<Attribute>,
    handler: &mut dyn ReadHandler,
) {
    if let Some(attr) = attr {
        match AnyAttribute::try_from(attr) {
            Ok(attr) => {
                handler
                    .handle_device_attribute(HeaderInfo::new(var, qualifier, false, false), attr);
            }
            Err(err) => {
                tracing::warn!(
                    "Expected attribute type {:?} but received {:?}",
                    err.expected,
                    err.actual
                );
            }
        }
    }
}

/// read handler that does nothing
#[derive(Copy, Clone)]
pub(crate) struct NullReadHandler;
impl ReadHandler for NullReadHandler {}