mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-16 07:00:00 -05:00
pod-builder: make more generic builder
Make a vararg based builder that produces much smaller code. Catch demarshal errors. Simplify array handling
This commit is contained in:
parent
f92b68c3c3
commit
78a3cd61b8
9 changed files with 862 additions and 637 deletions
|
|
@ -48,7 +48,8 @@ typedef enum {
|
|||
SPA_POD_TYPE_STRUCT,
|
||||
SPA_POD_TYPE_OBJECT,
|
||||
SPA_POD_TYPE_PROP,
|
||||
SPA_POD_TYPE_BYTES
|
||||
SPA_POD_TYPE_BYTES,
|
||||
SPA_POD_TYPE_POD
|
||||
} SpaPODType;
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -71,16 +72,6 @@ typedef struct {
|
|||
int32_t value;
|
||||
} SpaPODInt;
|
||||
|
||||
static inline bool
|
||||
spa_pod_get_int (SpaPOD **pod, int32_t *val)
|
||||
{
|
||||
if (*pod == NULL || (*pod)->type != SPA_POD_TYPE_INT)
|
||||
return false;
|
||||
*val = ((SpaPODInt *)(*pod))->value;
|
||||
*pod = SPA_MEMBER (*pod, SPA_ROUND_UP_N (SPA_POD_SIZE (*pod), 8), SpaPOD);
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef SpaPODInt SpaPODBool;
|
||||
typedef SpaPODInt SpaPODURI;
|
||||
|
||||
|
|
@ -89,16 +80,6 @@ typedef struct {
|
|||
int64_t value;
|
||||
} SpaPODLong;
|
||||
|
||||
static inline bool
|
||||
spa_pod_get_long (SpaPOD **pod, int64_t *val)
|
||||
{
|
||||
if (*pod == NULL || (*pod)->type != SPA_POD_TYPE_LONG)
|
||||
return false;
|
||||
*val = ((SpaPODLong *)*pod)->value;
|
||||
*pod = SPA_MEMBER (*pod, SPA_ROUND_UP_N (SPA_POD_SIZE (*pod), 8), SpaPOD);
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
SpaPOD pod;
|
||||
float value;
|
||||
|
|
@ -114,16 +95,6 @@ typedef struct {
|
|||
/* value here */
|
||||
} SpaPODString;
|
||||
|
||||
static inline bool
|
||||
spa_pod_get_string (SpaPOD **pod, const char **val)
|
||||
{
|
||||
if (*pod == NULL || (*pod)->type != SPA_POD_TYPE_STRING)
|
||||
return false;
|
||||
*val = SPA_POD_CONTENTS (SpaPODString, *pod);
|
||||
*pod = SPA_MEMBER (*pod, SPA_ROUND_UP_N (SPA_POD_SIZE (*pod), 8), SpaPOD);
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
SpaPOD pod;
|
||||
/* value here */
|
||||
|
|
@ -159,16 +130,6 @@ typedef struct {
|
|||
/* one or more SpaPOD follow */
|
||||
} SpaPODStruct;
|
||||
|
||||
static inline bool
|
||||
spa_pod_get_struct (SpaPOD **pod, SpaPOD **val)
|
||||
{
|
||||
if (*pod == NULL || (*pod)->type != SPA_POD_TYPE_STRUCT)
|
||||
return false;
|
||||
*val = *pod;
|
||||
*pod = SPA_MEMBER (*pod, SPA_ROUND_UP_N (SPA_POD_SIZE (*pod), 8), SpaPOD);
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint32_t key;
|
||||
#define SPA_POD_PROP_RANGE_NONE 0
|
||||
|
|
@ -207,28 +168,6 @@ typedef struct {
|
|||
SpaPODObjectBody body;
|
||||
} SpaPODObject;
|
||||
|
||||
static inline bool
|
||||
spa_pod_get_object (SpaPOD **pod, const SpaPOD **val)
|
||||
{
|
||||
if (*pod == NULL || (*pod)->type != SPA_POD_TYPE_OBJECT)
|
||||
return false;
|
||||
*val = *pod;
|
||||
*pod = SPA_MEMBER (*pod, SPA_ROUND_UP_N (SPA_POD_SIZE (*pod), 8), SpaPOD);
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
spa_pod_get_bytes (SpaPOD **pod, const void **val, uint32_t *size)
|
||||
{
|
||||
if (*pod == NULL || (*pod)->type != SPA_POD_TYPE_BYTES)
|
||||
return false;
|
||||
*val = SPA_POD_CONTENTS (SpaPODBytes, *pod);
|
||||
*size = SPA_POD_SIZE (*pod);
|
||||
*pod = SPA_MEMBER (*pod, SPA_ROUND_UP_N (SPA_POD_SIZE (*pod), 8), SpaPOD);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#define SPA_POD_ARRAY_BODY_FOREACH(body, _size, iter) \
|
||||
for ((iter) = SPA_MEMBER ((body), sizeof(SpaPODArrayBody), __typeof__(*(iter))); \
|
||||
(iter) < SPA_MEMBER ((body), (_size), __typeof__(*(iter))); \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue