Rework serialization

Move serialization to the protocol, we now just send blocks of bytes
over the connection and let the protocol deserialize them.
This commit is contained in:
Wim Taymans 2017-03-06 15:48:04 +01:00
parent 842d73ca4b
commit 41399b0b25
26 changed files with 1617 additions and 2501 deletions

View file

@ -231,8 +231,8 @@ struct _SpaNode {
* #SPA_RESULT_INVALID_COMMAND @command is an invalid command
* #SPA_RESULT_ASYNC @command is executed asynchronously
*/
SpaResult (*send_command) (SpaNode *node,
SpaNodeCommand *command);
SpaResult (*send_command) (SpaNode *node,
SpaNodeCommand *command);
/**
* SpaNode::set_event_callback:
* @node: a #SpaNode

View file

@ -211,7 +211,7 @@ spa_pod_builder_double (SpaPODBuilder *builder, double val)
}
static inline off_t
spa_pod_builder_string (SpaPODBuilder *builder, const char *str, uint32_t len)
spa_pod_builder_string_len (SpaPODBuilder *builder, const char *str, uint32_t len)
{
const SpaPODString p = { { len + 1, SPA_POD_TYPE_STRING } };
off_t out = spa_pod_builder_raw (builder, &p, sizeof (p) , false);
@ -220,6 +220,23 @@ spa_pod_builder_string (SpaPODBuilder *builder, const char *str, uint32_t len)
return out;
}
static inline off_t
spa_pod_builder_string (SpaPODBuilder *builder, const char *str)
{
uint32_t len = str ? strlen (str) : 0;
return spa_pod_builder_string_len (builder, str ? str : "", len);
}
static inline off_t
spa_pod_builder_bytes (SpaPODBuilder *builder, const void *bytes, uint32_t len)
{
const SpaPODBytes p = { { len, SPA_POD_TYPE_BYTES } };
off_t out = spa_pod_builder_raw (builder, &p, sizeof (p) , false);
if (spa_pod_builder_raw (builder, bytes, len, true) == -1)
out = -1;
return out;
}
static inline off_t
spa_pod_builder_rectangle (SpaPODBuilder *builder, uint32_t width, uint32_t height)
{
@ -334,7 +351,7 @@ spa_pod_builder_propv (SpaPODBuilder *builder,
{
const char *str = va_arg (args, char *);
uint32_t len = va_arg (args, uint32_t);
spa_pod_builder_string (builder, str, len);
spa_pod_builder_string_len (builder, str, len);
break;
}
case SPA_POD_TYPE_RECTANGLE:

View file

@ -70,6 +70,16 @@ 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;
@ -78,6 +88,16 @@ 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;
@ -93,6 +113,21 @@ 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 */
} SpaPODBytes;
typedef struct {
SpaPOD pod;
SpaRectangle value;
@ -123,6 +158,16 @@ 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
@ -161,6 +206,28 @@ 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)); \
@ -204,6 +271,7 @@ spa_pod_object_find_prop (const SpaPODObject *obj, uint32_t key)
return spa_pod_contents_find_prop (&obj->pod, sizeof (SpaPODObject), key);
}
#ifdef __cplusplus
} /* extern "C" */
#endif