Blame doc/xkb_internals

Packit 071ada
Packit 071ada
XKB introduces several uncommon data structures:
Packit 071ada
 - switch allows conditional inclusion of fields
Packit 071ada
 - several complex objects intermix variable and fixed size fields
Packit 071ada
 - lists with a variable number of variable size objects
Packit 071ada
Packit 071ada
To handle these objects, a number of new functions is generated:
Packit 071ada
 - _serialize() turns a structured object into a byte stream, 
Packit 071ada
   (re)ordering or including fields according to the protocol
Packit 071ada
 - _unserialize() rewrites data from a buffer into a structured object
Packit 071ada
 - _unpack() expands a buffer representing a switch object into 
Packit 071ada
   a special structured type, all flags needed to resolve the switch
Packit 071ada
   expression have to given as parameters
Packit 071ada
 - _sizeof() calculates the size of a serialized object, often by calling
Packit 071ada
   _unserialize()/_unpack() internally
Packit 071ada
Packit 071ada
The new structured data type for switch is special as it contains fixed 
Packit 071ada
and variable size fields. Variable size fields can be accessed via pointers. 
Packit 071ada
Packit 071ada
If switch appears in a request, an additional set of request helpers is 
Packit 071ada
generated with the suffix _aux or _aux_(un)checked. While the 'common'
Packit 071ada
request functions require that switch has been serialized before, the _aux
Packit 071ada
variants take the structured data type. They are especially designed to 
Packit 071ada
replace certain functions in xcb-util/aux. 
Packit 071ada
Packit 071ada
Accessors for switch members need two parameters, where the first is usually
Packit 071ada
a pointer to the respective request or reply structure, while the second 
Packit 071ada
is a pointer to the unpacked switch data structure. 
Packit 071ada
Packit 071ada
Functions from the serialize family that take a double pointer can allocate 
Packit 071ada
memory on their own, which is useful if the size of a buffer has to be 
Packit 071ada
calculated depending on the data within. These functions call malloc() when 
Packit 071ada
the double pointer is given as the address of a pointer that has been 
Packit 071ada
initialized to 0. It is the responsibility of the user to free any allocated
Packit 071ada
memory. 
Packit 071ada
Packit 071ada
Intermixed variable and fixed size fields are an important special case in XKB. 
Packit 071ada
The current implementation resolves the issue by reordering the fields before
Packit 071ada
sending them on the wire as well as before returning a reply. That means that 
Packit 071ada
these objects look like 'common' XCB data types and they can be accessed as such 
Packit 071ada
(i.e. fixed size fields directly via the structured type and variable size fields
Packit 071ada
via accessors/iterators).  
Packit 071ada
Packit 071ada
In case a list with variable size elements needs to be accessed, it is necessary 
Packit 071ada
to use iterators. The iterator functions take care of determining the actual 
Packit 071ada
object size for each element automatically. 
Packit 071ada
Packit 071ada
A small and preliminary set of auxiliary functions is available in xkb_util.c 
Packit 071ada
in the check_xkb module.