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
// Copyright Peter G. Bower 2025-2026.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//! # Generic Frame Encoder
//!
//! Serialise protocol frames into **on-the-wire bytes** efficiently.
//!
//! **Purpose**
//! - Central place to define how a frame becomes a byte sequence i.e., length-prefix, TLV, IPC, etc..
//! - Keeps responsibility for buffer management with the caller.
//! - Plays nicely with any sink incl., files, sockets, custom transports.
//!
//! Implement `FrameEncoder` for a custom format; call `encode()` to append the wire bytes into a buffer.
use io;
use crateStreamBuffer;
/// Implement this trait for any wire format requiring message serialisation,
/// such as Arrow IPC, protobuf, or custom binary protocols.
///
/// The encoder must only append to the provided buffer and must not retain references
/// or have side-effects to any data passed in.
///
/// ### Safety Contract
/// - The encoder must not mutate the frame being encoded.
/// - The encoder must not retain references to input data after the call.
/// - All writes must be bounded to the provided buffer.