sheave_core/messages/
video.rs1use std::{
2 borrow::Cow,
3 collections::{
4 BinaryHeap,
5 VecDeque
6 },
7 ffi::CString,
8 io::Result as IOResult,
9 ops::{
10 Deref,
11 DerefMut,
12 Index,
13 IndexMut
14 },
15 rc::Rc,
16 slice::SliceIndex,
17 sync::Arc
18};
19use crate::{
20 Decoder,
21 Encoder,
22 ByteBuffer
23};
24use super::{
25 Channel,
26 ChunkData,
27 headers::MessageType
28};
29
30#[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord)]
31pub struct Video(Vec<u8>);
32
33impl Video {
34 pub fn new(bytes: Vec<u8>) -> Self {
35 Self(bytes)
36 }
37
38 pub fn get_bytes(&self) -> &[u8] {
39 &self.0
40 }
41}
42
43impl<const N: usize> From<[u8; N]> for Video {
44 fn from(bytes: [u8; N]) -> Self {
45 Self(bytes.into())
46 }
47}
48
49impl<const N: usize> From<&[u8; N]> for Video {
50 fn from(bytes: &[u8; N]) -> Self {
51 Self(bytes.into())
52 }
53}
54
55impl<const N: usize> From<&mut [u8; N]> for Video {
56 fn from(bytes: &mut [u8; N]) -> Self {
57 Self(bytes.into())
58 }
59}
60
61impl From<&[u8]> for Video {
62 fn from(bytes: &[u8]) -> Self {
63 Self(bytes.into())
64 }
65}
66
67impl From<&mut [u8]> for Video {
68 fn from(bytes: &mut [u8]) -> Self {
69 Self(bytes.into())
70 }
71}
72
73impl From<&str> for Video {
74 fn from(s: &str) -> Self {
75 Self(s.into())
76 }
77}
78
79impl From<String> for Video {
80 fn from(s: String) -> Self {
81 Self(s.into())
82 }
83}
84
85impl From<CString> for Video {
86 fn from(s: CString) -> Self {
87 Self(s.into())
88 }
89}
90
91impl<'a> From<Cow<'a, [u8]>> for Video {
92 fn from(bytes: Cow<'a, [u8]>) -> Self {
93 Self(bytes.into())
94 }
95}
96
97impl From<Box<[u8]>> for Video {
98 fn from(bytes: Box<[u8]>) -> Self {
99 Self(bytes.into())
100 }
101}
102
103impl From<VecDeque<u8>> for Video {
104 fn from(bytes: VecDeque<u8>) -> Self {
105 Self(bytes.into())
106 }
107}
108
109impl From<BinaryHeap<u8>> for Video {
110 fn from(bytes: BinaryHeap<u8>) -> Self {
111 Self(bytes.into())
112 }
113}
114
115impl From<Video> for Vec<u8> {
116 fn from(video: Video) -> Self {
117 video.0
118 }
119}
120
121impl<'a> From<Video> for Cow<'a, [u8]> {
122 fn from(video: Video) -> Self {
123 video.0.into()
124 }
125}
126
127impl<'a> From<&'a Video> for Cow<'a, [u8]> {
128 fn from(video: &'a Video) -> Self {
129 Cow::from(&video.0)
130 }
131}
132
133impl From<Video> for Box<[u8]> {
134 fn from(video: Video) -> Self {
135 video.0.into()
136 }
137}
138
139impl From<Video> for VecDeque<u8> {
140 fn from(video: Video) -> Self {
141 video.0.into()
142 }
143}
144
145impl From<Video> for BinaryHeap<u8> {
146 fn from(video: Video) -> Self {
147 video.0.into()
148 }
149}
150
151impl From<Video> for Rc<[u8]> {
152 fn from(video: Video) -> Self {
153 video.0.into()
154 }
155}
156
157impl From<Video> for Arc<[u8]> {
158 fn from(video: Video) -> Self {
159 video.0.into()
160 }
161}
162
163impl<I: SliceIndex<[u8]>> Index<I> for Video {
164 type Output = I::Output;
165
166 fn index(&self, index: I) -> &Self::Output {
167 self.0.index(index)
168 }
169}
170
171impl<I: SliceIndex<[u8]>> IndexMut<I> for Video {
172 fn index_mut(&mut self, index: I) -> &mut Self::Output {
173 self.0.index_mut(index)
174 }
175}
176
177impl Deref for Video {
178 type Target = Vec<u8>;
179
180 fn deref(&self) -> &Self::Target {
181 &self.0
182 }
183}
184
185impl DerefMut for Video {
186 fn deref_mut(&mut self) -> &mut Self::Target {
187 &mut self.0
188 }
189}
190
191impl<const N: usize> PartialEq<[u8; N]> for Video {
192 fn eq(&self, other: &[u8; N]) -> bool {
193 self.0.eq(other)
194 }
195}
196
197impl<const N: usize> PartialEq<&[u8; N]> for Video {
198 fn eq(&self, other: &&[u8; N]) -> bool {
199 self.0.eq(other)
200 }
201}
202
203impl PartialEq<[u8]> for Video {
204 fn eq(&self, other: &[u8]) -> bool {
205 self.0.eq(other)
206 }
207}
208
209impl PartialEq<&[u8]> for Video {
210 fn eq(&self, other: &&[u8]) -> bool {
211 self.0.eq(other)
212 }
213}
214
215impl PartialEq<&mut [u8]> for Video {
216 fn eq(&self, other: &&mut [u8]) -> bool {
217 self.0.eq(other)
218 }
219}
220
221impl PartialEq<Vec<u8>> for Video {
222 fn eq(&self, other: &Vec<u8>) -> bool {
223 self.0.eq(other)
224 }
225}
226
227impl PartialEq<Video> for [u8] {
228 fn eq(&self, other: &Video) -> bool {
229 self.eq(&other.0)
230 }
231}
232
233impl PartialEq<Video> for &[u8] {
234 fn eq(&self, other: &Video) -> bool {
235 self.eq(&other.0)
236 }
237}
238
239impl PartialEq<Video> for &mut [u8] {
240 fn eq(&self, other: &Video) -> bool {
241 self.eq(&other.0)
242 }
243}
244
245impl PartialEq<Video> for Cow<'_, [u8]> {
246 fn eq(&self, other: &Video) -> bool {
247 self.eq(&other.0)
248 }
249}
250
251impl PartialEq<Video> for Vec<u8> {
252 fn eq(&self, other: &Video) -> bool {
253 self.eq(&other.0)
254 }
255}
256
257impl PartialEq<Video> for VecDeque<u8> {
258 fn eq(&self, other: &Video) -> bool {
259 self.eq(&other.0)
260 }
261}
262
263impl ChunkData for Video {
264 const CHANNEL: Channel = Channel::Video;
265 const MESSAGE_TYPE: MessageType = MessageType::Video;
266}
267
268impl Decoder<Video> for ByteBuffer {
269 fn decode(&mut self) -> IOResult<Video> {
270 let remained = self.remained();
271 self.get_bytes(remained).map(|bytes| Video::new(bytes.to_vec()))
272 }
273}
274
275impl Encoder<Video> for ByteBuffer {
276 fn encode(&mut self, video: &Video) {
277 self.put_bytes(video.get_bytes());
278 }
279}