pod: add support for vararg building and parsing of pod+body

This commit is contained in:
Wim Taymans 2025-07-30 15:14:49 +02:00
parent f7ae61cb1e
commit 77494086c1
3 changed files with 36 additions and 0 deletions

View file

@ -595,6 +595,17 @@ do { \
spa_pod_builder_primitive(builder, pod); \
break; \
} \
case 'Q': \
case 'N': \
case 'U': \
case 'W': \
{ \
struct spa_pod *pod = va_arg(args, struct spa_pod *); \
const void *body = va_arg(args, const void *); \
spa_pod_builder_primitive_body(builder, pod, \
body, pod->size, NULL, 0); \
break; \
} \
} \
} while(false)

View file

@ -540,6 +540,7 @@ SPA_API_POD_PARSER bool spa_pod_parser_body_can_collect(const struct spa_pod *po
switch (type) {
case 'P':
case 'Q':
return true;
case 'b':
return spa_pod_is_bool(pod);
@ -572,10 +573,13 @@ SPA_API_POD_PARSER bool spa_pod_parser_body_can_collect(const struct spa_pod *po
case 'h':
return spa_pod_is_fd(pod);
case 'T':
case 'U':
return spa_pod_is_struct(pod) || spa_pod_is_none(pod);
case 'N':
case 'O':
return spa_pod_is_object(pod) || spa_pod_is_none(pod);
case 'V':
case 'W':
default:
return false;
}
@ -673,6 +677,17 @@ do { \
NULL : SPA_PTROFF((body), -sizeof(struct spa_pod), const struct spa_pod); \
break; \
} \
case 'Q': \
case 'U': \
case 'N': \
case 'W': \
{ \
struct spa_pod *p = va_arg(args, struct spa_pod*); \
const void **v = va_arg(args, const void **); \
*p = *pod; \
*v = body; \
break; \
} \
default: \
break; \
} \
@ -807,6 +822,10 @@ SPA_API_POD_PARSER int spa_pod_parser_get(struct spa_pod_parser *parser, ...)
#define SPA_POD_OPT_PodObject(val) "?" SPA_POD_PodObject(val)
#define SPA_POD_OPT_PodStruct(val) "?" SPA_POD_PodStruct(val)
#define SPA_POD_OPT_PodChoice(val) "?" SPA_POD_PodChoice(val)
#define SPA_POD_OPT_PodBody(val,body) "?" SPA_POD_PodBody(val,body)
#define SPA_POD_OPT_PodBodyObject(val,body) "?" SPA_POD_PodBodyObject(val,body)
#define SPA_POD_OPT_PodBodyStruct(val,body) "?" SPA_POD_PodBodyStruct(val,body)
#define SPA_POD_OPT_PodBodyChoice(val,body) "?" SPA_POD_PodBodyChoice(val,body)
#define spa_pod_parser_get_object(p,type,id,...) \
({ \

View file

@ -82,6 +82,12 @@ extern "C" {
#define SPA_POD_PodStruct(val) "T", val
#define SPA_POD_PodChoice(val) "V", val
#define SPA_POD_PodBody(val,body) "Q", val, body
#define SPA_POD_PodBodyObject(val,body) "N", val, body
#define SPA_POD_PodBodyStruct(val,body) "U", val, body
#define SPA_POD_PodBodyChoice(val,body) "W", val, body
/**
* \}
*/