1// Package gio was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gio
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/glib"
12 "github.com/bnema/puregotk/v4/gobject"
13 "github.com/bnema/puregotk/v4/gobject/types"
14)
15
16type BufferedInputStreamClass struct {
17 _ structs.HostLayout
18
19 ParentClass FilterInputStreamClass
20
21 xFill uintptr
22
23 xFillAsync uintptr
24
25 xFillFinish uintptr
26
27 xGReserved1 uintptr
28
29 xGReserved2 uintptr
30
31 xGReserved3 uintptr
32
33 xGReserved4 uintptr
34
35 xGReserved5 uintptr
36}
37
38func (x *BufferedInputStreamClass) GoPointer() uintptr {
39 return uintptr(unsafe.Pointer(x))
40}
41
42// OverrideFill sets the "fill" callback function.
43func (x *BufferedInputStreamClass) OverrideFill(cb func(*BufferedInputStream, int, *Cancellable) int) {
44 if cb == nil {
45 x.xFill = 0
46 } else {
47 x.xFill = purego.NewCallback(func(StreamVarp uintptr, CountVarp int, CancellableVarp uintptr) int {
48 return cb(BufferedInputStreamNewFromInternalPtr(StreamVarp), CountVarp, CancellableNewFromInternalPtr(CancellableVarp))
49 })
50 }
51}
52
53// GetFill gets the "fill" callback function.
54func (x *BufferedInputStreamClass) GetFill() func(*BufferedInputStream, int, *Cancellable) int {
55 if x.xFill == 0 {
56 return nil
57 }
58 var rawCallback func(StreamVarp uintptr, CountVarp int, CancellableVarp uintptr) int
59 purego.RegisterFunc(&rawCallback, x.xFill)
60 return func(StreamVar *BufferedInputStream, CountVar int, CancellableVar *Cancellable) int {
61 return rawCallback(StreamVar.GoPointer(), CountVar, CancellableVar.GoPointer())
62 }
63}
64
65// OverrideFillAsync sets the "fill_async" callback function.
66func (x *BufferedInputStreamClass) OverrideFillAsync(cb func(*BufferedInputStream, int, int, *Cancellable, *AsyncReadyCallback, uintptr)) {
67 if cb == nil {
68 x.xFillAsync = 0
69 } else {
70 x.xFillAsync = purego.NewCallback(func(StreamVarp uintptr, CountVarp int, IoPriorityVarp int, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr) {
71 cb(BufferedInputStreamNewFromInternalPtr(StreamVarp), CountVarp, IoPriorityVarp, CancellableNewFromInternalPtr(CancellableVarp), (*AsyncReadyCallback)(unsafe.Pointer(CallbackVarp)), UserDataVarp)
72 })
73 }
74}
75
76// GetFillAsync gets the "fill_async" callback function.
77func (x *BufferedInputStreamClass) GetFillAsync() func(*BufferedInputStream, int, int, *Cancellable, *AsyncReadyCallback, uintptr) {
78 if x.xFillAsync == 0 {
79 return nil
80 }
81 var rawCallback func(StreamVarp uintptr, CountVarp int, IoPriorityVarp int, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr)
82 purego.RegisterFunc(&rawCallback, x.xFillAsync)
83 return func(StreamVar *BufferedInputStream, CountVar int, IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
84 rawCallback(StreamVar.GoPointer(), CountVar, IoPriorityVar, CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar)
85 }
86}
87
88// OverrideFillFinish sets the "fill_finish" callback function.
89func (x *BufferedInputStreamClass) OverrideFillFinish(cb func(*BufferedInputStream, AsyncResult) int) {
90 if cb == nil {
91 x.xFillFinish = 0
92 } else {
93 x.xFillFinish = purego.NewCallback(func(StreamVarp uintptr, ResultVarp uintptr) int {
94 return cb(BufferedInputStreamNewFromInternalPtr(StreamVarp), &AsyncResultBase{Ptr: ResultVarp})
95 })
96 }
97}
98
99// GetFillFinish gets the "fill_finish" callback function.
100func (x *BufferedInputStreamClass) GetFillFinish() func(*BufferedInputStream, AsyncResult) int {
101 if x.xFillFinish == 0 {
102 return nil
103 }
104 var rawCallback func(StreamVarp uintptr, ResultVarp uintptr) int
105 purego.RegisterFunc(&rawCallback, x.xFillFinish)
106 return func(StreamVar *BufferedInputStream, ResultVar AsyncResult) int {
107 return rawCallback(StreamVar.GoPointer(), ResultVar.GoPointer())
108 }
109}
110
111// OverrideGReserved1 sets the "_g_reserved1" callback function.
112func (x *BufferedInputStreamClass) OverrideGReserved1(cb func()) {
113 if cb == nil {
114 x.xGReserved1 = 0
115 } else {
116 x.xGReserved1 = purego.NewCallback(func() {
117 cb()
118 })
119 }
120}
121
122// GetGReserved1 gets the "_g_reserved1" callback function.
123func (x *BufferedInputStreamClass) GetGReserved1() func() {
124 if x.xGReserved1 == 0 {
125 return nil
126 }
127 var rawCallback func()
128 purego.RegisterFunc(&rawCallback, x.xGReserved1)
129 return func() {
130 rawCallback()
131 }
132}
133
134// OverrideGReserved2 sets the "_g_reserved2" callback function.
135func (x *BufferedInputStreamClass) OverrideGReserved2(cb func()) {
136 if cb == nil {
137 x.xGReserved2 = 0
138 } else {
139 x.xGReserved2 = purego.NewCallback(func() {
140 cb()
141 })
142 }
143}
144
145// GetGReserved2 gets the "_g_reserved2" callback function.
146func (x *BufferedInputStreamClass) GetGReserved2() func() {
147 if x.xGReserved2 == 0 {
148 return nil
149 }
150 var rawCallback func()
151 purego.RegisterFunc(&rawCallback, x.xGReserved2)
152 return func() {
153 rawCallback()
154 }
155}
156
157// OverrideGReserved3 sets the "_g_reserved3" callback function.
158func (x *BufferedInputStreamClass) OverrideGReserved3(cb func()) {
159 if cb == nil {
160 x.xGReserved3 = 0
161 } else {
162 x.xGReserved3 = purego.NewCallback(func() {
163 cb()
164 })
165 }
166}
167
168// GetGReserved3 gets the "_g_reserved3" callback function.
169func (x *BufferedInputStreamClass) GetGReserved3() func() {
170 if x.xGReserved3 == 0 {
171 return nil
172 }
173 var rawCallback func()
174 purego.RegisterFunc(&rawCallback, x.xGReserved3)
175 return func() {
176 rawCallback()
177 }
178}
179
180// OverrideGReserved4 sets the "_g_reserved4" callback function.
181func (x *BufferedInputStreamClass) OverrideGReserved4(cb func()) {
182 if cb == nil {
183 x.xGReserved4 = 0
184 } else {
185 x.xGReserved4 = purego.NewCallback(func() {
186 cb()
187 })
188 }
189}
190
191// GetGReserved4 gets the "_g_reserved4" callback function.
192func (x *BufferedInputStreamClass) GetGReserved4() func() {
193 if x.xGReserved4 == 0 {
194 return nil
195 }
196 var rawCallback func()
197 purego.RegisterFunc(&rawCallback, x.xGReserved4)
198 return func() {
199 rawCallback()
200 }
201}
202
203// OverrideGReserved5 sets the "_g_reserved5" callback function.
204func (x *BufferedInputStreamClass) OverrideGReserved5(cb func()) {
205 if cb == nil {
206 x.xGReserved5 = 0
207 } else {
208 x.xGReserved5 = purego.NewCallback(func() {
209 cb()
210 })
211 }
212}
213
214// GetGReserved5 gets the "_g_reserved5" callback function.
215func (x *BufferedInputStreamClass) GetGReserved5() func() {
216 if x.xGReserved5 == 0 {
217 return nil
218 }
219 var rawCallback func()
220 purego.RegisterFunc(&rawCallback, x.xGReserved5)
221 return func() {
222 rawCallback()
223 }
224}
225
226type BufferedInputStreamPrivate struct {
227 _ structs.HostLayout
228}
229
230func (x *BufferedInputStreamPrivate) GoPointer() uintptr {
231 return uintptr(unsafe.Pointer(x))
232}
233
234// Buffered input stream implements [class@Gio.FilterInputStream] and provides
235// for buffered reads.
236//
237// By default, `GBufferedInputStream`'s buffer size is set at 4 kilobytes.
238//
239// To create a buffered input stream, use [ctor@Gio.BufferedInputStream.new],
240// or [ctor@Gio.BufferedInputStream.new_sized] to specify the buffer's size at
241// construction.
242//
243// To get the size of a buffer within a buffered input stream, use
244// [method@Gio.BufferedInputStream.get_buffer_size]. To change the size of a
245// buffered input stream's buffer, use [method@Gio.BufferedInputStream.set_buffer_size].
246// Note that the buffer's size cannot be reduced below the size of the data within the buffer.
247type BufferedInputStream struct {
248 FilterInputStream
249}
250
251var xBufferedInputStreamGLibType func() types.GType
252
253func BufferedInputStreamGLibType() types.GType {
254 return xBufferedInputStreamGLibType()
255}
256
257func BufferedInputStreamNewFromInternalPtr(ptr uintptr) *BufferedInputStream {
258 cls := &BufferedInputStream{}
259 cls.Ptr = ptr
260 return cls
261}
262
263var xNewBufferedInputStream func(uintptr) uintptr
264
265// Creates a new [class@Gio.InputStream] from the given @base_stream, with
266// a buffer set to the default size (4 kilobytes).
267func NewBufferedInputStream(BaseStreamVar *InputStream) *BufferedInputStream {
268 var cls *BufferedInputStream
269
270 cret := xNewBufferedInputStream(BaseStreamVar.GoPointer())
271
272 if cret == 0 {
273 return nil
274 }
275 cls = &BufferedInputStream{}
276 cls.Ptr = cret
277 return cls
278}
279
280var xNewBufferedInputStreamSized func(uintptr, uint) uintptr
281
282// Creates a new [class@Gio.BufferedInputStream] from the given @base_stream,
283// with a buffer set to @size.
284func NewBufferedInputStreamSized(BaseStreamVar *InputStream, SizeVar uint) *BufferedInputStream {
285 var cls *BufferedInputStream
286
287 cret := xNewBufferedInputStreamSized(BaseStreamVar.GoPointer(), SizeVar)
288
289 if cret == 0 {
290 return nil
291 }
292 cls = &BufferedInputStream{}
293 cls.Ptr = cret
294 return cls
295}
296
297var xBufferedInputStreamFill func(uintptr, int, uintptr, **glib.Error) int
298
299// Tries to read @count bytes from the stream into the buffer.
300// Will block during this read.
301//
302// If @count is zero, returns zero and does nothing. A value of @count
303// larger than `G_MAXSSIZE` will cause a
304// [error@Gio.IOErrorEnum.INVALID_ARGUMENT] error.
305//
306// On success, the number of bytes read into the buffer is returned.
307// It is not an error if this is not the same as the requested size, as it
308// can happen e.g. near the end of a file. Zero is returned on end of file
309// (or if @count is zero), but never otherwise.
310//
311// If @count is -1 then the attempted read size is equal to the number of
312// bytes that are required to fill the buffer.
313//
314// If @cancellable is not `NULL`, then the operation can be cancelled by
315// triggering the cancellable object from another thread. If the operation
316// was cancelled, the error [error@Gio.IOErrorEnum.CANCELLED] will be returned.
317// If an operation was partially finished when the operation was cancelled the
318// partial result will be returned, without an error.
319//
320// On error `-1` is returned and @error is set accordingly.
321//
322// For the asynchronous, non-blocking, version of this function, see
323// [method@Gio.BufferedInputStream.fill_async].
324func (x *BufferedInputStream) Fill(CountVar int, CancellableVar *Cancellable) (int, error) {
325 var cerr *glib.Error
326
327 cret := xBufferedInputStreamFill(x.GoPointer(), CountVar, CancellableVar.GoPointer(), &cerr)
328 if cerr == nil {
329 return cret, nil
330 }
331 return cret, cerr
332
333}
334
335var xBufferedInputStreamFillAsync func(uintptr, int, int, uintptr, uintptr, uintptr)
336
337// Reads data into @stream's buffer asynchronously, up to @count size.
338// @io_priority can be used to prioritize reads. For the synchronous
339// version of this function, see [method@Gio.BufferedInputStream.fill].
340//
341// If @count is `-1` then the attempted read size is equal to the number
342// of bytes that are required to fill the buffer.
343func (x *BufferedInputStream) FillAsync(CountVar int, IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
344
345 var CallbackVarRef uintptr
346 if CallbackVar != nil {
347 CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
348 if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
349 CallbackVarRef = cbRefPtr
350 } else {
351 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
352 cbFn := *CallbackVar
353 cbFn(arg0, arg1, arg2)
354 }
355 CallbackVarRef = purego.NewCallback(fcb)
356 glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
357 }
358 }
359
360 xBufferedInputStreamFillAsync(x.GoPointer(), CountVar, IoPriorityVar, CancellableVar.GoPointer(), CallbackVarRef, UserDataVar)
361
362}
363
364var xBufferedInputStreamFillFinish func(uintptr, uintptr, **glib.Error) int
365
366// Finishes an asynchronous read.
367func (x *BufferedInputStream) FillFinish(ResultVar AsyncResult) (int, error) {
368 var cerr *glib.Error
369
370 cret := xBufferedInputStreamFillFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr)
371 if cerr == nil {
372 return cret, nil
373 }
374 return cret, cerr
375
376}
377
378var xBufferedInputStreamGetAvailable func(uintptr) uint
379
380// Gets the size of the available data within the stream.
381func (x *BufferedInputStream) GetAvailable() uint {
382
383 cret := xBufferedInputStreamGetAvailable(x.GoPointer())
384 return cret
385}
386
387var xBufferedInputStreamGetBufferSize func(uintptr) uint
388
389// Gets the size of the input buffer.
390func (x *BufferedInputStream) GetBufferSize() uint {
391
392 cret := xBufferedInputStreamGetBufferSize(x.GoPointer())
393 return cret
394}
395
396var xBufferedInputStreamPeek func(uintptr, []byte, uint, uint) uint
397
398// Peeks in the buffer, copying data of size @count into @buffer,
399// offset @offset bytes.
400func (x *BufferedInputStream) Peek(BufferVar []byte, OffsetVar uint, CountVar uint) uint {
401
402 cret := xBufferedInputStreamPeek(x.GoPointer(), BufferVar, OffsetVar, CountVar)
403 return cret
404}
405
406var xBufferedInputStreamPeekBuffer func(uintptr, *uint) uintptr
407
408// Returns the buffer with the currently available bytes. The returned
409// buffer must not be modified and will become invalid when reading from
410// the stream or filling the buffer.
411func (x *BufferedInputStream) PeekBuffer(CountVar *uint) uintptr {
412
413 cret := xBufferedInputStreamPeekBuffer(x.GoPointer(), CountVar)
414 return cret
415}
416
417var xBufferedInputStreamReadByte func(uintptr, uintptr, **glib.Error) int
418
419// Tries to read a single byte from the stream or the buffer. Will block
420// during this read.
421//
422// On success, the byte read from the stream is returned. On end of stream
423// `-1` is returned but it's not an exceptional error and @error is not set.
424//
425// If @cancellable is not `NULL`, then the operation can be cancelled by
426// triggering the cancellable object from another thread. If the operation
427// was cancelled, the error [error@Gio.IOErrorEnum.CANCELLED] will be returned.
428// If an operation was partially finished when the operation was cancelled the
429// partial result will be returned, without an error.
430//
431// On error `-1` is returned and @error is set accordingly.
432func (x *BufferedInputStream) ReadByte(CancellableVar *Cancellable) (int, error) {
433 var cerr *glib.Error
434
435 cret := xBufferedInputStreamReadByte(x.GoPointer(), CancellableVar.GoPointer(), &cerr)
436 if cerr == nil {
437 return cret, nil
438 }
439 return cret, cerr
440
441}
442
443var xBufferedInputStreamSetBufferSize func(uintptr, uint)
444
445// Sets the size of the internal buffer of @stream to @size, or to the
446// size of the contents of the buffer. The buffer can never be resized
447// smaller than its current contents.
448func (x *BufferedInputStream) SetBufferSize(SizeVar uint) {
449
450 xBufferedInputStreamSetBufferSize(x.GoPointer(), SizeVar)
451
452}
453
454func (c *BufferedInputStream) GoPointer() uintptr {
455 if c == nil {
456 return 0
457 }
458 return c.Ptr
459}
460
461func (c *BufferedInputStream) SetGoPointer(ptr uintptr) {
462 c.Ptr = ptr
463}
464
465// SetPropertyBufferSize sets the "buffer-size" property.
466// The size of the backend buffer, in bytes.
467func (x *BufferedInputStream) SetPropertyBufferSize(value uint) {
468 var v gobject.Value
469 v.Init(gobject.TypeUintVal)
470 v.SetUint(value)
471 x.SetProperty("buffer-size", &v)
472}
473
474// GetPropertyBufferSize gets the "buffer-size" property.
475// The size of the backend buffer, in bytes.
476func (x *BufferedInputStream) GetPropertyBufferSize() uint {
477 var v gobject.Value
478 x.GetProperty("buffer-size", &v)
479 return v.GetUint()
480}
481
482// Tests if the stream supports the #GSeekableIface.
483func (x *BufferedInputStream) CanSeek() bool {
484
485 cret := XGSeekableCanSeek(x.GoPointer())
486 return cret
487}
488
489// Tests if the length of the stream can be adjusted with
490// g_seekable_truncate().
491func (x *BufferedInputStream) CanTruncate() bool {
492
493 cret := XGSeekableCanTruncate(x.GoPointer())
494 return cret
495}
496
497// Seeks in the stream by the given @offset, modified by @type.
498//
499// Attempting to seek past the end of the stream will have different
500// results depending on if the stream is fixed-sized or resizable. If
501// the stream is resizable then seeking past the end and then writing
502// will result in zeros filling the empty space. Seeking past the end
503// of a resizable stream and reading will result in EOF. Seeking past
504// the end of a fixed-sized stream will fail.
505//
506// Any operation that would result in a negative offset will fail.
507//
508// If @cancellable is not %NULL, then the operation can be cancelled by
509// triggering the cancellable object from another thread. If the operation
510// was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
511func (x *BufferedInputStream) Seek(OffsetVar int64, TypeVar glib.SeekType, CancellableVar *Cancellable) (bool, error) {
512 var cerr *glib.Error
513
514 cret := XGSeekableSeek(x.GoPointer(), OffsetVar, TypeVar, CancellableVar.GoPointer(), &cerr)
515 if cerr == nil {
516 return cret, nil
517 }
518 return cret, cerr
519
520}
521
522// Tells the current position within the stream.
523func (x *BufferedInputStream) Tell() int64 {
524
525 cret := XGSeekableTell(x.GoPointer())
526 return cret
527}
528
529// Sets the length of the stream to @offset. If the stream was previously
530// larger than @offset, the extra data is discarded. If the stream was
531// previously shorter than @offset, it is extended with NUL ('\0') bytes.
532//
533// If @cancellable is not %NULL, then the operation can be cancelled by
534// triggering the cancellable object from another thread. If the operation
535// was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
536// operation was partially finished when the operation was cancelled the
537// partial result will be returned, without an error.
538func (x *BufferedInputStream) Truncate(OffsetVar int64, CancellableVar *Cancellable) (bool, error) {
539 var cerr *glib.Error
540
541 cret := XGSeekableTruncate(x.GoPointer(), OffsetVar, CancellableVar.GoPointer(), &cerr)
542 if cerr == nil {
543 return cret, nil
544 }
545 return cret, cerr
546
547}
548
549func init() {
550 core.SetPackageName("GIO", "gio-2.0")
551 core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
552 var libs []uintptr
553 for _, libPath := range core.GetPaths("GIO") {
554 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
555 if err != nil {
556 panic(err)
557 }
558 libs = append(libs, lib)
559 }
560
561 core.PuregoSafeRegister(&xBufferedInputStreamGLibType, libs, "g_buffered_input_stream_get_type")
562
563 core.PuregoSafeRegister(&xNewBufferedInputStream, libs, "g_buffered_input_stream_new")
564 core.PuregoSafeRegister(&xNewBufferedInputStreamSized, libs, "g_buffered_input_stream_new_sized")
565
566 core.PuregoSafeRegister(&xBufferedInputStreamFill, libs, "g_buffered_input_stream_fill")
567 core.PuregoSafeRegister(&xBufferedInputStreamFillAsync, libs, "g_buffered_input_stream_fill_async")
568 core.PuregoSafeRegister(&xBufferedInputStreamFillFinish, libs, "g_buffered_input_stream_fill_finish")
569 core.PuregoSafeRegister(&xBufferedInputStreamGetAvailable, libs, "g_buffered_input_stream_get_available")
570 core.PuregoSafeRegister(&xBufferedInputStreamGetBufferSize, libs, "g_buffered_input_stream_get_buffer_size")
571 core.PuregoSafeRegister(&xBufferedInputStreamPeek, libs, "g_buffered_input_stream_peek")
572 core.PuregoSafeRegister(&xBufferedInputStreamPeekBuffer, libs, "g_buffered_input_stream_peek_buffer")
573 core.PuregoSafeRegister(&xBufferedInputStreamReadByte, libs, "g_buffered_input_stream_read_byte")
574 core.PuregoSafeRegister(&xBufferedInputStreamSetBufferSize, libs, "g_buffered_input_stream_set_buffer_size")
575
576}