gio/auto/data_input_stream.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{
6 ffi, AsyncResult, BufferedInputStream, Cancellable, DataStreamByteOrder, DataStreamNewlineType,
7 FilterInputStream, InputStream, Seekable,
8};
9use glib::{
10 prelude::*,
11 signal::{connect_raw, SignalHandlerId},
12 translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17 /// Data input stream implements [`InputStream`][crate::InputStream] and includes functions
18 /// for reading structured data directly from a binary input stream.
19 ///
20 /// ## Properties
21 ///
22 ///
23 /// #### `byte-order`
24 /// The :byte-order property determines the byte ordering that
25 /// is used when reading multi-byte entities (such as integers)
26 /// from the stream.
27 ///
28 /// Readable | Writeable
29 ///
30 ///
31 /// #### `newline-type`
32 /// The :newline-type property determines what is considered
33 /// as a line ending when reading complete lines from the stream.
34 ///
35 /// Readable | Writeable
36 /// <details><summary><h4>BufferedInputStream</h4></summary>
37 ///
38 ///
39 /// #### `buffer-size`
40 /// The size of the backend buffer, in bytes.
41 ///
42 /// Readable | Writeable | Construct
43 /// </details>
44 /// <details><summary><h4>FilterInputStream</h4></summary>
45 ///
46 ///
47 /// #### `base-stream`
48 /// The underlying base stream on which the I/O ops will be done.
49 ///
50 /// Readable | Writeable | Construct Only
51 ///
52 ///
53 /// #### `close-base-stream`
54 /// Whether the base stream should be closed when the filter stream is closed.
55 ///
56 /// Readable | Writeable | Construct
57 /// </details>
58 ///
59 /// # Implements
60 ///
61 /// [`DataInputStreamExt`][trait@crate::prelude::DataInputStreamExt], [`BufferedInputStreamExt`][trait@crate::prelude::BufferedInputStreamExt], [`FilterInputStreamExt`][trait@crate::prelude::FilterInputStreamExt], [`InputStreamExt`][trait@crate::prelude::InputStreamExt], [`trait@glib::ObjectExt`], [`SeekableExt`][trait@crate::prelude::SeekableExt], [`DataInputStreamExtManual`][trait@crate::prelude::DataInputStreamExtManual], [`InputStreamExtManual`][trait@crate::prelude::InputStreamExtManual]
62 #[doc(alias = "GDataInputStream")]
63 pub struct DataInputStream(Object<ffi::GDataInputStream, ffi::GDataInputStreamClass>) @extends BufferedInputStream, FilterInputStream, InputStream, @implements Seekable;
64
65 match fn {
66 type_ => || ffi::g_data_input_stream_get_type(),
67 }
68}
69
70impl DataInputStream {
71 pub const NONE: Option<&'static DataInputStream> = None;
72
73 /// Creates a new data input stream for the @base_stream.
74 /// ## `base_stream`
75 /// a #GInputStream.
76 ///
77 /// # Returns
78 ///
79 /// a new #GDataInputStream.
80 #[doc(alias = "g_data_input_stream_new")]
81 pub fn new(base_stream: &impl IsA<InputStream>) -> DataInputStream {
82 unsafe {
83 from_glib_full(ffi::g_data_input_stream_new(
84 base_stream.as_ref().to_glib_none().0,
85 ))
86 }
87 }
88
89 // rustdoc-stripper-ignore-next
90 /// Creates a new builder-pattern struct instance to construct [`DataInputStream`] objects.
91 ///
92 /// This method returns an instance of [`DataInputStreamBuilder`](crate::builders::DataInputStreamBuilder) which can be used to create [`DataInputStream`] objects.
93 pub fn builder() -> DataInputStreamBuilder {
94 DataInputStreamBuilder::new()
95 }
96}
97
98impl Default for DataInputStream {
99 fn default() -> Self {
100 glib::object::Object::new::<Self>()
101 }
102}
103
104// rustdoc-stripper-ignore-next
105/// A [builder-pattern] type to construct [`DataInputStream`] objects.
106///
107/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
108#[must_use = "The builder must be built to be used"]
109pub struct DataInputStreamBuilder {
110 builder: glib::object::ObjectBuilder<'static, DataInputStream>,
111}
112
113impl DataInputStreamBuilder {
114 fn new() -> Self {
115 Self {
116 builder: glib::object::Object::builder(),
117 }
118 }
119
120 /// The :byte-order property determines the byte ordering that
121 /// is used when reading multi-byte entities (such as integers)
122 /// from the stream.
123 pub fn byte_order(self, byte_order: DataStreamByteOrder) -> Self {
124 Self {
125 builder: self.builder.property("byte-order", byte_order),
126 }
127 }
128
129 /// The :newline-type property determines what is considered
130 /// as a line ending when reading complete lines from the stream.
131 pub fn newline_type(self, newline_type: DataStreamNewlineType) -> Self {
132 Self {
133 builder: self.builder.property("newline-type", newline_type),
134 }
135 }
136
137 /// The size of the backend buffer, in bytes.
138 pub fn buffer_size(self, buffer_size: u32) -> Self {
139 Self {
140 builder: self.builder.property("buffer-size", buffer_size),
141 }
142 }
143
144 /// The underlying base stream on which the I/O ops will be done.
145 pub fn base_stream(self, base_stream: &impl IsA<InputStream>) -> Self {
146 Self {
147 builder: self
148 .builder
149 .property("base-stream", base_stream.clone().upcast()),
150 }
151 }
152
153 /// Whether the base stream should be closed when the filter stream is closed.
154 pub fn close_base_stream(self, close_base_stream: bool) -> Self {
155 Self {
156 builder: self
157 .builder
158 .property("close-base-stream", close_base_stream),
159 }
160 }
161
162 // rustdoc-stripper-ignore-next
163 /// Build the [`DataInputStream`].
164 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
165 pub fn build(self) -> DataInputStream {
166 self.builder.build()
167 }
168}
169
170/// Trait containing all [`struct@DataInputStream`] methods.
171///
172/// # Implementors
173///
174/// [`DataInputStream`][struct@crate::DataInputStream]
175pub trait DataInputStreamExt: IsA<DataInputStream> + 'static {
176 /// Gets the byte order for the data input stream.
177 ///
178 /// # Returns
179 ///
180 /// the @self's current #GDataStreamByteOrder.
181 #[doc(alias = "g_data_input_stream_get_byte_order")]
182 #[doc(alias = "get_byte_order")]
183 #[doc(alias = "byte-order")]
184 fn byte_order(&self) -> DataStreamByteOrder {
185 unsafe {
186 from_glib(ffi::g_data_input_stream_get_byte_order(
187 self.as_ref().to_glib_none().0,
188 ))
189 }
190 }
191
192 /// Gets the current newline type for the @self.
193 ///
194 /// # Returns
195 ///
196 /// #GDataStreamNewlineType for the given @self.
197 #[doc(alias = "g_data_input_stream_get_newline_type")]
198 #[doc(alias = "get_newline_type")]
199 #[doc(alias = "newline-type")]
200 fn newline_type(&self) -> DataStreamNewlineType {
201 unsafe {
202 from_glib(ffi::g_data_input_stream_get_newline_type(
203 self.as_ref().to_glib_none().0,
204 ))
205 }
206 }
207
208 /// Reads an unsigned 8-bit/1-byte value from @self.
209 /// ## `cancellable`
210 /// optional #GCancellable object, [`None`] to ignore.
211 ///
212 /// # Returns
213 ///
214 /// an unsigned 8-bit/1-byte value read from the @self or `0`
215 /// if an error occurred.
216 #[doc(alias = "g_data_input_stream_read_byte")]
217 fn read_byte(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<u8, glib::Error> {
218 unsafe {
219 let mut error = std::ptr::null_mut();
220 let ret = ffi::g_data_input_stream_read_byte(
221 self.as_ref().to_glib_none().0,
222 cancellable.map(|p| p.as_ref()).to_glib_none().0,
223 &mut error,
224 );
225 if error.is_null() {
226 Ok(ret)
227 } else {
228 Err(from_glib_full(error))
229 }
230 }
231 }
232
233 /// Reads a 16-bit/2-byte value from @self.
234 ///
235 /// In order to get the correct byte order for this read operation,
236 /// see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().
237 /// ## `cancellable`
238 /// optional #GCancellable object, [`None`] to ignore.
239 ///
240 /// # Returns
241 ///
242 /// a signed 16-bit/2-byte value read from @self or `0` if
243 /// an error occurred.
244 #[doc(alias = "g_data_input_stream_read_int16")]
245 fn read_int16(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<i16, glib::Error> {
246 unsafe {
247 let mut error = std::ptr::null_mut();
248 let ret = ffi::g_data_input_stream_read_int16(
249 self.as_ref().to_glib_none().0,
250 cancellable.map(|p| p.as_ref()).to_glib_none().0,
251 &mut error,
252 );
253 if error.is_null() {
254 Ok(ret)
255 } else {
256 Err(from_glib_full(error))
257 }
258 }
259 }
260
261 /// Reads a signed 32-bit/4-byte value from @self.
262 ///
263 /// In order to get the correct byte order for this read operation,
264 /// see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().
265 ///
266 /// If @cancellable is not [`None`], then the operation can be cancelled by
267 /// triggering the cancellable object from another thread. If the operation
268 /// was cancelled, the error [`IOErrorEnum::Cancelled`][crate::IOErrorEnum::Cancelled] will be returned.
269 /// ## `cancellable`
270 /// optional #GCancellable object, [`None`] to ignore.
271 ///
272 /// # Returns
273 ///
274 /// a signed 32-bit/4-byte value read from the @self or `0` if
275 /// an error occurred.
276 #[doc(alias = "g_data_input_stream_read_int32")]
277 fn read_int32(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<i32, glib::Error> {
278 unsafe {
279 let mut error = std::ptr::null_mut();
280 let ret = ffi::g_data_input_stream_read_int32(
281 self.as_ref().to_glib_none().0,
282 cancellable.map(|p| p.as_ref()).to_glib_none().0,
283 &mut error,
284 );
285 if error.is_null() {
286 Ok(ret)
287 } else {
288 Err(from_glib_full(error))
289 }
290 }
291 }
292
293 /// Reads a 64-bit/8-byte value from @self.
294 ///
295 /// In order to get the correct byte order for this read operation,
296 /// see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().
297 ///
298 /// If @cancellable is not [`None`], then the operation can be cancelled by
299 /// triggering the cancellable object from another thread. If the operation
300 /// was cancelled, the error [`IOErrorEnum::Cancelled`][crate::IOErrorEnum::Cancelled] will be returned.
301 /// ## `cancellable`
302 /// optional #GCancellable object, [`None`] to ignore.
303 ///
304 /// # Returns
305 ///
306 /// a signed 64-bit/8-byte value read from @self or `0` if
307 /// an error occurred.
308 #[doc(alias = "g_data_input_stream_read_int64")]
309 fn read_int64(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<i64, glib::Error> {
310 unsafe {
311 let mut error = std::ptr::null_mut();
312 let ret = ffi::g_data_input_stream_read_int64(
313 self.as_ref().to_glib_none().0,
314 cancellable.map(|p| p.as_ref()).to_glib_none().0,
315 &mut error,
316 );
317 if error.is_null() {
318 Ok(ret)
319 } else {
320 Err(from_glib_full(error))
321 }
322 }
323 }
324
325 /// Reads an unsigned 16-bit/2-byte value from @self.
326 ///
327 /// In order to get the correct byte order for this read operation,
328 /// see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().
329 /// ## `cancellable`
330 /// optional #GCancellable object, [`None`] to ignore.
331 ///
332 /// # Returns
333 ///
334 /// an unsigned 16-bit/2-byte value read from the @self or `0` if
335 /// an error occurred.
336 #[doc(alias = "g_data_input_stream_read_uint16")]
337 fn read_uint16(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<u16, glib::Error> {
338 unsafe {
339 let mut error = std::ptr::null_mut();
340 let ret = ffi::g_data_input_stream_read_uint16(
341 self.as_ref().to_glib_none().0,
342 cancellable.map(|p| p.as_ref()).to_glib_none().0,
343 &mut error,
344 );
345 if error.is_null() {
346 Ok(ret)
347 } else {
348 Err(from_glib_full(error))
349 }
350 }
351 }
352
353 /// Reads an unsigned 32-bit/4-byte value from @self.
354 ///
355 /// In order to get the correct byte order for this read operation,
356 /// see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().
357 ///
358 /// If @cancellable is not [`None`], then the operation can be cancelled by
359 /// triggering the cancellable object from another thread. If the operation
360 /// was cancelled, the error [`IOErrorEnum::Cancelled`][crate::IOErrorEnum::Cancelled] will be returned.
361 /// ## `cancellable`
362 /// optional #GCancellable object, [`None`] to ignore.
363 ///
364 /// # Returns
365 ///
366 /// an unsigned 32-bit/4-byte value read from the @self or `0` if
367 /// an error occurred.
368 #[doc(alias = "g_data_input_stream_read_uint32")]
369 fn read_uint32(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<u32, glib::Error> {
370 unsafe {
371 let mut error = std::ptr::null_mut();
372 let ret = ffi::g_data_input_stream_read_uint32(
373 self.as_ref().to_glib_none().0,
374 cancellable.map(|p| p.as_ref()).to_glib_none().0,
375 &mut error,
376 );
377 if error.is_null() {
378 Ok(ret)
379 } else {
380 Err(from_glib_full(error))
381 }
382 }
383 }
384
385 /// Reads an unsigned 64-bit/8-byte value from @self.
386 ///
387 /// In order to get the correct byte order for this read operation,
388 /// see g_data_input_stream_get_byte_order().
389 ///
390 /// If @cancellable is not [`None`], then the operation can be cancelled by
391 /// triggering the cancellable object from another thread. If the operation
392 /// was cancelled, the error [`IOErrorEnum::Cancelled`][crate::IOErrorEnum::Cancelled] will be returned.
393 /// ## `cancellable`
394 /// optional #GCancellable object, [`None`] to ignore.
395 ///
396 /// # Returns
397 ///
398 /// an unsigned 64-bit/8-byte read from @self or `0` if
399 /// an error occurred.
400 #[doc(alias = "g_data_input_stream_read_uint64")]
401 fn read_uint64(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<u64, glib::Error> {
402 unsafe {
403 let mut error = std::ptr::null_mut();
404 let ret = ffi::g_data_input_stream_read_uint64(
405 self.as_ref().to_glib_none().0,
406 cancellable.map(|p| p.as_ref()).to_glib_none().0,
407 &mut error,
408 );
409 if error.is_null() {
410 Ok(ret)
411 } else {
412 Err(from_glib_full(error))
413 }
414 }
415 }
416
417 /// This function sets the byte order for the given @self. All subsequent
418 /// reads from the @self will be read in the given @order.
419 /// ## `order`
420 /// a #GDataStreamByteOrder to set.
421 #[doc(alias = "g_data_input_stream_set_byte_order")]
422 #[doc(alias = "byte-order")]
423 fn set_byte_order(&self, order: DataStreamByteOrder) {
424 unsafe {
425 ffi::g_data_input_stream_set_byte_order(
426 self.as_ref().to_glib_none().0,
427 order.into_glib(),
428 );
429 }
430 }
431
432 /// Sets the newline type for the @self.
433 ///
434 /// Note that using G_DATA_STREAM_NEWLINE_TYPE_ANY is slightly unsafe. If a read
435 /// chunk ends in "CR" we must read an additional byte to know if this is "CR" or
436 /// "CR LF", and this might block if there is no more data available.
437 /// ## `type_`
438 /// the type of new line return as #GDataStreamNewlineType.
439 #[doc(alias = "g_data_input_stream_set_newline_type")]
440 #[doc(alias = "newline-type")]
441 fn set_newline_type(&self, type_: DataStreamNewlineType) {
442 unsafe {
443 ffi::g_data_input_stream_set_newline_type(
444 self.as_ref().to_glib_none().0,
445 type_.into_glib(),
446 );
447 }
448 }
449
450 #[doc(alias = "byte-order")]
451 fn connect_byte_order_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
452 unsafe extern "C" fn notify_byte_order_trampoline<
453 P: IsA<DataInputStream>,
454 F: Fn(&P) + 'static,
455 >(
456 this: *mut ffi::GDataInputStream,
457 _param_spec: glib::ffi::gpointer,
458 f: glib::ffi::gpointer,
459 ) {
460 let f: &F = &*(f as *const F);
461 f(DataInputStream::from_glib_borrow(this).unsafe_cast_ref())
462 }
463 unsafe {
464 let f: Box_<F> = Box_::new(f);
465 connect_raw(
466 self.as_ptr() as *mut _,
467 c"notify::byte-order".as_ptr() as *const _,
468 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
469 notify_byte_order_trampoline::<Self, F> as *const (),
470 )),
471 Box_::into_raw(f),
472 )
473 }
474 }
475
476 #[doc(alias = "newline-type")]
477 fn connect_newline_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
478 unsafe extern "C" fn notify_newline_type_trampoline<
479 P: IsA<DataInputStream>,
480 F: Fn(&P) + 'static,
481 >(
482 this: *mut ffi::GDataInputStream,
483 _param_spec: glib::ffi::gpointer,
484 f: glib::ffi::gpointer,
485 ) {
486 let f: &F = &*(f as *const F);
487 f(DataInputStream::from_glib_borrow(this).unsafe_cast_ref())
488 }
489 unsafe {
490 let f: Box_<F> = Box_::new(f);
491 connect_raw(
492 self.as_ptr() as *mut _,
493 c"notify::newline-type".as_ptr() as *const _,
494 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
495 notify_newline_type_trampoline::<Self, F> as *const (),
496 )),
497 Box_::into_raw(f),
498 )
499 }
500 }
501}
502
503impl<O: IsA<DataInputStream>> DataInputStreamExt for O {}