1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use gio_sys;
use glib;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::GString;
use glib::StaticType;
use glib::ToValue;
use glib_sys;
use gobject_sys;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem;
use std::mem::transmute;
use std::pin::Pin;
use std::ptr;
use BufferedInputStream;
use Cancellable;
use DataStreamByteOrder;
use DataStreamNewlineType;
use FilterInputStream;
use InputStream;
use Seekable;

glib_wrapper! {
    /// Data input stream implements `InputStream` and includes functions for
    /// reading structured data directly from a binary input stream.
    ///
    /// # Implements
    ///
    /// [`DataInputStreamExt`](trait.DataInputStreamExt.html), [`BufferedInputStreamExt`](trait.BufferedInputStreamExt.html), [`FilterInputStreamExt`](trait.FilterInputStreamExt.html), [`InputStreamExt`](trait.InputStreamExt.html), [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html), [`SeekableExt`](trait.SeekableExt.html), [`InputStreamExtManual`](prelude/trait.InputStreamExtManual.html)
    pub struct DataInputStream(Object<gio_sys::GDataInputStream, gio_sys::GDataInputStreamClass, DataInputStreamClass>) @extends BufferedInputStream, FilterInputStream, InputStream, @implements Seekable;

    match fn {
        get_type => || gio_sys::g_data_input_stream_get_type(),
    }
}

impl DataInputStream {
    /// Creates a new data input stream for the `base_stream`.
    /// ## `base_stream`
    /// a `InputStream`.
    ///
    /// # Returns
    ///
    /// a new `DataInputStream`.
    pub fn new<P: IsA<InputStream>>(base_stream: &P) -> DataInputStream {
        unsafe {
            from_glib_full(gio_sys::g_data_input_stream_new(
                base_stream.as_ref().to_glib_none().0,
            ))
        }
    }
}

#[derive(Clone, Default)]
pub struct DataInputStreamBuilder {
    byte_order: Option<DataStreamByteOrder>,
    newline_type: Option<DataStreamNewlineType>,
    buffer_size: Option<u32>,
    base_stream: Option<InputStream>,
    close_base_stream: Option<bool>,
}

impl DataInputStreamBuilder {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn build(self) -> DataInputStream {
        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
        if let Some(ref byte_order) = self.byte_order {
            properties.push(("byte-order", byte_order));
        }
        if let Some(ref newline_type) = self.newline_type {
            properties.push(("newline-type", newline_type));
        }
        if let Some(ref buffer_size) = self.buffer_size {
            properties.push(("buffer-size", buffer_size));
        }
        if let Some(ref base_stream) = self.base_stream {
            properties.push(("base-stream", base_stream));
        }
        if let Some(ref close_base_stream) = self.close_base_stream {
            properties.push(("close-base-stream", close_base_stream));
        }
        glib::Object::new(DataInputStream::static_type(), &properties)
            .expect("object new")
            .downcast()
            .expect("downcast")
    }

    pub fn byte_order(mut self, byte_order: DataStreamByteOrder) -> Self {
        self.byte_order = Some(byte_order);
        self
    }

    pub fn newline_type(mut self, newline_type: DataStreamNewlineType) -> Self {
        self.newline_type = Some(newline_type);
        self
    }

    pub fn buffer_size(mut self, buffer_size: u32) -> Self {
        self.buffer_size = Some(buffer_size);
        self
    }

    pub fn base_stream<P: IsA<InputStream>>(mut self, base_stream: &P) -> Self {
        self.base_stream = Some(base_stream.clone().upcast());
        self
    }

    pub fn close_base_stream(mut self, close_base_stream: bool) -> Self {
        self.close_base_stream = Some(close_base_stream);
        self
    }
}

pub const NONE_DATA_INPUT_STREAM: Option<&DataInputStream> = None;

/// Trait containing all `DataInputStream` methods.
///
/// # Implementors
///
/// [`DataInputStream`](struct.DataInputStream.html)
pub trait DataInputStreamExt: 'static {
    /// Gets the byte order for the data input stream.
    ///
    /// # Returns
    ///
    /// the `self`'s current `DataStreamByteOrder`.
    fn get_byte_order(&self) -> DataStreamByteOrder;

    /// Gets the current newline type for the `self`.
    ///
    /// # Returns
    ///
    /// `DataStreamNewlineType` for the given `self`.
    fn get_newline_type(&self) -> DataStreamNewlineType;

    /// Reads an unsigned 8-bit/1-byte value from `self`.
    /// ## `cancellable`
    /// optional `Cancellable` object, `None` to ignore.
    ///
    /// # Returns
    ///
    /// an unsigned 8-bit/1-byte value read from the `self` or `0`
    /// if an error occurred.
    fn read_byte<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<u8, glib::Error>;

    /// Reads a 16-bit/2-byte value from `self`.
    ///
    /// In order to get the correct byte order for this read operation,
    /// see `DataInputStreamExt::get_byte_order` and `DataInputStreamExt::set_byte_order`.
    /// ## `cancellable`
    /// optional `Cancellable` object, `None` to ignore.
    ///
    /// # Returns
    ///
    /// a signed 16-bit/2-byte value read from `self` or `0` if
    /// an error occurred.
    fn read_int16<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<i16, glib::Error>;

    /// Reads a signed 32-bit/4-byte value from `self`.
    ///
    /// In order to get the correct byte order for this read operation,
    /// see `DataInputStreamExt::get_byte_order` and `DataInputStreamExt::set_byte_order`.
    ///
    /// If `cancellable` is not `None`, then the operation can be cancelled by
    /// triggering the cancellable object from another thread. If the operation
    /// was cancelled, the error `IOErrorEnum::Cancelled` will be returned.
    /// ## `cancellable`
    /// optional `Cancellable` object, `None` to ignore.
    ///
    /// # Returns
    ///
    /// a signed 32-bit/4-byte value read from the `self` or `0` if
    /// an error occurred.
    fn read_int32<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<i32, glib::Error>;

    /// Reads a 64-bit/8-byte value from `self`.
    ///
    /// In order to get the correct byte order for this read operation,
    /// see `DataInputStreamExt::get_byte_order` and `DataInputStreamExt::set_byte_order`.
    ///
    /// If `cancellable` is not `None`, then the operation can be cancelled by
    /// triggering the cancellable object from another thread. If the operation
    /// was cancelled, the error `IOErrorEnum::Cancelled` will be returned.
    /// ## `cancellable`
    /// optional `Cancellable` object, `None` to ignore.
    ///
    /// # Returns
    ///
    /// a signed 64-bit/8-byte value read from `self` or `0` if
    /// an error occurred.
    fn read_int64<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<i64, glib::Error>;

    //fn read_line_finish_utf8(&self, result: /*Ignored*/&AsyncResult) -> Result<(Option<GString>, usize), glib::Error>;

    /// Reads a UTF-8 encoded line from the data input stream.
    ///
    /// If `cancellable` is not `None`, then the operation can be cancelled by
    /// triggering the cancellable object from another thread. If the operation
    /// was cancelled, the error `IOErrorEnum::Cancelled` will be returned.
    /// ## `length`
    /// a `gsize` to get the length of the data read in.
    /// ## `cancellable`
    /// optional `Cancellable` object, `None` to ignore.
    ///
    /// # Returns
    ///
    /// a NUL terminated UTF-8 string
    ///  with the line that was read in (without the newlines). Set
    ///  `length` to a `gsize` to get the length of the read line. On an
    ///  error, it will return `None` and `error` will be set. For UTF-8
    ///  conversion errors, the set error domain is `G_CONVERT_ERROR`. If
    ///  there's no content to read, it will still return `None`, but `error`
    ///  won't be set.
    fn read_line_utf8<P: IsA<Cancellable>>(
        &self,
        cancellable: Option<&P>,
    ) -> Result<(Option<GString>, usize), glib::Error>;

    /// Reads an unsigned 16-bit/2-byte value from `self`.
    ///
    /// In order to get the correct byte order for this read operation,
    /// see `DataInputStreamExt::get_byte_order` and `DataInputStreamExt::set_byte_order`.
    /// ## `cancellable`
    /// optional `Cancellable` object, `None` to ignore.
    ///
    /// # Returns
    ///
    /// an unsigned 16-bit/2-byte value read from the `self` or `0` if
    /// an error occurred.
    fn read_uint16<P: IsA<Cancellable>>(&self, cancellable: Option<&P>)
        -> Result<u16, glib::Error>;

    /// Reads an unsigned 32-bit/4-byte value from `self`.
    ///
    /// In order to get the correct byte order for this read operation,
    /// see `DataInputStreamExt::get_byte_order` and `DataInputStreamExt::set_byte_order`.
    ///
    /// If `cancellable` is not `None`, then the operation can be cancelled by
    /// triggering the cancellable object from another thread. If the operation
    /// was cancelled, the error `IOErrorEnum::Cancelled` will be returned.
    /// ## `cancellable`
    /// optional `Cancellable` object, `None` to ignore.
    ///
    /// # Returns
    ///
    /// an unsigned 32-bit/4-byte value read from the `self` or `0` if
    /// an error occurred.
    fn read_uint32<P: IsA<Cancellable>>(&self, cancellable: Option<&P>)
        -> Result<u32, glib::Error>;

    /// Reads an unsigned 64-bit/8-byte value from `self`.
    ///
    /// In order to get the correct byte order for this read operation,
    /// see `DataInputStreamExt::get_byte_order`.
    ///
    /// If `cancellable` is not `None`, then the operation can be cancelled by
    /// triggering the cancellable object from another thread. If the operation
    /// was cancelled, the error `IOErrorEnum::Cancelled` will be returned.
    /// ## `cancellable`
    /// optional `Cancellable` object, `None` to ignore.
    ///
    /// # Returns
    ///
    /// an unsigned 64-bit/8-byte read from `self` or `0` if
    /// an error occurred.
    fn read_uint64<P: IsA<Cancellable>>(&self, cancellable: Option<&P>)
        -> Result<u64, glib::Error>;

    /// Reads a string from the data input stream, up to the first
    /// occurrence of any of the stop characters.
    ///
    /// Note that, in contrast to `DataInputStreamExt::read_until_async`,
    /// this function consumes the stop character that it finds.
    ///
    /// Don't use this function in new code. Its functionality is
    /// inconsistent with `DataInputStreamExt::read_until_async`. Both
    /// functions will be marked as deprecated in a future release. Use
    /// `DataInputStreamExt::read_upto` instead, but note that that function
    /// does not consume the stop character.
    ///
    /// # Deprecated since 2.56
    ///
    /// Use `DataInputStreamExt::read_upto` instead, which has more
    ///  consistent behaviour regarding the stop character.
    /// ## `stop_chars`
    /// characters to terminate the read.
    /// ## `length`
    /// a `gsize` to get the length of the data read in.
    /// ## `cancellable`
    /// optional `Cancellable` object, `None` to ignore.
    ///
    /// # Returns
    ///
    /// a string with the data that was read
    ///  before encountering any of the stop characters. Set `length` to
    ///  a `gsize` to get the length of the string. This function will
    ///  return `None` on an error.
    #[cfg_attr(feature = "v2_56", deprecated)]
    fn read_until<P: IsA<Cancellable>>(
        &self,
        stop_chars: &str,
        cancellable: Option<&P>,
    ) -> Result<(GString, usize), glib::Error>;

    /// The asynchronous version of `DataInputStreamExt::read_until`.
    /// It is an error to have two outstanding calls to this function.
    ///
    /// Note that, in contrast to `DataInputStreamExt::read_until`,
    /// this function does not consume the stop character that it finds. You
    /// must read it for yourself.
    ///
    /// When the operation is finished, `callback` will be called. You
    /// can then call `DataInputStreamExt::read_until_finish` to get
    /// the result of the operation.
    ///
    /// Don't use this function in new code. Its functionality is
    /// inconsistent with `DataInputStreamExt::read_until`. Both functions
    /// will be marked as deprecated in a future release. Use
    /// `DataInputStreamExt::read_upto_async` instead.
    ///
    /// # Deprecated since 2.56
    ///
    /// Use `DataInputStreamExt::read_upto_async` instead, which
    ///  has more consistent behaviour regarding the stop character.
    /// ## `stop_chars`
    /// characters to terminate the read.
    /// ## `io_priority`
    /// the [I/O priority][io-priority] of the request
    /// ## `cancellable`
    /// optional `Cancellable` object, `None` to ignore.
    /// ## `callback`
    /// callback to call when the request is satisfied.
    /// ## `user_data`
    /// the data to pass to callback function.
    #[cfg_attr(feature = "v2_56", deprecated)]
    fn read_until_async<
        P: IsA<Cancellable>,
        Q: FnOnce(Result<(GString, usize), glib::Error>) + Send + 'static,
    >(
        &self,
        stop_chars: &str,
        io_priority: glib::Priority,
        cancellable: Option<&P>,
        callback: Q,
    );

    #[cfg_attr(feature = "v2_56", deprecated)]

    fn read_until_async_future(
        &self,
        stop_chars: &str,
        io_priority: glib::Priority,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(GString, usize), glib::Error>> + 'static>>;

    /// Reads a string from the data input stream, up to the first
    /// occurrence of any of the stop characters.
    ///
    /// In contrast to `DataInputStreamExt::read_until`, this function
    /// does not consume the stop character. You have to use
    /// `DataInputStreamExt::read_byte` to get it before calling
    /// `DataInputStreamExt::read_upto` again.
    ///
    /// Note that `stop_chars` may contain '\0' if `stop_chars_len` is
    /// specified.
    ///
    /// The returned string will always be nul-terminated on success.
    /// ## `stop_chars`
    /// characters to terminate the read
    /// ## `stop_chars_len`
    /// length of `stop_chars`. May be -1 if `stop_chars` is
    ///  nul-terminated
    /// ## `length`
    /// a `gsize` to get the length of the data read in
    /// ## `cancellable`
    /// optional `Cancellable` object, `None` to ignore
    ///
    /// # Returns
    ///
    /// a string with the data that was read
    ///  before encountering any of the stop characters. Set `length` to
    ///  a `gsize` to get the length of the string. This function will
    ///  return `None` on an error
    fn read_upto<P: IsA<Cancellable>>(
        &self,
        stop_chars: &str,
        cancellable: Option<&P>,
    ) -> Result<(GString, usize), glib::Error>;

    /// The asynchronous version of `DataInputStreamExt::read_upto`.
    /// It is an error to have two outstanding calls to this function.
    ///
    /// In contrast to `DataInputStreamExt::read_until`, this function
    /// does not consume the stop character. You have to use
    /// `DataInputStreamExt::read_byte` to get it before calling
    /// `DataInputStreamExt::read_upto` again.
    ///
    /// Note that `stop_chars` may contain '\0' if `stop_chars_len` is
    /// specified.
    ///
    /// When the operation is finished, `callback` will be called. You
    /// can then call `DataInputStreamExt::read_upto_finish` to get
    /// the result of the operation.
    /// ## `stop_chars`
    /// characters to terminate the read
    /// ## `stop_chars_len`
    /// length of `stop_chars`. May be -1 if `stop_chars` is
    ///  nul-terminated
    /// ## `io_priority`
    /// the [I/O priority][io-priority] of the request
    /// ## `cancellable`
    /// optional `Cancellable` object, `None` to ignore
    /// ## `callback`
    /// callback to call when the request is satisfied
    /// ## `user_data`
    /// the data to pass to callback function
    fn read_upto_async<
        P: IsA<Cancellable>,
        Q: FnOnce(Result<(GString, usize), glib::Error>) + Send + 'static,
    >(
        &self,
        stop_chars: &str,
        io_priority: glib::Priority,
        cancellable: Option<&P>,
        callback: Q,
    );

    fn read_upto_async_future(
        &self,
        stop_chars: &str,
        io_priority: glib::Priority,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(GString, usize), glib::Error>> + 'static>>;

    /// This function sets the byte order for the given `self`. All subsequent
    /// reads from the `self` will be read in the given `order`.
    /// ## `order`
    /// a `DataStreamByteOrder` to set.
    fn set_byte_order(&self, order: DataStreamByteOrder);

    /// Sets the newline type for the `self`.
    ///
    /// Note that using G_DATA_STREAM_NEWLINE_TYPE_ANY is slightly unsafe. If a read
    /// chunk ends in "CR" we must read an additional byte to know if this is "CR" or
    /// "CR LF", and this might block if there is no more data available.
    /// ## `type_`
    /// the type of new line return as `DataStreamNewlineType`.
    fn set_newline_type(&self, type_: DataStreamNewlineType);

    fn connect_property_byte_order_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_newline_type_notify<F: Fn(&Self) + 'static>(&self, f: F)
        -> SignalHandlerId;
}

impl<O: IsA<DataInputStream>> DataInputStreamExt for O {
    fn get_byte_order(&self) -> DataStreamByteOrder {
        unsafe {
            from_glib(gio_sys::g_data_input_stream_get_byte_order(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_newline_type(&self) -> DataStreamNewlineType {
        unsafe {
            from_glib(gio_sys::g_data_input_stream_get_newline_type(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn read_byte<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<u8, glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = gio_sys::g_data_input_stream_read_byte(
                self.as_ref().to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(ret)
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn read_int16<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<i16, glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = gio_sys::g_data_input_stream_read_int16(
                self.as_ref().to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(ret)
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn read_int32<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<i32, glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = gio_sys::g_data_input_stream_read_int32(
                self.as_ref().to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(ret)
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn read_int64<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<i64, glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = gio_sys::g_data_input_stream_read_int64(
                self.as_ref().to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(ret)
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    //fn read_line_finish_utf8(&self, result: /*Ignored*/&AsyncResult) -> Result<(Option<GString>, usize), glib::Error> {
    //    unsafe { TODO: call gio_sys:g_data_input_stream_read_line_finish_utf8() }
    //}

    fn read_line_utf8<P: IsA<Cancellable>>(
        &self,
        cancellable: Option<&P>,
    ) -> Result<(Option<GString>, usize), glib::Error> {
        unsafe {
            let mut length = mem::MaybeUninit::uninit();
            let mut error = ptr::null_mut();
            let ret = gio_sys::g_data_input_stream_read_line_utf8(
                self.as_ref().to_glib_none().0,
                length.as_mut_ptr(),
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            let length = length.assume_init();
            if error.is_null() {
                Ok((from_glib_full(ret), length))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn read_uint16<P: IsA<Cancellable>>(
        &self,
        cancellable: Option<&P>,
    ) -> Result<u16, glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = gio_sys::g_data_input_stream_read_uint16(
                self.as_ref().to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(ret)
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn read_uint32<P: IsA<Cancellable>>(
        &self,
        cancellable: Option<&P>,
    ) -> Result<u32, glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = gio_sys::g_data_input_stream_read_uint32(
                self.as_ref().to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(ret)
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn read_uint64<P: IsA<Cancellable>>(
        &self,
        cancellable: Option<&P>,
    ) -> Result<u64, glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = gio_sys::g_data_input_stream_read_uint64(
                self.as_ref().to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(ret)
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn read_until<P: IsA<Cancellable>>(
        &self,
        stop_chars: &str,
        cancellable: Option<&P>,
    ) -> Result<(GString, usize), glib::Error> {
        unsafe {
            let mut length = mem::MaybeUninit::uninit();
            let mut error = ptr::null_mut();
            let ret = gio_sys::g_data_input_stream_read_until(
                self.as_ref().to_glib_none().0,
                stop_chars.to_glib_none().0,
                length.as_mut_ptr(),
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            let length = length.assume_init();
            if error.is_null() {
                Ok((from_glib_full(ret), length))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn read_until_async<
        P: IsA<Cancellable>,
        Q: FnOnce(Result<(GString, usize), glib::Error>) + Send + 'static,
    >(
        &self,
        stop_chars: &str,
        io_priority: glib::Priority,
        cancellable: Option<&P>,
        callback: Q,
    ) {
        let user_data: Box_<Q> = Box_::new(callback);
        unsafe extern "C" fn read_until_async_trampoline<
            Q: FnOnce(Result<(GString, usize), glib::Error>) + Send + 'static,
        >(
            _source_object: *mut gobject_sys::GObject,
            res: *mut gio_sys::GAsyncResult,
            user_data: glib_sys::gpointer,
        ) {
            let mut error = ptr::null_mut();
            let mut length = mem::MaybeUninit::uninit();
            let ret = gio_sys::g_data_input_stream_read_until_finish(
                _source_object as *mut _,
                res,
                length.as_mut_ptr(),
                &mut error,
            );
            let length = length.assume_init();
            let result = if error.is_null() {
                Ok((from_glib_full(ret), length))
            } else {
                Err(from_glib_full(error))
            };
            let callback: Box_<Q> = Box_::from_raw(user_data as *mut _);
            callback(result);
        }
        let callback = read_until_async_trampoline::<Q>;
        unsafe {
            gio_sys::g_data_input_stream_read_until_async(
                self.as_ref().to_glib_none().0,
                stop_chars.to_glib_none().0,
                io_priority.to_glib(),
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                Some(callback),
                Box_::into_raw(user_data) as *mut _,
            );
        }
    }

    fn read_until_async_future(
        &self,
        stop_chars: &str,
        io_priority: glib::Priority,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(GString, usize), glib::Error>> + 'static>>
    {
        let stop_chars = String::from(stop_chars);
        Box_::pin(crate::GioFuture::new(self, move |obj, send| {
            let cancellable = Cancellable::new();
            obj.read_until_async(&stop_chars, io_priority, Some(&cancellable), move |res| {
                send.resolve(res);
            });

            cancellable
        }))
    }

    fn read_upto<P: IsA<Cancellable>>(
        &self,
        stop_chars: &str,
        cancellable: Option<&P>,
    ) -> Result<(GString, usize), glib::Error> {
        let stop_chars_len = stop_chars.len() as isize;
        unsafe {
            let mut length = mem::MaybeUninit::uninit();
            let mut error = ptr::null_mut();
            let ret = gio_sys::g_data_input_stream_read_upto(
                self.as_ref().to_glib_none().0,
                stop_chars.to_glib_none().0,
                stop_chars_len,
                length.as_mut_ptr(),
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            let length = length.assume_init();
            if error.is_null() {
                Ok((from_glib_full(ret), length))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn read_upto_async<
        P: IsA<Cancellable>,
        Q: FnOnce(Result<(GString, usize), glib::Error>) + Send + 'static,
    >(
        &self,
        stop_chars: &str,
        io_priority: glib::Priority,
        cancellable: Option<&P>,
        callback: Q,
    ) {
        let stop_chars_len = stop_chars.len() as isize;
        let user_data: Box_<Q> = Box_::new(callback);
        unsafe extern "C" fn read_upto_async_trampoline<
            Q: FnOnce(Result<(GString, usize), glib::Error>) + Send + 'static,
        >(
            _source_object: *mut gobject_sys::GObject,
            res: *mut gio_sys::GAsyncResult,
            user_data: glib_sys::gpointer,
        ) {
            let mut error = ptr::null_mut();
            let mut length = mem::MaybeUninit::uninit();
            let ret = gio_sys::g_data_input_stream_read_upto_finish(
                _source_object as *mut _,
                res,
                length.as_mut_ptr(),
                &mut error,
            );
            let length = length.assume_init();
            let result = if error.is_null() {
                Ok((from_glib_full(ret), length))
            } else {
                Err(from_glib_full(error))
            };
            let callback: Box_<Q> = Box_::from_raw(user_data as *mut _);
            callback(result);
        }
        let callback = read_upto_async_trampoline::<Q>;
        unsafe {
            gio_sys::g_data_input_stream_read_upto_async(
                self.as_ref().to_glib_none().0,
                stop_chars.to_glib_none().0,
                stop_chars_len,
                io_priority.to_glib(),
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                Some(callback),
                Box_::into_raw(user_data) as *mut _,
            );
        }
    }

    fn read_upto_async_future(
        &self,
        stop_chars: &str,
        io_priority: glib::Priority,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(GString, usize), glib::Error>> + 'static>>
    {
        let stop_chars = String::from(stop_chars);
        Box_::pin(crate::GioFuture::new(self, move |obj, send| {
            let cancellable = Cancellable::new();
            obj.read_upto_async(&stop_chars, io_priority, Some(&cancellable), move |res| {
                send.resolve(res);
            });

            cancellable
        }))
    }

    fn set_byte_order(&self, order: DataStreamByteOrder) {
        unsafe {
            gio_sys::g_data_input_stream_set_byte_order(
                self.as_ref().to_glib_none().0,
                order.to_glib(),
            );
        }
    }

    fn set_newline_type(&self, type_: DataStreamNewlineType) {
        unsafe {
            gio_sys::g_data_input_stream_set_newline_type(
                self.as_ref().to_glib_none().0,
                type_.to_glib(),
            );
        }
    }

    fn connect_property_byte_order_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_byte_order_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut gio_sys::GDataInputStream,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<DataInputStream>,
        {
            let f: &F = &*(f as *const F);
            f(&DataInputStream::from_glib_borrow(this).unsafe_cast())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::byte-order\0".as_ptr() as *const _,
                Some(transmute(notify_byte_order_trampoline::<Self, F> as usize)),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_newline_type_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_newline_type_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut gio_sys::GDataInputStream,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<DataInputStream>,
        {
            let f: &F = &*(f as *const F);
            f(&DataInputStream::from_glib_borrow(this).unsafe_cast())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::newline-type\0".as_ptr() as *const _,
                Some(transmute(
                    notify_newline_type_trampoline::<Self, F> as usize,
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for DataInputStream {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "DataInputStream")
    }
}