gi-glib-2.0.12: GLib bindings

CopyrightWill Thompson, Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria (garetxe@gmail.com)
Safe HaskellNone
LanguageHaskell2010

GI.GLib.Structs.Bytes

Contents

Description

A simple refcounted data type representing an immutable sequence of zero or more bytes from an unspecified origin.

The purpose of a Bytes is to keep the memory region that it holds alive for as long as anyone holds a reference to the bytes. When the last reference count is dropped, the memory is released. Multiple unrelated callers can use byte data in the Bytes without coordinating their activities, resting assured that the byte data will not change or move while they hold a reference.

A Bytes can come from many different origins that may have different procedures for freeing the memory region. Examples are memory from malloc, from memory slices, from a MappedFile or memory from other allocators.

Bytes work well as keys in HashTable. Use bytesEqual and bytesHash as parameters to g_hash_table_new() or g_hash_table_new_full(). Bytes can also be used as keys in a Tree by passing the bytesCompare function to g_tree_new().

The data pointed to by this bytes must not be modified. For a mutable array of bytes see ByteArray. Use bytesUnrefToArray to create a mutable array for a Bytes sequence. To create an immutable Bytes from a mutable ByteArray, use the byteArrayFreeToBytes function.

Synopsis

Exported types

newtype Bytes Source #

Constructors

Bytes (ManagedPtr Bytes) 

Instances

BoxedObject Bytes Source # 

Methods

boxedType :: Bytes -> IO GType #

((~) * info (ResolveBytesMethod t Bytes), MethodInfo * info Bytes p) => IsLabel t (Bytes -> p) Source # 

Methods

fromLabel :: Proxy# Symbol t -> Bytes -> p #

((~) * info (ResolveBytesMethod t Bytes), MethodInfo * info Bytes p) => IsLabelProxy t (Bytes -> p) Source # 

Methods

fromLabelProxy :: Proxy Symbol t -> Bytes -> p #

HasAttributeList * Bytes Source # 
((~) * signature (m ByteString), MonadIO m) => MethodInfo * BytesUnrefToDataMethodInfo Bytes signature Source # 
((~) * signature (m ByteString), MonadIO m) => MethodInfo * BytesUnrefToArrayMethodInfo Bytes signature Source # 
((~) * signature (m ()), MonadIO m) => MethodInfo * BytesUnrefMethodInfo Bytes signature Source # 
((~) * signature (m Bytes), MonadIO m) => MethodInfo * BytesRefMethodInfo Bytes signature Source # 
((~) * signature (Word64 -> Word64 -> m Bytes), MonadIO m) => MethodInfo * BytesNewFromBytesMethodInfo Bytes signature Source # 
((~) * signature (m Word32), MonadIO m) => MethodInfo * BytesHashMethodInfo Bytes signature Source # 
((~) * signature (m Word64), MonadIO m) => MethodInfo * BytesGetSizeMethodInfo Bytes signature Source # 
((~) * signature (m (Maybe ByteString)), MonadIO m) => MethodInfo * BytesGetDataMethodInfo Bytes signature Source # 
((~) * signature (Bytes -> m Bool), MonadIO m) => MethodInfo * BytesEqualMethodInfo Bytes signature Source # 
((~) * signature (Bytes -> m Int32), MonadIO m) => MethodInfo * BytesCompareMethodInfo Bytes signature Source # 
type AttributeList Bytes Source # 

Methods

compare

data BytesCompareMethodInfo Source #

Instances

((~) * signature (Bytes -> m Int32), MonadIO m) => MethodInfo * BytesCompareMethodInfo Bytes signature Source # 

bytesCompare Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Bytes

bytes1: a pointer to a Bytes

-> Bytes

bytes2: a pointer to a Bytes to compare with bytes1

-> m Int32

Returns: a negative value if bytes2 is lesser, a positive value if bytes2 is greater, and zero if bytes2 is equal to bytes1

Compares the two Bytes values.

This function can be used to sort GBytes instances in lexographical order.

Since: 2.32

equal

data BytesEqualMethodInfo Source #

Instances

((~) * signature (Bytes -> m Bool), MonadIO m) => MethodInfo * BytesEqualMethodInfo Bytes signature Source # 

bytesEqual Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Bytes

bytes1: a pointer to a Bytes

-> Bytes

bytes2: a pointer to a Bytes to compare with bytes1

-> m Bool

Returns: True if the two keys match.

Compares the two Bytes values being pointed to and returns True if they are equal.

This function can be passed to g_hash_table_new() as the keyEqualFunc parameter, when using non-Nothing Bytes pointers as keys in a HashTable.

Since: 2.32

getData

bytesGetData Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Bytes

bytes: a Bytes

-> m (Maybe ByteString)

Returns: a pointer to the byte data, or Nothing

Get the byte data in the Bytes. This data should not be modified.

This function will always return the same pointer for a given Bytes.

Nothing may be returned if size is 0. This is not guaranteed, as the Bytes may represent an empty string with data non-Nothing and size as 0. Nothing will not be returned if size is non-zero.

Since: 2.32

getSize

bytesGetSize Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Bytes

bytes: a Bytes

-> m Word64

Returns: the size

Get the size of the byte data in the Bytes.

This function will always return the same value for a given Bytes.

Since: 2.32

hash

data BytesHashMethodInfo Source #

Instances

((~) * signature (m Word32), MonadIO m) => MethodInfo * BytesHashMethodInfo Bytes signature Source # 

bytesHash Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Bytes

bytes: a pointer to a Bytes key

-> m Word32

Returns: a hash value corresponding to the key.

Creates an integer hash code for the byte data in the Bytes.

This function can be passed to g_hash_table_new() as the keyHashFunc parameter, when using non-Nothing Bytes pointers as keys in a HashTable.

Since: 2.32

new

bytesNew Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Maybe ByteString

data: the data to be used for the bytes

-> m Bytes

Returns: a new Bytes

Creates a new Bytes from data.

data is copied. If size is 0, data may be Nothing.

Since: 2.32

newFromBytes

bytesNewFromBytes Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Bytes

bytes: a Bytes

-> Word64

offset: offset which subsection starts at

-> Word64

length: length of subsection

-> m Bytes

Returns: a new Bytes

Creates a Bytes which is a subsection of another Bytes. The offset + length may not be longer than the size of bytes.

A reference to bytes will be held by the newly created Bytes until the byte data is no longer needed.

Since: 2.32

newTake

bytesNewTake Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Maybe ByteString

data: the data to be used for the bytes

-> m Bytes

Returns: a new Bytes

Creates a new Bytes from data.

After this call, data belongs to the bytes and may no longer be modified by the caller. free will be called on data when the bytes is no longer in use. Because of this data must have been created by a call to malloc, malloc0 or realloc or by one of the many functions that wrap these calls (such as g_new(), strdup, etc).

For creating Bytes with memory from other allocators, see g_bytes_new_with_free_func().

data may be Nothing if size is 0.

Since: 2.32

ref

data BytesRefMethodInfo Source #

Instances

((~) * signature (m Bytes), MonadIO m) => MethodInfo * BytesRefMethodInfo Bytes signature Source # 

bytesRef Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Bytes

bytes: a Bytes

-> m Bytes

Returns: the Bytes

Increase the reference count on bytes.

Since: 2.32

unref

data BytesUnrefMethodInfo Source #

Instances

((~) * signature (m ()), MonadIO m) => MethodInfo * BytesUnrefMethodInfo Bytes signature Source # 

bytesUnref Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Bytes

bytes: a Bytes

-> m () 

Releases a reference on bytes. This may result in the bytes being freed.

Since: 2.32

unrefToArray

bytesUnrefToArray Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Bytes

bytes: a Bytes

-> m ByteString

Returns: a new mutable ByteArray containing the same byte data

Unreferences the bytes, and returns a new mutable ByteArray containing the same byte data.

As an optimization, the byte data is transferred to the array without copying if this was the last reference to bytes and bytes was created with bytesNew, bytesNewTake or byteArrayFreeToBytes. In all other cases the data is copied.

Since: 2.32

unrefToData

bytesUnrefToData Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Bytes

bytes: a Bytes

-> m ByteString

Returns: a pointer to the same byte data, which should be freed with free

Unreferences the bytes, and returns a pointer the same byte data contents.

As an optimization, the byte data is returned without copying if this was the last reference to bytes and bytes was created with bytesNew, bytesNewTake or byteArrayFreeToBytes. In all other cases the data is copied.

Since: 2.32