Package: glib
CStruct glib:variant
Details The g:variant structure is a variant datatype.
It stores a value along with information about the type of that value. The
range of possible values is determined by the type. The type system used by g:variant instances is the g:variant-type type. g:variant instances always have a type and a value, which are given at construction time. The variant type and value of a g:variant instance can never change other than by the g:variant instance itself being destroyed. A g:variant instance cannot contain a pointer. A g:variant instance is reference counted using the g:variant-ref and g:variant-unref functions. The g:variant instance also has floating reference counts, see the g:variant-ref-sink function. The g:variant structure is completely threadsafe. A g:variant instance can be concurrently accessed in any way from any number of threads without problems. The g:variant structure is heavily optimised for dealing with data in serialised form. It works particularly well with data located in memory mapped files. It can perform nearly all deserialisation operations in a small constant time, usually touching only a single memory page. Serialised g:variant data can also be sent over the network. The g:variant structure is largely compatible with D-Bus. Almost all types of g:variant instances can be sent over D-Bus. See the g:variant-type documentation for exceptions. However, g:variant structures serialisation format is not the same as the serialisation format of a D-Bus message body: use GDBusMessage, in the GIO library, for those. For space-efficiency, the g:variant serialisation format does not automatically include the variant's length, type or endianness, which must either be implied from context (such as knowledge that a particular file format always contains a little-endian "v" which occupies the whole length of the file) or supplied out-of-band (for instance, a length, type and/or endianness indicator could be placed at the beginning of a file, network message or network stream). A g:variant instance size is limited mainly by any lower level operating system constraints, such as the number of bits in :size. For example, it is reasonable to have a 2 GB file mapped into memory with GMappedFile, and call the g_variant_new_from_data() function on it. For convenience to C programmers, the g:variant values features powerful varargs-based value construction and destruction. This feature is designed to be embedded in other libraries. There is a Python-inspired text language for describing g:variant parameters. The g:variant structure includes a printer for this language and a parser with type inferencing. | See also |
2025-2-3