qubit_io_binary/stream/
methods.rs1use std::io::{
11 Result,
12 SeekFrom,
13};
14
15use qubit_io::{
16 Input,
17 Output,
18 Seekable,
19};
20
21use super::{
22 BinaryReader,
23 BinaryWriter,
24 BufferedBinaryReader,
25 BufferedBinaryWriter,
26 BufferedLeb128Reader,
27 BufferedLeb128Writer,
28 BufferedZigZagReader,
29 BufferedZigZagWriter,
30 Leb128Reader,
31 Leb128Writer,
32 ZigZagReader,
33 ZigZagWriter,
34};
35
36macro_rules! impl_input_methods {
37 ($type:ident<$($param:ident),+> where $($bound:tt)*) => {
38 impl<$($param),+> $type<$($param),+>
39 where
40 $($bound)*
41 {
42 #[inline(always)]
44 pub fn is_buffered(&self) -> bool {
45 Input::is_buffered(self)
46 }
47
48 #[inline(always)]
54 pub unsafe fn read_unchecked(
55 &mut self,
56 output: &mut [u8],
57 index: usize,
58 count: usize,
59 ) -> Result<usize> {
60 unsafe { Input::read_unchecked(self, output, index, count) }
62 }
63
64 #[inline(always)]
66 pub fn read(&mut self, output: &mut [u8]) -> Result<usize> {
67 Input::read(self, output)
68 }
69
70 #[inline(always)]
76 pub unsafe fn read_fully_unchecked(
77 &mut self,
78 output: &mut [u8],
79 index: usize,
80 count: usize,
81 ) -> Result<usize> {
82 unsafe { Input::read_fully_unchecked(self, output, index, count) }
84 }
85
86 #[inline(always)]
88 pub fn read_fully(&mut self, output: &mut [u8]) -> Result<usize> {
89 Input::read_fully(self, output)
90 }
91
92 #[inline(always)]
94 pub fn read_exactly(&mut self, output: &mut [u8]) -> Result<()> {
95 Input::read_exactly(self, output)
96 }
97 }
98 };
99}
100
101macro_rules! impl_output_methods {
102 ($type:ident<$($param:ident),+> where $($bound:tt)*) => {
103 impl<$($param),+> $type<$($param),+>
104 where
105 $($bound)*
106 {
107 #[inline(always)]
109 pub fn is_buffered(&self) -> bool {
110 Output::is_buffered(self)
111 }
112
113 #[inline(always)]
119 pub unsafe fn write_unchecked(
120 &mut self,
121 input: &[u8],
122 index: usize,
123 count: usize,
124 ) -> Result<usize> {
125 unsafe { Output::write_unchecked(self, input, index, count) }
127 }
128
129 #[inline(always)]
131 pub fn write(&mut self, input: &[u8]) -> Result<usize> {
132 Output::write(self, input)
133 }
134
135 #[inline(always)]
141 pub unsafe fn write_fully_unchecked(
142 &mut self,
143 input: &[u8],
144 index: usize,
145 count: usize,
146 ) -> Result<()> {
147 unsafe { Output::write_fully_unchecked(self, input, index, count) }
149 }
150
151 #[inline(always)]
153 pub fn write_fully(&mut self, input: &[u8]) -> Result<()> {
154 Output::write_fully(self, input)
155 }
156
157 #[inline(always)]
159 pub fn flush(&mut self) -> Result<()> {
160 Output::flush(self)
161 }
162 }
163 };
164}
165
166macro_rules! impl_seekable_methods {
167 ($type:ident<$($param:ident),+> where $($bound:tt)*) => {
168 impl<$($param),+> $type<$($param),+>
169 where
170 $($bound)*
171 {
172 #[inline(always)]
174 pub fn seek_to(&mut self, position: SeekFrom) -> Result<u64> {
175 Seekable::seek_to(self, position)
176 }
177 }
178 };
179}
180
181impl_input_methods!(BinaryReader<R, O> where R: Input<Item = u8>);
182impl_input_methods!(BufferedBinaryReader<R, O> where R: Input<Item = u8>);
183impl_input_methods!(Leb128Reader<R, P> where R: Input<Item = u8>);
184impl_input_methods!(BufferedLeb128Reader<R, P> where R: Input<Item = u8>);
185impl_input_methods!(ZigZagReader<R, P> where R: Input<Item = u8>);
186impl_input_methods!(BufferedZigZagReader<R, P> where R: Input<Item = u8>);
187
188impl_output_methods!(BinaryWriter<W, O> where W: Output<Item = u8>);
189impl_output_methods!(BufferedBinaryWriter<W, O> where W: Output<Item = u8>);
190impl_output_methods!(Leb128Writer<W> where W: Output<Item = u8>);
191impl_output_methods!(BufferedLeb128Writer<W> where W: Output<Item = u8>);
192impl_output_methods!(ZigZagWriter<W> where W: Output<Item = u8>);
193impl_output_methods!(BufferedZigZagWriter<W> where W: Output<Item = u8>);
194
195impl_seekable_methods!(BinaryReader<R, O> where R: Seekable<Unit = u8>);
196impl_seekable_methods!(BufferedBinaryReader<R, O> where R: Input<Item = u8> + Seekable<Unit = u8>);
197impl_seekable_methods!(Leb128Reader<R, P> where R: Seekable<Unit = u8>);
198impl_seekable_methods!(BufferedLeb128Reader<R, P> where R: Input<Item = u8> + Seekable<Unit = u8>);
199impl_seekable_methods!(ZigZagReader<R, P> where R: Seekable<Unit = u8>);
200impl_seekable_methods!(BufferedZigZagReader<R, P> where R: Input<Item = u8> + Seekable<Unit = u8>);
201impl_seekable_methods!(BinaryWriter<W, O> where W: Seekable<Unit = u8>);
202impl_seekable_methods!(BufferedBinaryWriter<W, O> where W: Output<Item = u8> + Seekable<Unit = u8>);
203impl_seekable_methods!(Leb128Writer<W> where W: Seekable<Unit = u8>);
204impl_seekable_methods!(BufferedLeb128Writer<W> where W: Output<Item = u8> + Seekable<Unit = u8>);
205impl_seekable_methods!(ZigZagWriter<W> where W: Seekable<Unit = u8>);
206impl_seekable_methods!(BufferedZigZagWriter<W> where W: Output<Item = u8> + Seekable<Unit = u8>);