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
//! Parameter objects for message assembly test steps.
use wireframe::message_assembler::{FrameSequence, MessageKey};
/// Parameters for creating a first frame.
#[derive(Debug)]
pub struct FirstFrameParams {
/// Message key.
pub key: MessageKey,
/// Metadata bytes.
pub metadata: Vec<u8>,
/// Body bytes.
pub body: Vec<u8>,
/// Whether this is the final frame.
pub is_last: bool,
}
impl FirstFrameParams {
/// Create parameters for a first frame with default values.
#[must_use]
pub fn new(key: MessageKey, body: Vec<u8>) -> Self {
Self {
key,
metadata: vec![],
body,
is_last: false,
}
}
/// Set metadata bytes.
#[must_use]
pub fn with_metadata(mut self, metadata: Vec<u8>) -> Self {
self.metadata = metadata;
self
}
/// Mark as the final frame.
#[must_use]
pub fn final_frame(mut self) -> Self {
self.is_last = true;
self
}
}
/// Parameters for creating a continuation frame.
#[derive(Debug)]
pub struct ContinuationFrameParams {
/// Message key.
pub key: MessageKey,
/// Optional sequence number.
pub sequence: Option<FrameSequence>,
/// Body bytes.
pub body: Vec<u8>,
/// Whether this is the final frame.
pub is_last: bool,
}
impl ContinuationFrameParams {
/// Create parameters for a continuation frame with default sequence 1.
#[must_use]
pub fn new(key: MessageKey, body: Vec<u8>) -> Self {
Self {
key,
sequence: Some(FrameSequence(1)),
body,
is_last: false,
}
}
/// Set the sequence number.
#[must_use]
pub fn with_sequence(mut self, sequence: FrameSequence) -> Self {
self.sequence = Some(sequence);
self
}
/// Mark as the final frame.
#[must_use]
pub fn final_frame(mut self) -> Self {
self.is_last = true;
self
}
}