N-ByteArray

#------------------------------------------------------------------------------- #--[Class Description]---------------------------------------------------------- #-------------------------------------------------------------------------------

Gnome::Glib::N-ByteArray

Description

Contains the public fields of a GByteArray.

#------------------------------------------------------------------------------- #--[Class Initialization]------------------------------------------------------- #-------------------------------------------------------------------------------

Class initialization

new

:native-object

Create an object using a native object from elsewhere. See also Gnome::N::TopLevelSupportClass.

multi method new ( N-Object :$native-object! )

#------------------------------------------------------------------------------- #--[Functions]------------------------------------------------------------------ #-------------------------------------------------------------------------------

Functions

#-------------------------------------------------------------------------------

append

Adds the given bytes to the end of the Gnome::Glib::N-ByteArray. The array will grow in size automatically if necessary.

method append ( N-Object $array, Array[Int] $data, UInt() $len --> N-Object )
  • $array; a Gnome::Glib::N-ByteArray

  • $data; the byte data to be added.

  • $len; the number of bytes to add.

Return value; the Gnome::Glib::N-ByteArray.

#-------------------------------------------------------------------------------

free

Frees the memory allocated by the Gnome::Glib::N-ByteArray. If $free-segment is True it frees the actual byte data. If the reference count of $array is greater than one, the Gnome::Glib::N-ByteArray wrapper is preserved but the size of $array will be set to zero.

method free ( N-Object $array, Bool() $free-segment --> Array[Int] )
  • $array; a Gnome::Glib::N-ByteArray

  • $free-segment; if True the actual byte data is freed as well.

Return value; the element data if $free-segment is False, otherwise undefined. The element data should be freed using g_free()..

#-------------------------------------------------------------------------------

free-to-bytes

Transfers the data from the Gnome::Glib::N-ByteArray into a new immutable Gnome::Glib::N-Bytes.

The Gnome::Glib::N-ByteArray is freed unless the reference count of $array is greater than one, the Gnome::Glib::N-ByteArray wrapper is preserved but the size of $array will be set to zero.

This is identical to using g_bytes_new_take() and .free() together.

method free-to-bytes ( N-Object $array --> N-Object )
  • $array; (transfer ownership: full) a Gnome::Glib::N-ByteArray

Return value; a new immutable Gnome::Glib::N-Bytes representing same byte data that was in the array.

#-------------------------------------------------------------------------------

new

Creates a new Gnome::Glib::N-ByteArray with a reference count of 1.

method new (--> N-Object )

Return value; the new Gnome::Glib::N-ByteArray.

#-------------------------------------------------------------------------------

new-take

Create byte array containing the data. The data will be owned by the array and will be freed with g_free(), i.e. it could be allocated using g_strdup().

Do not use it if $len is greater than G_MAXUINT. Gnome::Glib::N-ByteArray stores the length of its data in #guint, which may be shorter than #gsize.

method new-take ( Array[Int] $data, Int() $len --> N-Object )
  • $data; (transfer ownership: full) byte data for the array.

  • $len; length of $data.

Return value; a new Gnome::Glib::N-ByteArray.

#-------------------------------------------------------------------------------

prepend

Adds the given data to the start of the Gnome::Glib::N-ByteArray. The array will grow in size automatically if necessary.

method prepend ( N-Object $array, Array[Int] $data, UInt() $len --> N-Object )
  • $array; a Gnome::Glib::N-ByteArray

  • $data; the byte data to be added.

  • $len; the number of bytes to add.

Return value; the Gnome::Glib::N-ByteArray.

#-------------------------------------------------------------------------------

ref

Atomically increments the reference count of $array by one. This function is thread-safe and may be called from any thread.

method ref ( N-Object $array --> N-Object )
  • $array; A Gnome::Glib::N-ByteArray

Return value; The passed in Gnome::Glib::N-ByteArray.

#-------------------------------------------------------------------------------

remove-index

Removes the byte at the given index from a Gnome::Glib::N-ByteArray. The following bytes are moved down one place.

method remove-index ( N-Object $array, UInt() $index --> N-Object )
  • $array; a Gnome::Glib::N-ByteArray

  • $index; the index of the byte to remove.

Return value; the Gnome::Glib::N-ByteArray.

#-------------------------------------------------------------------------------

remove-index-fast

Removes the byte at the given index from a Gnome::Glib::N-ByteArray. The last element in the array is used to fill in the space, so this function does not preserve the order of the Gnome::Glib::N-ByteArray. But it is faster than .remove-index().

method remove-index-fast ( N-Object $array, UInt() $index --> N-Object )
  • $array; a Gnome::Glib::N-ByteArray

  • $index; the index of the byte to remove.

Return value; the Gnome::Glib::N-ByteArray.

#-------------------------------------------------------------------------------

remove-range

Removes the given number of bytes starting at the given index from a Gnome::Glib::N-ByteArray. The following elements are moved to close the gap.

method remove-range ( N-Object $array, UInt() $index, UInt() $length --> N-Object )
  • $array; a $GByteArray

  • $index; the index of the first byte to remove.

  • $length; the number of bytes to remove.

Return value; the Gnome::Glib::N-ByteArray.

#-------------------------------------------------------------------------------

set-size

Sets the size of the Gnome::Glib::N-ByteArray, expanding it if necessary.

method set-size ( N-Object $array, UInt() $length --> N-Object )
  • $array; a Gnome::Glib::N-ByteArray

  • $length; the new size of the Gnome::Glib::N-ByteArray.

Return value; the Gnome::Glib::N-ByteArray.

#-------------------------------------------------------------------------------

sized-new

Creates a new Gnome::Glib::N-ByteArray with $reserved-size bytes preallocated. This avoids frequent reallocation, if you are going to add many bytes to the array. Note however that the size of the array is still 0.

method sized-new ( UInt() $reserved-size --> N-Object )
  • $reserved-size; number of bytes preallocated.

Return value; the new Gnome::Glib::N-ByteArray.

#-------------------------------------------------------------------------------

sort

Sorts a byte array, using $compare-func which should be a qsort()-style comparison function (returns less than zero for first arg is less than second arg, zero for equal, greater than zero if first arg is greater than second arg).

If two array elements compare equal, their order in the sorted array is undefined. If you want equal elements to keep their order (i.e. you want a stable sort) you can write a comparison function that, if two elements would otherwise compare equal, compares them by their addresses.

method sort ( N-Object $array, &compare-func )
  • $array; a Gnome::Glib::N-ByteArray

  • &compare-func; comparison function. Tthe function must be specified with following signature; :( gpointer $a, gpointer $b -- gint )>.

#-------------------------------------------------------------------------------

sort-with-data

Like .sort(), but the comparison function takes an extra user data argument.

method sort-with-data ( N-Object $array, &compare-func, gpointer $user-data )
  • $array; a Gnome::Glib::N-ByteArray

  • &compare-func; comparison function. Tthe function must be specified with following signature; :( gpointer $a, gpointer $b, gpointer $user-data -- gint )>.

  • $user-data; data to pass to $compare-func.

#-------------------------------------------------------------------------------

steal

Frees the data in the array and resets the size to zero, while the underlying array is preserved for use elsewhere and returned to the caller.

method steal ( N-Object $array, Array[gsize] $len --> Array[Int] )
  • $array; a Gnome::Glib::N-ByteArray.

  • $len; (transfer ownership: full) pointer to retrieve the number of elements of the original array.

Return value; the element data, which should be freed using g_free()..

#-------------------------------------------------------------------------------

unref

Atomically decrements the reference count of $array by one. If the reference count drops to 0, all memory allocated by the array is released. This function is thread-safe and may be called from any thread.

method unref ( N-Object $array )
  • $array; A Gnome::Glib::N-ByteArray

Gnome::Glib v0.1.12

Modules for package Gnome::Glib:api<2>. The language binding to GNOME's lowest level library

Authors

    License

    Artistic-2.0

    Dependencies

    Gnome::N:api<2>

    Test Dependencies

    Provides

    • Gnome::Glib::N-Array
    • Gnome::Glib::N-ByteArray
    • Gnome::Glib::N-Bytes
    • Gnome::Glib::N-Error
    • Gnome::Glib::N-List
    • Gnome::Glib::N-MainContext
    • Gnome::Glib::N-MainLoop
    • Gnome::Glib::N-PtrArray
    • Gnome::Glib::N-SList
    • Gnome::Glib::N-Variant
    • Gnome::Glib::N-VariantBuilder
    • Gnome::Glib::N-VariantDict
    • Gnome::Glib::N-VariantIter
    • Gnome::Glib::N-VariantType
    • Gnome::Glib::T-array
    • Gnome::Glib::T-error
    • Gnome::Glib::T-list
    • Gnome::Glib::T-main
    • Gnome::Glib::T-quark
    • Gnome::Glib::T-slist
    • Gnome::Glib::T-variant
    • Gnome::Glib::T-varianttype

    The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.