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
170mod sealed {
171 pub trait Sealed {}
172 impl<T: super::IsA<super::DataInputStream>> Sealed for T {}
173}
174
175/// Trait containing all [`struct@DataInputStream`] methods.
176///
177/// # Implementors
178///
179/// [`DataInputStream`][struct@crate::DataInputStream]
180pub trait DataInputStreamExt: IsA<DataInputStream> + sealed::Sealed + 'static {
181 /// Gets the byte order for the data input stream.
182 ///
183 /// # Returns
184 ///
185 /// the @self's current #GDataStreamByteOrder.
186 #[doc(alias = "g_data_input_stream_get_byte_order")]
187 #[doc(alias = "get_byte_order")]
188 #[doc(alias = "byte-order")]
189 fn byte_order(&self) -> DataStreamByteOrder {
190 unsafe {
191 from_glib(ffi::g_data_input_stream_get_byte_order(
192 self.as_ref().to_glib_none().0,
193 ))
194 }
195 }
196
197 /// Gets the current newline type for the @self.
198 ///
199 /// # Returns
200 ///
201 /// #GDataStreamNewlineType for the given @self.
202 #[doc(alias = "g_data_input_stream_get_newline_type")]
203 #[doc(alias = "get_newline_type")]
204 #[doc(alias = "newline-type")]
205 fn newline_type(&self) -> DataStreamNewlineType {
206 unsafe {
207 from_glib(ffi::g_data_input_stream_get_newline_type(
208 self.as_ref().to_glib_none().0,
209 ))
210 }
211 }
212
213 /// Reads an unsigned 8-bit/1-byte value from @self.
214 /// ## `cancellable`
215 /// optional #GCancellable object, [`None`] to ignore.
216 ///
217 /// # Returns
218 ///
219 /// an unsigned 8-bit/1-byte value read from the @self or `0`
220 /// if an error occurred.
221 #[doc(alias = "g_data_input_stream_read_byte")]
222 fn read_byte(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<u8, glib::Error> {
223 unsafe {
224 let mut error = std::ptr::null_mut();
225 let ret = ffi::g_data_input_stream_read_byte(
226 self.as_ref().to_glib_none().0,
227 cancellable.map(|p| p.as_ref()).to_glib_none().0,
228 &mut error,
229 );
230 if error.is_null() {
231 Ok(ret)
232 } else {
233 Err(from_glib_full(error))
234 }
235 }
236 }
237
238 /// Reads a 16-bit/2-byte value from @self.
239 ///
240 /// In order to get the correct byte order for this read operation,
241 /// see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().
242 /// ## `cancellable`
243 /// optional #GCancellable object, [`None`] to ignore.
244 ///
245 /// # Returns
246 ///
247 /// a signed 16-bit/2-byte value read from @self or `0` if
248 /// an error occurred.
249 #[doc(alias = "g_data_input_stream_read_int16")]
250 fn read_int16(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<i16, glib::Error> {
251 unsafe {
252 let mut error = std::ptr::null_mut();
253 let ret = ffi::g_data_input_stream_read_int16(
254 self.as_ref().to_glib_none().0,
255 cancellable.map(|p| p.as_ref()).to_glib_none().0,
256 &mut error,
257 );
258 if error.is_null() {
259 Ok(ret)
260 } else {
261 Err(from_glib_full(error))
262 }
263 }
264 }
265
266 /// Reads a signed 32-bit/4-byte value from @self.
267 ///
268 /// In order to get the correct byte order for this read operation,
269 /// see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().
270 ///
271 /// If @cancellable is not [`None`], then the operation can be cancelled by
272 /// triggering the cancellable object from another thread. If the operation
273 /// was cancelled, the error [`IOErrorEnum::Cancelled`][crate::IOErrorEnum::Cancelled] will be returned.
274 /// ## `cancellable`
275 /// optional #GCancellable object, [`None`] to ignore.
276 ///
277 /// # Returns
278 ///
279 /// a signed 32-bit/4-byte value read from the @self or `0` if
280 /// an error occurred.
281 #[doc(alias = "g_data_input_stream_read_int32")]
282 fn read_int32(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<i32, glib::Error> {
283 unsafe {
284 let mut error = std::ptr::null_mut();
285 let ret = ffi::g_data_input_stream_read_int32(
286 self.as_ref().to_glib_none().0,
287 cancellable.map(|p| p.as_ref()).to_glib_none().0,
288 &mut error,
289 );
290 if error.is_null() {
291 Ok(ret)
292 } else {
293 Err(from_glib_full(error))
294 }
295 }
296 }
297
298 /// Reads a 64-bit/8-byte value from @self.
299 ///
300 /// In order to get the correct byte order for this read operation,
301 /// see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().
302 ///
303 /// If @cancellable is not [`None`], then the operation can be cancelled by
304 /// triggering the cancellable object from another thread. If the operation
305 /// was cancelled, the error [`IOErrorEnum::Cancelled`][crate::IOErrorEnum::Cancelled] will be returned.
306 /// ## `cancellable`
307 /// optional #GCancellable object, [`None`] to ignore.
308 ///
309 /// # Returns
310 ///
311 /// a signed 64-bit/8-byte value read from @self or `0` if
312 /// an error occurred.
313 #[doc(alias = "g_data_input_stream_read_int64")]
314 fn read_int64(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<i64, glib::Error> {
315 unsafe {
316 let mut error = std::ptr::null_mut();
317 let ret = ffi::g_data_input_stream_read_int64(
318 self.as_ref().to_glib_none().0,
319 cancellable.map(|p| p.as_ref()).to_glib_none().0,
320 &mut error,
321 );
322 if error.is_null() {
323 Ok(ret)
324 } else {
325 Err(from_glib_full(error))
326 }
327 }
328 }
329
330 /// Reads an unsigned 16-bit/2-byte value from @self.
331 ///
332 /// In order to get the correct byte order for this read operation,
333 /// see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().
334 /// ## `cancellable`
335 /// optional #GCancellable object, [`None`] to ignore.
336 ///
337 /// # Returns
338 ///
339 /// an unsigned 16-bit/2-byte value read from the @self or `0` if
340 /// an error occurred.
341 #[doc(alias = "g_data_input_stream_read_uint16")]
342 fn read_uint16(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<u16, glib::Error> {
343 unsafe {
344 let mut error = std::ptr::null_mut();
345 let ret = ffi::g_data_input_stream_read_uint16(
346 self.as_ref().to_glib_none().0,
347 cancellable.map(|p| p.as_ref()).to_glib_none().0,
348 &mut error,
349 );
350 if error.is_null() {
351 Ok(ret)
352 } else {
353 Err(from_glib_full(error))
354 }
355 }
356 }
357
358 /// Reads an unsigned 32-bit/4-byte value from @self.
359 ///
360 /// In order to get the correct byte order for this read operation,
361 /// see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().
362 ///
363 /// If @cancellable is not [`None`], then the operation can be cancelled by
364 /// triggering the cancellable object from another thread. If the operation
365 /// was cancelled, the error [`IOErrorEnum::Cancelled`][crate::IOErrorEnum::Cancelled] will be returned.
366 /// ## `cancellable`
367 /// optional #GCancellable object, [`None`] to ignore.
368 ///
369 /// # Returns
370 ///
371 /// an unsigned 32-bit/4-byte value read from the @self or `0` if
372 /// an error occurred.
373 #[doc(alias = "g_data_input_stream_read_uint32")]
374 fn read_uint32(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<u32, glib::Error> {
375 unsafe {
376 let mut error = std::ptr::null_mut();
377 let ret = ffi::g_data_input_stream_read_uint32(
378 self.as_ref().to_glib_none().0,
379 cancellable.map(|p| p.as_ref()).to_glib_none().0,
380 &mut error,
381 );
382 if error.is_null() {
383 Ok(ret)
384 } else {
385 Err(from_glib_full(error))
386 }
387 }
388 }
389
390 /// Reads an unsigned 64-bit/8-byte value from @self.
391 ///
392 /// In order to get the correct byte order for this read operation,
393 /// see g_data_input_stream_get_byte_order().
394 ///
395 /// If @cancellable is not [`None`], then the operation can be cancelled by
396 /// triggering the cancellable object from another thread. If the operation
397 /// was cancelled, the error [`IOErrorEnum::Cancelled`][crate::IOErrorEnum::Cancelled] will be returned.
398 /// ## `cancellable`
399 /// optional #GCancellable object, [`None`] to ignore.
400 ///
401 /// # Returns
402 ///
403 /// an unsigned 64-bit/8-byte read from @self or `0` if
404 /// an error occurred.
405 #[doc(alias = "g_data_input_stream_read_uint64")]
406 fn read_uint64(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<u64, glib::Error> {
407 unsafe {
408 let mut error = std::ptr::null_mut();
409 let ret = ffi::g_data_input_stream_read_uint64(
410 self.as_ref().to_glib_none().0,
411 cancellable.map(|p| p.as_ref()).to_glib_none().0,
412 &mut error,
413 );
414 if error.is_null() {
415 Ok(ret)
416 } else {
417 Err(from_glib_full(error))
418 }
419 }
420 }
421
422 /// This function sets the byte order for the given @self. All subsequent
423 /// reads from the @self will be read in the given @order.
424 /// ## `order`
425 /// a #GDataStreamByteOrder to set.
426 #[doc(alias = "g_data_input_stream_set_byte_order")]
427 #[doc(alias = "byte-order")]
428 fn set_byte_order(&self, order: DataStreamByteOrder) {
429 unsafe {
430 ffi::g_data_input_stream_set_byte_order(
431 self.as_ref().to_glib_none().0,
432 order.into_glib(),
433 );
434 }
435 }
436
437 /// Sets the newline type for the @self.
438 ///
439 /// Note that using G_DATA_STREAM_NEWLINE_TYPE_ANY is slightly unsafe. If a read
440 /// chunk ends in "CR" we must read an additional byte to know if this is "CR" or
441 /// "CR LF", and this might block if there is no more data available.
442 /// ## `type_`
443 /// the type of new line return as #GDataStreamNewlineType.
444 #[doc(alias = "g_data_input_stream_set_newline_type")]
445 #[doc(alias = "newline-type")]
446 fn set_newline_type(&self, type_: DataStreamNewlineType) {
447 unsafe {
448 ffi::g_data_input_stream_set_newline_type(
449 self.as_ref().to_glib_none().0,
450 type_.into_glib(),
451 );
452 }
453 }
454
455 #[doc(alias = "byte-order")]
456 fn connect_byte_order_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
457 unsafe extern "C" fn notify_byte_order_trampoline<
458 P: IsA<DataInputStream>,
459 F: Fn(&P) + 'static,
460 >(
461 this: *mut ffi::GDataInputStream,
462 _param_spec: glib::ffi::gpointer,
463 f: glib::ffi::gpointer,
464 ) {
465 let f: &F = &*(f as *const F);
466 f(DataInputStream::from_glib_borrow(this).unsafe_cast_ref())
467 }
468 unsafe {
469 let f: Box_<F> = Box_::new(f);
470 connect_raw(
471 self.as_ptr() as *mut _,
472 b"notify::byte-order\0".as_ptr() as *const _,
473 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
474 notify_byte_order_trampoline::<Self, F> as *const (),
475 )),
476 Box_::into_raw(f),
477 )
478 }
479 }
480
481 #[doc(alias = "newline-type")]
482 fn connect_newline_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
483 unsafe extern "C" fn notify_newline_type_trampoline<
484 P: IsA<DataInputStream>,
485 F: Fn(&P) + 'static,
486 >(
487 this: *mut ffi::GDataInputStream,
488 _param_spec: glib::ffi::gpointer,
489 f: glib::ffi::gpointer,
490 ) {
491 let f: &F = &*(f as *const F);
492 f(DataInputStream::from_glib_borrow(this).unsafe_cast_ref())
493 }
494 unsafe {
495 let f: Box_<F> = Box_::new(f);
496 connect_raw(
497 self.as_ptr() as *mut _,
498 b"notify::newline-type\0".as_ptr() as *const _,
499 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
500 notify_newline_type_trampoline::<Self, F> as *const (),
501 )),
502 Box_::into_raw(f),
503 )
504 }
505 }
506}
507
508impl<O: IsA<DataInputStream>> DataInputStreamExt for O {}