1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gst.base.ByteWriter;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gst.base.c.functions;
31 public  import gst.base.c.types;
32 private import gstreamer.Buffer;
33 private import gtkd.Loader;
34 
35 
36 /**
37  * #GstByteWriter provides a byte writer and reader that can write/read different
38  * integer and floating point types to/from a memory buffer. It provides functions
39  * for writing/reading signed/unsigned, little/big endian integers of 8, 16, 24,
40  * 32 and 64 bits and functions for reading little/big endian floating points numbers of
41  * 32 and 64 bits. It also provides functions to write/read NUL-terminated strings
42  * in various character encodings.
43  */
44 public class ByteWriter
45 {
46 	/** the main Gtk struct */
47 	protected GstByteWriter* gstByteWriter;
48 	protected bool ownedRef;
49 
50 	/** Get the main Gtk struct */
51 	public GstByteWriter* getByteWriterStruct(bool transferOwnership = false)
52 	{
53 		if (transferOwnership)
54 			ownedRef = false;
55 		return gstByteWriter;
56 	}
57 
58 	/** the main Gtk struct as a void* */
59 	protected void* getStruct()
60 	{
61 		return cast(void*)gstByteWriter;
62 	}
63 
64 	/**
65 	 * Sets our main struct and passes it to the parent class.
66 	 */
67 	public this (GstByteWriter* gstByteWriter, bool ownedRef = false)
68 	{
69 		this.gstByteWriter = gstByteWriter;
70 		this.ownedRef = ownedRef;
71 	}
72 
73 	~this ()
74 	{
75 		if ( Linker.isLoaded(LIBRARY_GSTBASE) && ownedRef )
76 			gst_byte_writer_free(gstByteWriter);
77 	}
78 
79 	/**
80 	 * Frees @writer and all memory allocated by it except
81 	 * the current data, which is returned.
82 	 *
83 	 * Free-function: g_free
84 	 *
85 	 * Returns: the current data. g_free() after usage.
86 	 */
87 	public ubyte[] freeAndGetData()
88 	{
89 		ubyte* p = gst_byte_writer_free_and_get_data(gstByteWriter);
90 		ownedRef = false;
91 		return p[0 .. gstByteWriter.parent.size];
92 	}
93 
94 	/**
95 	 * Resets @writer and returns the current data.
96 	 *
97 	 * Free-function: g_free
98 	 *
99 	 * Returns: the current data. g_free() after
100 	 *     usage.
101 	 */
102 	public ubyte[] resetAndGetData()
103 	{
104 		auto p = gst_byte_writer_reset_and_get_data(gstByteWriter);
105 
106 		return p[0 .. gstByteWriter.parent.size];
107 	}
108 
109 	/**
110 	 */
111 
112 	/**
113 	 * Checks if enough free space from the current write cursor is
114 	 * available and reallocates if necessary.
115 	 *
116 	 * Params:
117 	 *     size = Number of bytes that should be available
118 	 *
119 	 * Returns: %TRUE if at least @size bytes are still available
120 	 */
121 	public bool ensureFreeSpace(uint size)
122 	{
123 		return gst_byte_writer_ensure_free_space(gstByteWriter, size) != 0;
124 	}
125 
126 	/**
127 	 * Writes @size bytes containing @value to @writer.
128 	 *
129 	 * Params:
130 	 *     value = Value to be written
131 	 *     size = Number of bytes to be written
132 	 *
133 	 * Returns: %TRUE if the value could be written
134 	 */
135 	public bool fill(ubyte value, uint size)
136 	{
137 		return gst_byte_writer_fill(gstByteWriter, value, size) != 0;
138 	}
139 
140 	/**
141 	 * Frees @writer and all memory allocated by it.
142 	 */
143 	public void free()
144 	{
145 		gst_byte_writer_free(gstByteWriter);
146 		ownedRef = false;
147 	}
148 
149 	/**
150 	 * Frees @writer and all memory allocated by it except
151 	 * the current data, which is returned as #GstBuffer.
152 	 *
153 	 * Free-function: gst_buffer_unref
154 	 *
155 	 * Returns: the current data as buffer. gst_buffer_unref()
156 	 *     after usage.
157 	 */
158 	public Buffer freeAndGetBuffer()
159 	{
160 		auto p = gst_byte_writer_free_and_get_buffer(gstByteWriter);
161 
162 		if(p is null)
163 		{
164 			return null;
165 		}
166 
167 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true);
168 	}
169 
170 	/**
171 	 * Returns the remaining size of data that can still be written. If
172 	 * -1 is returned the remaining size is only limited by system resources.
173 	 *
174 	 * Returns: the remaining size of data that can still be written
175 	 */
176 	public uint getRemaining()
177 	{
178 		return gst_byte_writer_get_remaining(gstByteWriter);
179 	}
180 
181 	/**
182 	 * Initializes @writer to an empty instance
183 	 */
184 	public void init()
185 	{
186 		gst_byte_writer_init(gstByteWriter);
187 	}
188 
189 	/**
190 	 * Initializes @writer with the given
191 	 * memory area. If @initialized is %TRUE it is possible to
192 	 * read @size bytes from the #GstByteWriter from the beginning.
193 	 *
194 	 * Params:
195 	 *     data = Memory area for writing
196 	 *     initialized = If %TRUE the complete data can be read from the beginning
197 	 */
198 	public void initWithData(ubyte[] data, bool initialized)
199 	{
200 		gst_byte_writer_init_with_data(gstByteWriter, data.ptr, cast(uint)data.length, initialized);
201 	}
202 
203 	/**
204 	 * Initializes @writer with the given initial data size.
205 	 *
206 	 * Params:
207 	 *     size = Initial size of data
208 	 *     fixed = If %TRUE the data can't be reallocated
209 	 */
210 	public void initWithSize(uint size, bool fixed)
211 	{
212 		gst_byte_writer_init_with_size(gstByteWriter, size, fixed);
213 	}
214 
215 	/**
216 	 * Writes @size bytes of @data to @writer.
217 	 *
218 	 * Params:
219 	 *     buffer = source #GstBuffer
220 	 *     offset = offset to copy from
221 	 *     size = total size to copy. If -1, all data is copied
222 	 *
223 	 * Returns: %TRUE if the data could be written
224 	 */
225 	public bool putBuffer(Buffer buffer, size_t offset, ptrdiff_t size)
226 	{
227 		return gst_byte_writer_put_buffer(gstByteWriter, (buffer is null) ? null : buffer.getBufferStruct(), offset, size) != 0;
228 	}
229 
230 	/**
231 	 * Writes @size bytes of @data to @writer.
232 	 *
233 	 * Params:
234 	 *     data = Data to write
235 	 *
236 	 * Returns: %TRUE if the value could be written
237 	 */
238 	public bool putData(ubyte[] data)
239 	{
240 		return gst_byte_writer_put_data(gstByteWriter, data.ptr, cast(uint)data.length) != 0;
241 	}
242 
243 	/**
244 	 * Writes a big endian 32 bit float to @writer.
245 	 *
246 	 * Params:
247 	 *     val = Value to write
248 	 *
249 	 * Returns: %TRUE if the value could be written
250 	 */
251 	public bool putFloat32Be(float val)
252 	{
253 		return gst_byte_writer_put_float32_be(gstByteWriter, val) != 0;
254 	}
255 
256 	/**
257 	 * Writes a little endian 32 bit float to @writer.
258 	 *
259 	 * Params:
260 	 *     val = Value to write
261 	 *
262 	 * Returns: %TRUE if the value could be written
263 	 */
264 	public bool putFloat32Le(float val)
265 	{
266 		return gst_byte_writer_put_float32_le(gstByteWriter, val) != 0;
267 	}
268 
269 	/**
270 	 * Writes a big endian 64 bit float to @writer.
271 	 *
272 	 * Params:
273 	 *     val = Value to write
274 	 *
275 	 * Returns: %TRUE if the value could be written
276 	 */
277 	public bool putFloat64Be(double val)
278 	{
279 		return gst_byte_writer_put_float64_be(gstByteWriter, val) != 0;
280 	}
281 
282 	/**
283 	 * Writes a little endian 64 bit float to @writer.
284 	 *
285 	 * Params:
286 	 *     val = Value to write
287 	 *
288 	 * Returns: %TRUE if the value could be written
289 	 */
290 	public bool putFloat64Le(double val)
291 	{
292 		return gst_byte_writer_put_float64_le(gstByteWriter, val) != 0;
293 	}
294 
295 	/**
296 	 * Writes a signed big endian 16 bit integer to @writer.
297 	 *
298 	 * Params:
299 	 *     val = Value to write
300 	 *
301 	 * Returns: %TRUE if the value could be written
302 	 */
303 	public bool putInt16Be(short val)
304 	{
305 		return gst_byte_writer_put_int16_be(gstByteWriter, val) != 0;
306 	}
307 
308 	/**
309 	 * Writes a signed little endian 16 bit integer to @writer.
310 	 *
311 	 * Params:
312 	 *     val = Value to write
313 	 *
314 	 * Returns: %TRUE if the value could be written
315 	 */
316 	public bool putInt16Le(short val)
317 	{
318 		return gst_byte_writer_put_int16_le(gstByteWriter, val) != 0;
319 	}
320 
321 	/**
322 	 * Writes a signed big endian 24 bit integer to @writer.
323 	 *
324 	 * Params:
325 	 *     val = Value to write
326 	 *
327 	 * Returns: %TRUE if the value could be written
328 	 */
329 	public bool putInt24Be(int val)
330 	{
331 		return gst_byte_writer_put_int24_be(gstByteWriter, val) != 0;
332 	}
333 
334 	/**
335 	 * Writes a signed little endian 24 bit integer to @writer.
336 	 *
337 	 * Params:
338 	 *     val = Value to write
339 	 *
340 	 * Returns: %TRUE if the value could be written
341 	 */
342 	public bool putInt24Le(int val)
343 	{
344 		return gst_byte_writer_put_int24_le(gstByteWriter, val) != 0;
345 	}
346 
347 	/**
348 	 * Writes a signed big endian 32 bit integer to @writer.
349 	 *
350 	 * Params:
351 	 *     val = Value to write
352 	 *
353 	 * Returns: %TRUE if the value could be written
354 	 */
355 	public bool putInt32Be(int val)
356 	{
357 		return gst_byte_writer_put_int32_be(gstByteWriter, val) != 0;
358 	}
359 
360 	/**
361 	 * Writes a signed little endian 32 bit integer to @writer.
362 	 *
363 	 * Params:
364 	 *     val = Value to write
365 	 *
366 	 * Returns: %TRUE if the value could be written
367 	 */
368 	public bool putInt32Le(int val)
369 	{
370 		return gst_byte_writer_put_int32_le(gstByteWriter, val) != 0;
371 	}
372 
373 	/**
374 	 * Writes a signed big endian 64 bit integer to @writer.
375 	 *
376 	 * Params:
377 	 *     val = Value to write
378 	 *
379 	 * Returns: %TRUE if the value could be written
380 	 */
381 	public bool putInt64Be(long val)
382 	{
383 		return gst_byte_writer_put_int64_be(gstByteWriter, val) != 0;
384 	}
385 
386 	/**
387 	 * Writes a signed little endian 64 bit integer to @writer.
388 	 *
389 	 * Params:
390 	 *     val = Value to write
391 	 *
392 	 * Returns: %TRUE if the value could be written
393 	 */
394 	public bool putInt64Le(long val)
395 	{
396 		return gst_byte_writer_put_int64_le(gstByteWriter, val) != 0;
397 	}
398 
399 	/**
400 	 * Writes a signed 8 bit integer to @writer.
401 	 *
402 	 * Params:
403 	 *     val = Value to write
404 	 *
405 	 * Returns: %TRUE if the value could be written
406 	 */
407 	public bool putInt8(byte val)
408 	{
409 		return gst_byte_writer_put_int8(gstByteWriter, val) != 0;
410 	}
411 
412 	/**
413 	 * Writes a NUL-terminated UTF16 string to @writer (including the terminator).
414 	 *
415 	 * Params:
416 	 *     data = UTF16 string to write
417 	 *
418 	 * Returns: %TRUE if the value could be written
419 	 */
420 	public bool putStringUtf16(ushort[] data)
421 	{
422 		return gst_byte_writer_put_string_utf16(gstByteWriter, data.ptr) != 0;
423 	}
424 
425 	/**
426 	 * Writes a NUL-terminated UTF32 string to @writer (including the terminator).
427 	 *
428 	 * Params:
429 	 *     data = UTF32 string to write
430 	 *
431 	 * Returns: %TRUE if the value could be written
432 	 */
433 	public bool putStringUtf32(uint[] data)
434 	{
435 		return gst_byte_writer_put_string_utf32(gstByteWriter, data.ptr) != 0;
436 	}
437 
438 	/**
439 	 * Writes a NUL-terminated UTF8 string to @writer (including the terminator).
440 	 *
441 	 * Params:
442 	 *     data = UTF8 string to write
443 	 *
444 	 * Returns: %TRUE if the value could be written
445 	 */
446 	public bool putStringUtf8(string data)
447 	{
448 		return gst_byte_writer_put_string_utf8(gstByteWriter, Str.toStringz(data)) != 0;
449 	}
450 
451 	/**
452 	 * Writes a unsigned big endian 16 bit integer to @writer.
453 	 *
454 	 * Params:
455 	 *     val = Value to write
456 	 *
457 	 * Returns: %TRUE if the value could be written
458 	 */
459 	public bool putUint16Be(ushort val)
460 	{
461 		return gst_byte_writer_put_uint16_be(gstByteWriter, val) != 0;
462 	}
463 
464 	/**
465 	 * Writes a unsigned little endian 16 bit integer to @writer.
466 	 *
467 	 * Params:
468 	 *     val = Value to write
469 	 *
470 	 * Returns: %TRUE if the value could be written
471 	 */
472 	public bool putUint16Le(ushort val)
473 	{
474 		return gst_byte_writer_put_uint16_le(gstByteWriter, val) != 0;
475 	}
476 
477 	/**
478 	 * Writes a unsigned big endian 24 bit integer to @writer.
479 	 *
480 	 * Params:
481 	 *     val = Value to write
482 	 *
483 	 * Returns: %TRUE if the value could be written
484 	 */
485 	public bool putUint24Be(uint val)
486 	{
487 		return gst_byte_writer_put_uint24_be(gstByteWriter, val) != 0;
488 	}
489 
490 	/**
491 	 * Writes a unsigned little endian 24 bit integer to @writer.
492 	 *
493 	 * Params:
494 	 *     val = Value to write
495 	 *
496 	 * Returns: %TRUE if the value could be written
497 	 */
498 	public bool putUint24Le(uint val)
499 	{
500 		return gst_byte_writer_put_uint24_le(gstByteWriter, val) != 0;
501 	}
502 
503 	/**
504 	 * Writes a unsigned big endian 32 bit integer to @writer.
505 	 *
506 	 * Params:
507 	 *     val = Value to write
508 	 *
509 	 * Returns: %TRUE if the value could be written
510 	 */
511 	public bool putUint32Be(uint val)
512 	{
513 		return gst_byte_writer_put_uint32_be(gstByteWriter, val) != 0;
514 	}
515 
516 	/**
517 	 * Writes a unsigned little endian 32 bit integer to @writer.
518 	 *
519 	 * Params:
520 	 *     val = Value to write
521 	 *
522 	 * Returns: %TRUE if the value could be written
523 	 */
524 	public bool putUint32Le(uint val)
525 	{
526 		return gst_byte_writer_put_uint32_le(gstByteWriter, val) != 0;
527 	}
528 
529 	/**
530 	 * Writes a unsigned big endian 64 bit integer to @writer.
531 	 *
532 	 * Params:
533 	 *     val = Value to write
534 	 *
535 	 * Returns: %TRUE if the value could be written
536 	 */
537 	public bool putUint64Be(ulong val)
538 	{
539 		return gst_byte_writer_put_uint64_be(gstByteWriter, val) != 0;
540 	}
541 
542 	/**
543 	 * Writes a unsigned little endian 64 bit integer to @writer.
544 	 *
545 	 * Params:
546 	 *     val = Value to write
547 	 *
548 	 * Returns: %TRUE if the value could be written
549 	 */
550 	public bool putUint64Le(ulong val)
551 	{
552 		return gst_byte_writer_put_uint64_le(gstByteWriter, val) != 0;
553 	}
554 
555 	/**
556 	 * Writes a unsigned 8 bit integer to @writer.
557 	 *
558 	 * Params:
559 	 *     val = Value to write
560 	 *
561 	 * Returns: %TRUE if the value could be written
562 	 */
563 	public bool putUint8(ubyte val)
564 	{
565 		return gst_byte_writer_put_uint8(gstByteWriter, val) != 0;
566 	}
567 
568 	/**
569 	 * Resets @writer and frees the data if it's
570 	 * owned by @writer.
571 	 */
572 	public void reset()
573 	{
574 		gst_byte_writer_reset(gstByteWriter);
575 	}
576 
577 	/**
578 	 * Resets @writer and returns the current data as buffer.
579 	 *
580 	 * Free-function: gst_buffer_unref
581 	 *
582 	 * Returns: the current data as buffer. gst_buffer_unref()
583 	 *     after usage.
584 	 */
585 	public Buffer resetAndGetBuffer()
586 	{
587 		auto p = gst_byte_writer_reset_and_get_buffer(gstByteWriter);
588 
589 		if(p is null)
590 		{
591 			return null;
592 		}
593 
594 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true);
595 	}
596 
597 	/**
598 	 * Creates a new, empty #GstByteWriter instance
599 	 *
600 	 * Free-function: gst_byte_writer_free
601 	 *
602 	 * Returns: a new, empty #GstByteWriter instance
603 	 *
604 	 * Throws: ConstructionException GTK+ fails to create the object.
605 	 */
606 	public this()
607 	{
608 		auto p = gst_byte_writer_new();
609 
610 		if(p is null)
611 		{
612 			throw new ConstructionException("null returned by new");
613 		}
614 
615 		this(cast(GstByteWriter*) p);
616 	}
617 
618 	/**
619 	 * Creates a new #GstByteWriter instance with the given
620 	 * memory area. If @initialized is %TRUE it is possible to
621 	 * read @size bytes from the #GstByteWriter from the beginning.
622 	 *
623 	 * Free-function: gst_byte_writer_free
624 	 *
625 	 * Params:
626 	 *     data = Memory area for writing
627 	 *     initialized = If %TRUE the complete data can be read from the beginning
628 	 *
629 	 * Returns: a new #GstByteWriter instance
630 	 *
631 	 * Throws: ConstructionException GTK+ fails to create the object.
632 	 */
633 	public this(ubyte[] data, bool initialized)
634 	{
635 		auto p = gst_byte_writer_new_with_data(data.ptr, cast(uint)data.length, initialized);
636 
637 		if(p is null)
638 		{
639 			throw new ConstructionException("null returned by new_with_data");
640 		}
641 
642 		this(cast(GstByteWriter*) p);
643 	}
644 
645 	/**
646 	 * Creates a new #GstByteWriter instance with the given
647 	 * initial data size.
648 	 *
649 	 * Free-function: gst_byte_writer_free
650 	 *
651 	 * Params:
652 	 *     size = Initial size of data
653 	 *     fixed = If %TRUE the data can't be reallocated
654 	 *
655 	 * Returns: a new #GstByteWriter instance
656 	 *
657 	 * Throws: ConstructionException GTK+ fails to create the object.
658 	 */
659 	public this(uint size, bool fixed)
660 	{
661 		auto p = gst_byte_writer_new_with_size(size, fixed);
662 
663 		if(p is null)
664 		{
665 			throw new ConstructionException("null returned by new_with_size");
666 		}
667 
668 		this(cast(GstByteWriter*) p);
669 	}
670 }