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
use std::collections::VecDeque;
use bytes::Bytes;
use crate::Message;

/// Builder type for [`Message`].
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MessageBuilder {
	frames: VecDeque<Bytes>,
}

impl MessageBuilder {
	/// Construct empty [`MessageBuilder`].
	pub fn new() -> Self {
        Self {
            frames: Default::default(),
        }
    }

	/// Push a frame to the [`Message`].
	pub fn frame(mut self, frame: Bytes) -> Self {
		self.frames.push_back(frame);
		self
	}

	/// Extend the current [`Message`] with another [`Message`].
	pub fn message(mut self, mut msg: Message) -> Self {
		self.frames.append(&mut msg.frames);
		self
	}

	/// Finalize and build the [`Message`].
	pub fn build(self) -> Message {
        Message {
            frames: self.frames,
        }
    }
}