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
16// Changes the size of the memory block pointed to by @data to
17// @size bytes.
18//
19// The function should have the same semantics as realloc().
20type ReallocFunc func(uintptr, uint) uintptr
21
22type MemoryOutputStreamClass struct {
23 _ structs.HostLayout
24
25 ParentClass OutputStreamClass
26
27 xGReserved1 uintptr
28
29 xGReserved2 uintptr
30
31 xGReserved3 uintptr
32
33 xGReserved4 uintptr
34
35 xGReserved5 uintptr
36}
37
38func (x *MemoryOutputStreamClass) GoPointer() uintptr {
39 return uintptr(unsafe.Pointer(x))
40}
41
42// OverrideGReserved1 sets the "_g_reserved1" callback function.
43func (x *MemoryOutputStreamClass) OverrideGReserved1(cb func()) {
44 if cb == nil {
45 x.xGReserved1 = 0
46 } else {
47 x.xGReserved1 = purego.NewCallback(func() {
48 cb()
49 })
50 }
51}
52
53// GetGReserved1 gets the "_g_reserved1" callback function.
54func (x *MemoryOutputStreamClass) GetGReserved1() func() {
55 if x.xGReserved1 == 0 {
56 return nil
57 }
58 var rawCallback func()
59 purego.RegisterFunc(&rawCallback, x.xGReserved1)
60 return func() {
61 rawCallback()
62 }
63}
64
65// OverrideGReserved2 sets the "_g_reserved2" callback function.
66func (x *MemoryOutputStreamClass) OverrideGReserved2(cb func()) {
67 if cb == nil {
68 x.xGReserved2 = 0
69 } else {
70 x.xGReserved2 = purego.NewCallback(func() {
71 cb()
72 })
73 }
74}
75
76// GetGReserved2 gets the "_g_reserved2" callback function.
77func (x *MemoryOutputStreamClass) GetGReserved2() func() {
78 if x.xGReserved2 == 0 {
79 return nil
80 }
81 var rawCallback func()
82 purego.RegisterFunc(&rawCallback, x.xGReserved2)
83 return func() {
84 rawCallback()
85 }
86}
87
88// OverrideGReserved3 sets the "_g_reserved3" callback function.
89func (x *MemoryOutputStreamClass) OverrideGReserved3(cb func()) {
90 if cb == nil {
91 x.xGReserved3 = 0
92 } else {
93 x.xGReserved3 = purego.NewCallback(func() {
94 cb()
95 })
96 }
97}
98
99// GetGReserved3 gets the "_g_reserved3" callback function.
100func (x *MemoryOutputStreamClass) GetGReserved3() func() {
101 if x.xGReserved3 == 0 {
102 return nil
103 }
104 var rawCallback func()
105 purego.RegisterFunc(&rawCallback, x.xGReserved3)
106 return func() {
107 rawCallback()
108 }
109}
110
111// OverrideGReserved4 sets the "_g_reserved4" callback function.
112func (x *MemoryOutputStreamClass) OverrideGReserved4(cb func()) {
113 if cb == nil {
114 x.xGReserved4 = 0
115 } else {
116 x.xGReserved4 = purego.NewCallback(func() {
117 cb()
118 })
119 }
120}
121
122// GetGReserved4 gets the "_g_reserved4" callback function.
123func (x *MemoryOutputStreamClass) GetGReserved4() func() {
124 if x.xGReserved4 == 0 {
125 return nil
126 }
127 var rawCallback func()
128 purego.RegisterFunc(&rawCallback, x.xGReserved4)
129 return func() {
130 rawCallback()
131 }
132}
133
134// OverrideGReserved5 sets the "_g_reserved5" callback function.
135func (x *MemoryOutputStreamClass) OverrideGReserved5(cb func()) {
136 if cb == nil {
137 x.xGReserved5 = 0
138 } else {
139 x.xGReserved5 = purego.NewCallback(func() {
140 cb()
141 })
142 }
143}
144
145// GetGReserved5 gets the "_g_reserved5" callback function.
146func (x *MemoryOutputStreamClass) GetGReserved5() func() {
147 if x.xGReserved5 == 0 {
148 return nil
149 }
150 var rawCallback func()
151 purego.RegisterFunc(&rawCallback, x.xGReserved5)
152 return func() {
153 rawCallback()
154 }
155}
156
157type MemoryOutputStreamPrivate struct {
158 _ structs.HostLayout
159}
160
161func (x *MemoryOutputStreamPrivate) GoPointer() uintptr {
162 return uintptr(unsafe.Pointer(x))
163}
164
165// `GMemoryOutputStream` is a class for using arbitrary
166// memory chunks as output for GIO streaming output operations.
167//
168// As of GLib 2.34, `GMemoryOutputStream` trivially implements
169// [iface@Gio.PollableOutputStream]: it always polls as ready.
170type MemoryOutputStream struct {
171 OutputStream
172}
173
174var xMemoryOutputStreamGLibType func() types.GType
175
176func MemoryOutputStreamGLibType() types.GType {
177 return xMemoryOutputStreamGLibType()
178}
179
180func MemoryOutputStreamNewFromInternalPtr(ptr uintptr) *MemoryOutputStream {
181 cls := &MemoryOutputStream{}
182 cls.Ptr = ptr
183 return cls
184}
185
186var xNewMemoryOutputStream func(uintptr, uint, uintptr, uintptr) uintptr
187
188// Creates a new #GMemoryOutputStream.
189//
190// In most cases this is not the function you want. See
191// g_memory_output_stream_new_resizable() instead.
192//
193// If @data is non-%NULL, the stream will use that for its internal storage.
194//
195// If @realloc_fn is non-%NULL, it will be used for resizing the internal
196// storage when necessary and the stream will be considered resizable.
197// In that case, the stream will start out being (conceptually) empty.
198// @size is used only as a hint for how big @data is. Specifically,
199// seeking to the end of a newly-created stream will seek to zero, not
200// @size. Seeking past the end of the stream and then writing will
201// introduce a zero-filled gap.
202//
203// If @realloc_fn is %NULL then the stream is fixed-sized. Seeking to
204// the end will seek to @size exactly. Writing past the end will give
205// an 'out of space' error. Attempting to seek past the end will fail.
206// Unlike the resizable case, seeking to an offset within the stream and
207// writing will preserve the bytes passed in as @data before that point
208// and will return them as part of g_memory_output_stream_steal_data().
209// If you intend to seek you should probably therefore ensure that @data
210// is properly initialised.
211//
212// It is probably only meaningful to provide @data and @size in the case
213// that you want a fixed-sized stream. Put another way: if @realloc_fn
214// is non-%NULL then it makes most sense to give @data as %NULL and
215// @size as 0 (allowing #GMemoryOutputStream to do the initial
216// allocation for itself).
217//
218// |[<!-- language="C" -->
219// // a stream that can grow
220// stream = g_memory_output_stream_new (NULL, 0, realloc, free);
221//
222// // another stream that can grow
223// stream2 = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
224//
225// // a fixed-size stream
226// data = malloc (200);
227// stream3 = g_memory_output_stream_new (data, 200, NULL, free);
228// ]|
229func NewMemoryOutputStream(DataVar uintptr, SizeVar uint, ReallocFunctionVar *ReallocFunc, DestroyFunctionVar *glib.DestroyNotify) *MemoryOutputStream {
230 var cls *MemoryOutputStream
231
232 var ReallocFunctionVarRef uintptr
233 if ReallocFunctionVar != nil {
234 ReallocFunctionVarPtr := uintptr(unsafe.Pointer(ReallocFunctionVar))
235 if cbRefPtr, ok := glib.GetCallback(ReallocFunctionVarPtr); ok {
236 ReallocFunctionVarRef = cbRefPtr
237 } else {
238 fcb := func(arg0 uintptr, arg1 uint) uintptr {
239 cbFn := *ReallocFunctionVar
240 return cbFn(arg0, arg1)
241 }
242 ReallocFunctionVarRef = purego.NewCallback(fcb)
243 glib.SaveCallbackWithClosure(ReallocFunctionVarPtr, ReallocFunctionVarRef, ReallocFunctionVar)
244 }
245 }
246
247 var DestroyFunctionVarRef uintptr
248 if DestroyFunctionVar != nil {
249 DestroyFunctionVarPtr := uintptr(unsafe.Pointer(DestroyFunctionVar))
250 if cbRefPtr, ok := glib.GetCallback(DestroyFunctionVarPtr); ok {
251 DestroyFunctionVarRef = cbRefPtr
252 } else {
253 fcb := func(arg0 uintptr) {
254 cbFn := *DestroyFunctionVar
255 cbFn(arg0)
256 }
257 DestroyFunctionVarRef = purego.NewCallback(fcb)
258 glib.SaveCallbackWithClosure(DestroyFunctionVarPtr, DestroyFunctionVarRef, DestroyFunctionVar)
259 }
260 }
261
262 cret := xNewMemoryOutputStream(DataVar, SizeVar, ReallocFunctionVarRef, DestroyFunctionVarRef)
263
264 if cret == 0 {
265 return nil
266 }
267 cls = &MemoryOutputStream{}
268 cls.Ptr = cret
269 return cls
270}
271
272var xNewMemoryOutputStreamResizable func() uintptr
273
274// Creates a new #GMemoryOutputStream, using g_realloc() and g_free()
275// for memory allocation.
276func NewMemoryOutputStreamResizable() *MemoryOutputStream {
277 var cls *MemoryOutputStream
278
279 cret := xNewMemoryOutputStreamResizable()
280
281 if cret == 0 {
282 return nil
283 }
284 cls = &MemoryOutputStream{}
285 cls.Ptr = cret
286 return cls
287}
288
289var xMemoryOutputStreamGetData func(uintptr) uintptr
290
291// Gets any loaded data from the @ostream.
292//
293// Note that the returned pointer may become invalid on the next
294// write or truncate operation on the stream.
295func (x *MemoryOutputStream) GetData() uintptr {
296
297 cret := xMemoryOutputStreamGetData(x.GoPointer())
298 return cret
299}
300
301var xMemoryOutputStreamGetDataSize func(uintptr) uint
302
303// Returns the number of bytes from the start up to including the last
304// byte written in the stream that has not been truncated away.
305func (x *MemoryOutputStream) GetDataSize() uint {
306
307 cret := xMemoryOutputStreamGetDataSize(x.GoPointer())
308 return cret
309}
310
311var xMemoryOutputStreamGetSize func(uintptr) uint
312
313// Gets the size of the currently allocated data area (available from
314// g_memory_output_stream_get_data()).
315//
316// You probably don't want to use this function on resizable streams.
317// See g_memory_output_stream_get_data_size() instead. For resizable
318// streams the size returned by this function is an implementation
319// detail and may be change at any time in response to operations on the
320// stream.
321//
322// If the stream is fixed-sized (ie: no realloc was passed to
323// g_memory_output_stream_new()) then this is the maximum size of the
324// stream and further writes will return %G_IO_ERROR_NO_SPACE.
325//
326// In any case, if you want the number of bytes currently written to the
327// stream, use g_memory_output_stream_get_data_size().
328func (x *MemoryOutputStream) GetSize() uint {
329
330 cret := xMemoryOutputStreamGetSize(x.GoPointer())
331 return cret
332}
333
334var xMemoryOutputStreamStealAsBytes func(uintptr) *glib.Bytes
335
336// Returns data from the @ostream as a #GBytes. @ostream must be
337// closed before calling this function.
338func (x *MemoryOutputStream) StealAsBytes() *glib.Bytes {
339
340 cret := xMemoryOutputStreamStealAsBytes(x.GoPointer())
341 return cret
342}
343
344var xMemoryOutputStreamStealData func(uintptr) uintptr
345
346// Gets any loaded data from the @ostream. Ownership of the data
347// is transferred to the caller; when no longer needed it must be
348// freed using the free function set in @ostream's
349// #GMemoryOutputStream:destroy-function property.
350//
351// @ostream must be closed before calling this function.
352func (x *MemoryOutputStream) StealData() uintptr {
353
354 cret := xMemoryOutputStreamStealData(x.GoPointer())
355 return cret
356}
357
358func (c *MemoryOutputStream) GoPointer() uintptr {
359 if c == nil {
360 return 0
361 }
362 return c.Ptr
363}
364
365func (c *MemoryOutputStream) SetGoPointer(ptr uintptr) {
366 c.Ptr = ptr
367}
368
369// SetPropertyData sets the "data" property.
370// Pointer to buffer where data will be written.
371func (x *MemoryOutputStream) SetPropertyData(value uintptr) {
372 var v gobject.Value
373 v.Init(gobject.TypePointerVal)
374 v.SetPointer(value)
375 x.SetProperty("data", &v)
376}
377
378// GetPropertyData gets the "data" property.
379// Pointer to buffer where data will be written.
380func (x *MemoryOutputStream) GetPropertyData() uintptr {
381 var v gobject.Value
382 x.GetProperty("data", &v)
383 return v.GetPointer()
384}
385
386// GetPropertyDataSize gets the "data-size" property.
387// Size of data written to the buffer.
388func (x *MemoryOutputStream) GetPropertyDataSize() uint {
389 var v gobject.Value
390 x.GetProperty("data-size", &v)
391 return v.GetUint()
392}
393
394// SetPropertyDestroyFunction sets the "destroy-function" property.
395// Function called with the buffer as argument when the stream is destroyed.
396func (x *MemoryOutputStream) SetPropertyDestroyFunction(value uintptr) {
397 var v gobject.Value
398 v.Init(gobject.TypePointerVal)
399 v.SetPointer(value)
400 x.SetProperty("destroy-function", &v)
401}
402
403// GetPropertyDestroyFunction gets the "destroy-function" property.
404// Function called with the buffer as argument when the stream is destroyed.
405func (x *MemoryOutputStream) GetPropertyDestroyFunction() uintptr {
406 var v gobject.Value
407 x.GetProperty("destroy-function", &v)
408 return v.GetPointer()
409}
410
411// SetPropertyReallocFunction sets the "realloc-function" property.
412// Function with realloc semantics called to enlarge the buffer.
413func (x *MemoryOutputStream) SetPropertyReallocFunction(value uintptr) {
414 var v gobject.Value
415 v.Init(gobject.TypePointerVal)
416 v.SetPointer(value)
417 x.SetProperty("realloc-function", &v)
418}
419
420// GetPropertyReallocFunction gets the "realloc-function" property.
421// Function with realloc semantics called to enlarge the buffer.
422func (x *MemoryOutputStream) GetPropertyReallocFunction() uintptr {
423 var v gobject.Value
424 x.GetProperty("realloc-function", &v)
425 return v.GetPointer()
426}
427
428// SetPropertySize sets the "size" property.
429// Current size of the data buffer.
430func (x *MemoryOutputStream) SetPropertySize(value uint) {
431 var v gobject.Value
432 v.Init(gobject.TypeUintVal)
433 v.SetUint(value)
434 x.SetProperty("size", &v)
435}
436
437// GetPropertySize gets the "size" property.
438// Current size of the data buffer.
439func (x *MemoryOutputStream) GetPropertySize() uint {
440 var v gobject.Value
441 x.GetProperty("size", &v)
442 return v.GetUint()
443}
444
445// Checks if @stream is actually pollable. Some classes may implement
446// #GPollableOutputStream but have only certain instances of that
447// class be pollable. If this method returns %FALSE, then the behavior
448// of other #GPollableOutputStream methods is undefined.
449//
450// For any given stream, the value returned by this method is constant;
451// a stream cannot switch from pollable to non-pollable or vice versa.
452func (x *MemoryOutputStream) CanPoll() bool {
453
454 cret := XGPollableOutputStreamCanPoll(x.GoPointer())
455 return cret
456}
457
458// Creates a #GSource that triggers when @stream can be written, or
459// @cancellable is triggered or an error occurs. The callback on the
460// source is of the #GPollableSourceFunc type.
461//
462// As with g_pollable_output_stream_is_writable(), it is possible that
463// the stream may not actually be writable even after the source
464// triggers, so you should use g_pollable_output_stream_write_nonblocking()
465// rather than g_output_stream_write() from the callback.
466//
467// The behaviour of this method is undefined if
468// g_pollable_output_stream_can_poll() returns %FALSE for @stream.
469func (x *MemoryOutputStream) CreateSource(CancellableVar *Cancellable) *glib.Source {
470
471 cret := XGPollableOutputStreamCreateSource(x.GoPointer(), CancellableVar.GoPointer())
472 return cret
473}
474
475// Checks if @stream can be written.
476//
477// Note that some stream types may not be able to implement this 100%
478// reliably, and it is possible that a call to g_output_stream_write()
479// after this returns %TRUE would still block. To guarantee
480// non-blocking behavior, you should always use
481// g_pollable_output_stream_write_nonblocking(), which will return a
482// %G_IO_ERROR_WOULD_BLOCK error rather than blocking.
483//
484// The behaviour of this method is undefined if
485// g_pollable_output_stream_can_poll() returns %FALSE for @stream.
486func (x *MemoryOutputStream) IsWritable() bool {
487
488 cret := XGPollableOutputStreamIsWritable(x.GoPointer())
489 return cret
490}
491
492// Attempts to write up to @count bytes from @buffer to @stream, as
493// with g_output_stream_write(). If @stream is not currently writable,
494// this will immediately return %G_IO_ERROR_WOULD_BLOCK, and you can
495// use g_pollable_output_stream_create_source() to create a #GSource
496// that will be triggered when @stream is writable.
497//
498// Note that since this method never blocks, you cannot actually
499// use @cancellable to cancel it. However, it will return an error
500// if @cancellable has already been cancelled when you call, which
501// may happen if you call this method after a source triggers due
502// to having been cancelled.
503//
504// Also note that if %G_IO_ERROR_WOULD_BLOCK is returned some underlying
505// transports like D/TLS require that you re-send the same @buffer and
506// @count in the next write call.
507//
508// The behaviour of this method is undefined if
509// g_pollable_output_stream_can_poll() returns %FALSE for @stream.
510func (x *MemoryOutputStream) WriteNonblocking(BufferVar []byte, CountVar uint, CancellableVar *Cancellable) (int, error) {
511 var cerr *glib.Error
512
513 cret := XGPollableOutputStreamWriteNonblocking(x.GoPointer(), BufferVar, CountVar, CancellableVar.GoPointer(), &cerr)
514 if cerr == nil {
515 return cret, nil
516 }
517 return cret, cerr
518
519}
520
521// Attempts to write the bytes contained in the @n_vectors @vectors to @stream,
522// as with g_output_stream_writev(). If @stream is not currently writable,
523// this will immediately return %@G_POLLABLE_RETURN_WOULD_BLOCK, and you can
524// use g_pollable_output_stream_create_source() to create a #GSource
525// that will be triggered when @stream is writable. @error will *not* be
526// set in that case.
527//
528// Note that since this method never blocks, you cannot actually
529// use @cancellable to cancel it. However, it will return an error
530// if @cancellable has already been cancelled when you call, which
531// may happen if you call this method after a source triggers due
532// to having been cancelled.
533//
534// Also note that if %G_POLLABLE_RETURN_WOULD_BLOCK is returned some underlying
535// transports like D/TLS require that you re-send the same @vectors and
536// @n_vectors in the next write call.
537//
538// The behaviour of this method is undefined if
539// g_pollable_output_stream_can_poll() returns %FALSE for @stream.
540func (x *MemoryOutputStream) WritevNonblocking(VectorsVar []OutputVector, NVectorsVar uint, BytesWrittenVar *uint, CancellableVar *Cancellable) (PollableReturn, error) {
541 var cerr *glib.Error
542
543 cret := XGPollableOutputStreamWritevNonblocking(x.GoPointer(), VectorsVar, NVectorsVar, BytesWrittenVar, CancellableVar.GoPointer(), &cerr)
544 if cerr == nil {
545 return cret, nil
546 }
547 return cret, cerr
548
549}
550
551// Tests if the stream supports the #GSeekableIface.
552func (x *MemoryOutputStream) CanSeek() bool {
553
554 cret := XGSeekableCanSeek(x.GoPointer())
555 return cret
556}
557
558// Tests if the length of the stream can be adjusted with
559// g_seekable_truncate().
560func (x *MemoryOutputStream) CanTruncate() bool {
561
562 cret := XGSeekableCanTruncate(x.GoPointer())
563 return cret
564}
565
566// Seeks in the stream by the given @offset, modified by @type.
567//
568// Attempting to seek past the end of the stream will have different
569// results depending on if the stream is fixed-sized or resizable. If
570// the stream is resizable then seeking past the end and then writing
571// will result in zeros filling the empty space. Seeking past the end
572// of a resizable stream and reading will result in EOF. Seeking past
573// the end of a fixed-sized stream will fail.
574//
575// Any operation that would result in a negative offset will fail.
576//
577// If @cancellable is not %NULL, then the operation can be cancelled by
578// triggering the cancellable object from another thread. If the operation
579// was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
580func (x *MemoryOutputStream) Seek(OffsetVar int64, TypeVar glib.SeekType, CancellableVar *Cancellable) (bool, error) {
581 var cerr *glib.Error
582
583 cret := XGSeekableSeek(x.GoPointer(), OffsetVar, TypeVar, CancellableVar.GoPointer(), &cerr)
584 if cerr == nil {
585 return cret, nil
586 }
587 return cret, cerr
588
589}
590
591// Tells the current position within the stream.
592func (x *MemoryOutputStream) Tell() int64 {
593
594 cret := XGSeekableTell(x.GoPointer())
595 return cret
596}
597
598// Sets the length of the stream to @offset. If the stream was previously
599// larger than @offset, the extra data is discarded. If the stream was
600// previously shorter than @offset, it is extended with NUL ('\0') bytes.
601//
602// If @cancellable is not %NULL, then the operation can be cancelled by
603// triggering the cancellable object from another thread. If the operation
604// was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
605// operation was partially finished when the operation was cancelled the
606// partial result will be returned, without an error.
607func (x *MemoryOutputStream) Truncate(OffsetVar int64, CancellableVar *Cancellable) (bool, error) {
608 var cerr *glib.Error
609
610 cret := XGSeekableTruncate(x.GoPointer(), OffsetVar, CancellableVar.GoPointer(), &cerr)
611 if cerr == nil {
612 return cret, nil
613 }
614 return cret, cerr
615
616}
617
618func init() {
619 core.SetPackageName("GIO", "gio-2.0")
620 core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
621 var libs []uintptr
622 for _, libPath := range core.GetPaths("GIO") {
623 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
624 if err != nil {
625 panic(err)
626 }
627 libs = append(libs, lib)
628 }
629
630 core.PuregoSafeRegister(&xMemoryOutputStreamGLibType, libs, "g_memory_output_stream_get_type")
631
632 core.PuregoSafeRegister(&xNewMemoryOutputStream, libs, "g_memory_output_stream_new")
633 core.PuregoSafeRegister(&xNewMemoryOutputStreamResizable, libs, "g_memory_output_stream_new_resizable")
634
635 core.PuregoSafeRegister(&xMemoryOutputStreamGetData, libs, "g_memory_output_stream_get_data")
636 core.PuregoSafeRegister(&xMemoryOutputStreamGetDataSize, libs, "g_memory_output_stream_get_data_size")
637 core.PuregoSafeRegister(&xMemoryOutputStreamGetSize, libs, "g_memory_output_stream_get_size")
638 core.PuregoSafeRegister(&xMemoryOutputStreamStealAsBytes, libs, "g_memory_output_stream_steal_as_bytes")
639 core.PuregoSafeRegister(&xMemoryOutputStreamStealData, libs, "g_memory_output_stream_steal_data")
640
641}