paper_utils/
sheet.rs

1/*
2 * Copyright (c) Kia Shakiba
3 *
4 * This source code is licensed under the GNU AGPLv3 license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8pub mod builder;
9
10use std::net::TcpStream;
11use crate::stream::{Buffer, StreamError, write_buf};
12
13pub struct Sheet {
14	data: Buffer,
15}
16
17impl Sheet {
18	pub fn new(data: Buffer) -> Self {
19		Sheet {
20			data,
21		}
22	}
23
24	pub fn serialize(&self) -> &[u8] {
25		&self.data
26	}
27
28	pub fn data(&self) -> &Buffer {
29		&self.data
30	}
31
32	pub fn write_to_stream(&self, stream: &mut TcpStream) -> Result<(), StreamError> {
33		match write_buf(stream, &self.data) {
34			Ok(_) => Ok(()),
35			Err(_) => Err(StreamError::InvalidStream),
36		}
37	}
38}
39
40pub use crate::sheet::builder::*;