Soup.Buffer¶
Fields¶
Name |
Type |
Access |
Description |
---|---|---|---|
data |
r/w |
the data |
|
length |
r/w |
length of data |
Methods¶
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
Details¶
- class Soup.Buffer¶
A data buffer, generally used to represent a chunk of a
Soup.MessageBody
.data is a
str
because that’s generally convenient; in some situations you may need to cast it to #guchar or another type.- classmethod new(data)¶
- Parameters:
data (
bytes
) – data- Returns:
the new
Soup.Buffer
.- Return type:
Creates a new
Soup.Buffer
containing length bytes from data.This function is exactly equivalent to
Soup.Buffer.new
() withSoup.MemoryUse.TAKE
as first argument; it exists mainly for convenience and simplifying language bindings.New in version 2.32.
- classmethod new_with_owner(data, owner, owner_dnotify)¶
- Parameters:
data (
bytes
) – dataowner (
object
orNone
) – pointer to an object that owns dataowner_dnotify (
GLib.DestroyNotify
orNone
) – a function to free/unref owner when the buffer is freed
- Returns:
the new
Soup.Buffer
.- Return type:
Creates a new
Soup.Buffer
containing length bytes from data. When theSoup.Buffer
is freed, it will call owner_dnotify, passing owner to it. You must ensure that data will remain valid until owner_dnotify 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, (GLib.DestroyNotify
)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).
- copy()¶
- Returns:
the new (or newly-reffed) buffer
- Return type:
Makes a copy of self. In reality,
Soup.Buffer
is a refcounted type, and callingSoup.Buffer.copy
() will normally just increment the refcount on self and return it. However, if self was created withSoup.MemoryUse.TEMPORARY
memory, thenSoup.Buffer.copy
() 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 self. (In reality, as described in the documentation for
Soup.Buffer.copy
(), this is actually an “unref” operation, and may or may not actually free self.)
- get_as_bytes()¶
- Returns:
a new
GLib.Bytes
which has the same content as theSoup.Buffer
.- Return type:
Creates a
GLib.Bytes
pointing to the same memory as self. TheGLib.Bytes
will hold a reference on self to ensure that it is not freed while theGLib.Bytes
is still valid.New in version 2.40.
- get_data()¶
- Returns:
the pointer to the buffer data is stored here
- Return type:
data:
bytes
This function exists for use by language bindings, because it’s not currently possible to get the right effect by annotating the fields of
Soup.Buffer
.New in version 2.32.
- get_owner()¶
-
Gets the “owner” object for a buffer created with
Soup.Buffer.new_with_owner
().
- new_subbuffer(offset, length)¶
- Parameters:
- Returns:
the new
Soup.Buffer
.- Return type:
Creates a new
Soup.Buffer
containing length bytes “copied” from self starting at offset. (Normally this will not actually copy any data, but will instead simply reference the same data as self does.)