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
//! # Generic Frame Decoder
//!
//! Turn a growing byte buffer into **discrete messages** without allocating.
//!
//! **Why this is useful**
//! - Cleanly split a raw byte stream (from files/sockets) into protocol frames.
//! - Minimal overhead: the decoder only *looks* at bytes and tells you what to consume.
//! - Easy to test and reuse across transports.
//!
//! Implement `FrameDecoder` for your wire format; call `decode()` as chunks arrive.
//! On a full frame, you get `{ frame, consumed }`; on `NeedMore`, just read more bytes.
//!
//! See the IPC, TLV cases as examples.
use crateDecodeResult;
use io;
/// A trait for non-allocating, pull-based frame decoders.
///
/// Implement this trait for any wire format requiring message boundary detection,
/// such as Arrow IPC, protobuf, or custom binary protocols.
///
/// The decoder should never allocate or retain buffer data.
/// It must *only* inspect the provided slice and return either a complete frame
/// and how many bytes were consumed, or indicate that more data is needed.
///
/// ### Safety Contract
/// - The decoder musn't mutate or take ownership of the input buffer.
/// - It must not remove bytes itself—return `consumed`, the caller will drop them.
/// - It should always leave the buffer unchanged if returning `NeedMore`.