// GENERATED — DO NOT EDIT

///|
/// [Upstream documentation](https://docs.gtk.org/gio/class.DataInputStream.html).
pub type DataInputStream

///|
pub(open) trait IDataInputStream {
  fn as_data_input_stream(Self) -> DataInputStream
  fn get_byte_order(Self) -> DataStreamByteOrder = _
  fn get_newline_type(Self) -> DataStreamNewlineType = _
  fn read_byte(Self, &ICancellable?) -> UInt raise @glib.Error_ = _
  fn read_int16(Self, &ICancellable?) -> Int raise @glib.Error_ = _
  fn read_int32(Self, &ICancellable?) -> Int raise @glib.Error_ = _
  fn read_int64(Self, &ICancellable?) -> Int64 raise @glib.Error_ = _
  fn read_line_finish_utf8(Self, &IAsyncResult) -> (String?, UInt64) raise @glib.Error_ = _
  fn read_line_utf8(Self, &ICancellable?) -> (String?, UInt64) raise @glib.Error_ = _
  fn read_uint16(Self, &ICancellable?) -> UInt raise @glib.Error_ = _
  fn read_uint32(Self, &ICancellable?) -> UInt raise @glib.Error_ = _
  fn read_uint64(Self, &ICancellable?) -> UInt64 raise @glib.Error_ = _
  fn read_upto(Self, String, Int64, &ICancellable?) -> (String, UInt64) raise @glib.Error_ = _
  fn set_byte_order(Self, DataStreamByteOrder) -> Unit = _
  fn set_newline_type(Self, DataStreamNewlineType) -> Unit = _
  fn read_upto_async(
    Self,
    String,
    Int64,
    Int,
    &ICancellable?,
    (Result[(String, UInt64), @glib.Error_]) -> Unit,
  ) -> Unit = _
}

///|
pub impl IDataInputStream for DataInputStream with fn as_data_input_stream(self) {
  self
}

///|
#borrow(base_stream)
extern "c" fn moonbit_g_data_input_stream_new(
  base_stream : InputStream,
) -> DataInputStream = "moonbit_g_data_input_stream_new"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/ctor.DataInputStream.new.html).
pub fn DataInputStream::new(base_stream : &IInputStream) -> DataInputStream {
  moonbit_g_data_input_stream_new(base_stream.as_input_stream())
}

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DataInputStream.get_byte_order.html).
#borrow(self)
pub extern "c" fn DataInputStream::get_byte_order(
  self : DataInputStream,
) -> DataStreamByteOrder = "moonbit_g_data_input_stream_get_byte_order"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DataInputStream.get_newline_type.html).
#borrow(self)
pub extern "c" fn DataInputStream::get_newline_type(
  self : DataInputStream,
) -> DataStreamNewlineType = "moonbit_g_data_input_stream_get_newline_type"

///|
#borrow(self_, cancellable, error)
extern "c" fn moonbit_g_data_input_stream_read_byte(
  self_ : DataInputStream,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> UInt = "moonbit_g_data_input_stream_read_byte"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DataInputStream.read_byte.html).
pub fn DataInputStream::read_byte(
  self : DataInputStream,
  cancellable : &ICancellable?,
) -> UInt raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_data_input_stream_read_byte(
    self,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, cancellable, error)
extern "c" fn moonbit_g_data_input_stream_read_int16(
  self_ : DataInputStream,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Int = "moonbit_g_data_input_stream_read_int16"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DataInputStream.read_int16.html).
pub fn DataInputStream::read_int16(
  self : DataInputStream,
  cancellable : &ICancellable?,
) -> Int raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_data_input_stream_read_int16(
    self,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, cancellable, error)
extern "c" fn moonbit_g_data_input_stream_read_int32(
  self_ : DataInputStream,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Int = "moonbit_g_data_input_stream_read_int32"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DataInputStream.read_int32.html).
pub fn DataInputStream::read_int32(
  self : DataInputStream,
  cancellable : &ICancellable?,
) -> Int raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_data_input_stream_read_int32(
    self,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, cancellable, error)
extern "c" fn moonbit_g_data_input_stream_read_int64(
  self_ : DataInputStream,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Int64 = "moonbit_g_data_input_stream_read_int64"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DataInputStream.read_int64.html).
pub fn DataInputStream::read_int64(
  self : DataInputStream,
  cancellable : &ICancellable?,
) -> Int64 raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_data_input_stream_read_int64(
    self,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, result, length, error)
extern "c" fn moonbit_g_data_input_stream_read_line_finish_utf8(
  self_ : DataInputStream,
  result : AsyncResult,
  length : Ref[UInt64],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> @glib.Nullable[Bytes] = "moonbit_g_data_input_stream_read_line_finish_utf8"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DataInputStream.read_line_finish_utf8.html).
pub fn DataInputStream::read_line_finish_utf8(
  self : DataInputStream,
  result : &IAsyncResult,
) -> (String?, UInt64) raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let length = Ref(0UL)
  let result_ = moonbit_g_data_input_stream_read_line_finish_utf8(
    self,
    result.as_async_result(),
    length,
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  let result = match result_.to_option() {
    Some(bytes) => Some(@encoding/utf8.decode_lossy(bytes))
    None => None
  }
  (result, length.val)
}

///|
#borrow(self_, length, cancellable, error)
extern "c" fn moonbit_g_data_input_stream_read_line_utf8(
  self_ : DataInputStream,
  length : Ref[UInt64],
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> @glib.Nullable[Bytes] = "moonbit_g_data_input_stream_read_line_utf8"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DataInputStream.read_line_utf8.html).
pub fn DataInputStream::read_line_utf8(
  self : DataInputStream,
  cancellable : &ICancellable?,
) -> (String?, UInt64) raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let length = Ref(0UL)
  let result_ = moonbit_g_data_input_stream_read_line_utf8(
    self,
    length,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  let result = match result_.to_option() {
    Some(bytes) => Some(@encoding/utf8.decode_lossy(bytes))
    None => None
  }
  (result, length.val)
}

///|
#borrow(self_, cancellable, error)
extern "c" fn moonbit_g_data_input_stream_read_uint16(
  self_ : DataInputStream,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> UInt = "moonbit_g_data_input_stream_read_uint16"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DataInputStream.read_uint16.html).
pub fn DataInputStream::read_uint16(
  self : DataInputStream,
  cancellable : &ICancellable?,
) -> UInt raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_data_input_stream_read_uint16(
    self,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, cancellable, error)
extern "c" fn moonbit_g_data_input_stream_read_uint32(
  self_ : DataInputStream,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> UInt = "moonbit_g_data_input_stream_read_uint32"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DataInputStream.read_uint32.html).
pub fn DataInputStream::read_uint32(
  self : DataInputStream,
  cancellable : &ICancellable?,
) -> UInt raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_data_input_stream_read_uint32(
    self,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, cancellable, error)
extern "c" fn moonbit_g_data_input_stream_read_uint64(
  self_ : DataInputStream,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> UInt64 = "moonbit_g_data_input_stream_read_uint64"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DataInputStream.read_uint64.html).
pub fn DataInputStream::read_uint64(
  self : DataInputStream,
  cancellable : &ICancellable?,
) -> UInt64 raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_data_input_stream_read_uint64(
    self,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, stop_chars, length, cancellable, error)
extern "c" fn moonbit_g_data_input_stream_read_upto(
  self_ : DataInputStream,
  stop_chars : Bytes,
  stop_chars_len : Int64,
  length : Ref[UInt64],
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Bytes = "moonbit_g_data_input_stream_read_upto"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DataInputStream.read_upto.html).
pub fn DataInputStream::read_upto(
  self : DataInputStream,
  stop_chars : String,
  stop_chars_len : Int64,
  cancellable : &ICancellable?,
) -> (String, UInt64) raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let length = Ref(0UL)
  let result_ = moonbit_g_data_input_stream_read_upto(
    self,
    @encoding/utf8.encode(stop_chars),
    stop_chars_len,
    length,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  let result = @encoding/utf8.decode_lossy(result_)
  (result, length.val)
}

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DataInputStream.set_byte_order.html).
#borrow(self)
pub extern "c" fn DataInputStream::set_byte_order(
  self : DataInputStream,
  order : DataStreamByteOrder,
) = "moonbit_g_data_input_stream_set_byte_order"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DataInputStream.set_newline_type.html).
#borrow(self)
pub extern "c" fn DataInputStream::set_newline_type(
  self : DataInputStream,
  type_ : DataStreamNewlineType,
) = "moonbit_g_data_input_stream_set_newline_type"

///|
#borrow(self_, stop_chars, cancellable)
extern "c" fn g_data_input_stream_read_upto_async(
  self_ : DataInputStream,
  stop_chars : Bytes,
  stop_chars_len : Int64,
  io_priority : Int,
  cancellable : @glib.Nullable[Cancellable],
  function : FuncRef[
    (
      @glib.Nullable[Bytes],
      UInt64,
      @glib.Nullable[@glib.Error_],
      (@glib.Nullable[Bytes], UInt64, @glib.Nullable[@glib.Error_]) -> Unit,
    ) -> Unit,
  ],
  closure : (@glib.Nullable[Bytes], UInt64, @glib.Nullable[@glib.Error_]) -> Unit,
) = "moonbit_g_data_input_stream_read_upto_async"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DataInputStream.read_upto_async.html).
pub fn DataInputStream::read_upto_async(
  self : DataInputStream,
  stop_chars : String,
  stop_chars_len : Int64,
  io_priority : Int,
  cancellable : &ICancellable?,
  callback : (Result[(String, UInt64), @glib.Error_]) -> Unit,
) -> Unit {
  g_data_input_stream_read_upto_async(
    self,
    @encoding/utf8.encode(stop_chars),
    stop_chars_len,
    io_priority,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    fn(result, __out0, error, f) { f(result, __out0, error) },
    fn(result, __out0, error) {
      match error.to_option() {
        Some(e) => callback(Err(e))
        None =>
          match result.to_option() {
            Some(bytes) =>
              callback(Ok((@encoding/utf8.decode_lossy(bytes), __out0)))
            None => ()
          }
      }
    },
  )
}

///|
impl IDataInputStream with fn get_byte_order(self) -> DataStreamByteOrder {
  self.as_data_input_stream().get_byte_order()
}

///|
impl IDataInputStream with fn get_newline_type(self) -> DataStreamNewlineType {
  self.as_data_input_stream().get_newline_type()
}

///|
impl IDataInputStream with fn read_byte(self, cancellable) -> UInt raise @glib.Error_ {
  self.as_data_input_stream().read_byte(cancellable)
}

///|
impl IDataInputStream with fn read_int16(self, cancellable) -> Int raise @glib.Error_ {
  self.as_data_input_stream().read_int16(cancellable)
}

///|
impl IDataInputStream with fn read_int32(self, cancellable) -> Int raise @glib.Error_ {
  self.as_data_input_stream().read_int32(cancellable)
}

///|
impl IDataInputStream with fn read_int64(self, cancellable) -> Int64 raise @glib.Error_ {
  self.as_data_input_stream().read_int64(cancellable)
}

///|
impl IDataInputStream with fn read_line_finish_utf8(self, result) -> (
  String?,
  UInt64,
) raise @glib.Error_ {
  self.as_data_input_stream().read_line_finish_utf8(result)
}

///|
impl IDataInputStream with fn read_line_utf8(self, cancellable) -> (
  String?,
  UInt64,
) raise @glib.Error_ {
  self.as_data_input_stream().read_line_utf8(cancellable)
}

///|
impl IDataInputStream with fn read_uint16(self, cancellable) -> UInt raise @glib.Error_ {
  self.as_data_input_stream().read_uint16(cancellable)
}

///|
impl IDataInputStream with fn read_uint32(self, cancellable) -> UInt raise @glib.Error_ {
  self.as_data_input_stream().read_uint32(cancellable)
}

///|
impl IDataInputStream with fn read_uint64(self, cancellable) -> UInt64 raise @glib.Error_ {
  self.as_data_input_stream().read_uint64(cancellable)
}

///|
impl IDataInputStream with fn read_upto(
  self,
  stop_chars,
  stop_chars_len,
  cancellable,
) -> (String, UInt64) raise @glib.Error_ {
  self.as_data_input_stream().read_upto(stop_chars, stop_chars_len, cancellable)
}

///|
impl IDataInputStream with fn set_byte_order(self, order) -> Unit {
  self.as_data_input_stream().set_byte_order(order)
}

///|
impl IDataInputStream with fn set_newline_type(self, type_) -> Unit {
  self.as_data_input_stream().set_newline_type(type_)
}

///|
impl IDataInputStream with fn read_upto_async(
  self,
  stop_chars,
  stop_chars_len,
  io_priority,
  cancellable,
  callback,
) -> Unit {
  self
  .as_data_input_stream()
  .read_upto_async(
    stop_chars, stop_chars_len, io_priority, cancellable, callback,
  )
}

///|
pub fn DataInputStream::as_buffered_input_stream(
  self : DataInputStream,
) -> BufferedInputStream = "%identity"

///|
pub impl IBufferedInputStream for DataInputStream with fn as_buffered_input_stream(
  self,
) {
  self.as_buffered_input_stream()
}

///|
pub fn DataInputStream::as_filter_input_stream(
  self : DataInputStream,
) -> FilterInputStream = "%identity"

///|
pub impl IFilterInputStream for DataInputStream with fn as_filter_input_stream(
  self,
) {
  self.as_filter_input_stream()
}

///|
pub fn DataInputStream::as_input_stream(self : DataInputStream) -> InputStream = "%identity"

///|
pub impl IInputStream for DataInputStream with fn as_input_stream(self) {
  self.as_input_stream()
}

///|
pub fn DataInputStream::as_gobject_object(
  self : DataInputStream,
) -> @gobject.Object = "%identity"

///|
pub impl @gobject.IObject for DataInputStream with fn as_object(self) {
  self.as_gobject_object()
}

///|
pub fn DataInputStream::as_seekable(self : DataInputStream) -> Seekable = "%identity"

///|
pub impl ISeekable for DataInputStream with fn as_seekable(self) {
  self.as_seekable()
}