| Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte |
|---|---|
| License | LGPL-2.1 |
| Maintainer | Iñaki García Etxebarria (inaki@blueleaf.cc) |
| Safe Haskell | None |
| Language | Haskell2010 |
GI.Soup.Structs.Buffer
Contents
Description
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
- noBuffer :: Maybe 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.
Constructors
| Buffer (ManagedPtr Buffer) |
Instances
| BoxedObject Buffer Source # | |
| tag ~ AttrSet => Constructible Buffer tag Source # | |
Defined in GI.Soup.Structs.Buffer | |
Methods
copy
Arguments
| :: (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
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Buffer |
|
| -> m () |
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
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Buffer |
|
| -> m ByteString |
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
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Buffer |
|
| -> m (Ptr ()) | Returns: the owner pointer |
Gets the "owner" object for a buffer created with
bufferNewWithOwner.
new
Arguments
| :: (HasCallStack, MonadIO m) | |
| => ByteString |
|
| -> m Buffer | Returns: the 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
Arguments
| :: (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
Arguments
| :: (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
setbuffer [ #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
setbuffer [ #length:=value ]