Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | None |
Language | Haskell2010 |
A data buffer, generally used to represent a chunk of a
MessageBody
.
data
is a char
because that's generally convenient; in some
situations you may need to cast it to guchar
or another type.
Synopsis
- newtype Buffer = Buffer (ManagedPtr Buffer)
- newZeroBuffer :: MonadIO m => m Buffer
- bufferCopy :: (HasCallStack, MonadIO m) => Buffer -> m Buffer
- bufferFree :: (HasCallStack, MonadIO m) => Buffer -> m ()
- bufferGetAsBytes :: (HasCallStack, MonadIO m) => Buffer -> m Bytes
- bufferGetData :: (HasCallStack, MonadIO m) => Buffer -> m ByteString
- bufferGetOwner :: (HasCallStack, MonadIO m) => Buffer -> m (Ptr ())
- bufferNew :: (HasCallStack, MonadIO m) => ByteString -> m Buffer
- bufferNewSubbuffer :: (HasCallStack, MonadIO m) => Buffer -> Word64 -> Word64 -> m Buffer
- bufferNewWithOwner :: (HasCallStack, MonadIO m) => ByteString -> Ptr () -> Maybe DestroyNotify -> m Buffer
- clearBufferData :: MonadIO m => Buffer -> m ()
- getBufferData :: MonadIO m => Buffer -> m (Ptr ())
- setBufferData :: MonadIO m => Buffer -> Ptr () -> m ()
- getBufferLength :: MonadIO m => Buffer -> m Word64
- setBufferLength :: MonadIO m => Buffer -> Word64 -> m ()
Exported types
Memory-managed wrapper type.
Instances
Eq Buffer Source # | |
GBoxed Buffer Source # | |
Defined in GI.Soup.Structs.Buffer | |
ManagedPtrNewtype Buffer Source # | |
Defined in GI.Soup.Structs.Buffer toManagedPtr :: Buffer -> ManagedPtr Buffer | |
TypedObject Buffer Source # | |
Defined in GI.Soup.Structs.Buffer glibType :: IO GType | |
IsGValue Buffer Source # | Convert |
Defined in GI.Soup.Structs.Buffer toGValue :: Buffer -> IO GValue fromGValue :: GValue -> IO Buffer | |
HasParentTypes Buffer Source # | |
Defined in GI.Soup.Structs.Buffer | |
tag ~ 'AttrSet => Constructible Buffer tag Source # | |
type ParentTypes Buffer Source # | |
Defined in GI.Soup.Structs.Buffer type ParentTypes Buffer = '[] :: [Type] |
Methods
Overloaded methods
copy
:: (HasCallStack, MonadIO m) | |
=> Buffer |
|
-> m Buffer | Returns: the new (or newly-reffed) buffer |
Makes a copy of buffer
. In reality, Buffer
is a refcounted
type, and calling bufferCopy
will normally just increment
the refcount on buffer
and return it. However, if buffer
was
created with SOUP_MEMORY_TEMPORARY
memory, then bufferCopy
will actually return a copy of it, so that the data in the copy
will remain valid after the temporary buffer is freed.
free
Frees buffer
. (In reality, as described in the documentation for
bufferCopy
, this is actually an "unref" operation, and may
or may not actually free buffer
.)
getAsBytes
getData
This function exists for use by language bindings, because it's not
currently possible to get the right effect by annotating the fields
of Buffer
.
Since: 2.32
getOwner
:: (HasCallStack, MonadIO m) | |
=> Buffer |
|
-> m (Ptr ()) | Returns: the owner pointer |
Gets the "owner" object for a buffer created with
bufferNewWithOwner
.
new
Creates a new Buffer
containing length
bytes from data
.
This function is exactly equivalent to soup_buffer_new()
with
MemoryUseTake
as first argument; it exists mainly for
convenience and simplifying language bindings.
Since: 2.32
newSubbuffer
:: (HasCallStack, MonadIO m) | |
=> Buffer |
|
-> Word64 |
|
-> Word64 |
|
-> m Buffer | Returns: the new |
Creates a new Buffer
containing length
bytes "copied" from
parent
starting at offset
. (Normally this will not actually copy
any data, but will instead simply reference the same data as
parent
does.)
newWithOwner
:: (HasCallStack, MonadIO m) | |
=> ByteString |
|
-> Ptr () |
|
-> Maybe DestroyNotify |
|
-> m Buffer | Returns: the new |
Creates a new Buffer
containing length
bytes from data
. When
the Buffer
is freed, it will call ownerDnotify
, passing
owner
to it. You must ensure that data
will remain valid until
ownerDnotify
is called.
For example, you could use this to create a buffer containing data returned from libxml without needing to do an extra copy:
<informalexample><programlisting> xmlDocDumpMemory (doc, &xmlbody, &len); return soup_buffer_new_with_owner (xmlbody, len, xmlbody, (GDestroyNotify)xmlFree); </programlisting></informalexample>
In this example, data
and owner
are the same, but in other cases
they would be different (eg, owner
would be a object, and data
would be a pointer to one of the object's fields).
Properties
data
the data
clearBufferData :: MonadIO m => Buffer -> m () Source #
Set the value of the “data
” field to Nothing
.
When overloading is enabled, this is equivalent to
clear
#data
getBufferData :: MonadIO m => Buffer -> m (Ptr ()) Source #
Get the value of the “data
” field.
When overloading is enabled, this is equivalent to
get
buffer #data
setBufferData :: MonadIO m => Buffer -> Ptr () -> m () Source #
Set the value of the “data
” field.
When overloading is enabled, this is equivalent to
set
buffer [ #data:=
value ]
length
length of data
getBufferLength :: MonadIO m => Buffer -> m Word64 Source #
Get the value of the “length
” field.
When overloading is enabled, this is equivalent to
get
buffer #length
setBufferLength :: MonadIO m => Buffer -> Word64 -> m () Source #
Set the value of the “length
” field.
When overloading is enabled, this is equivalent to
set
buffer [ #length:=
value ]