tagstruct: Refactor writing/reading basic types
authorTanu Kaskinen <tanu.kaskinen@linux.intel.com>
Tue, 17 Feb 2015 19:40:13 +0000 (21:40 +0200)
committerDavid Henningsson <david.henningsson@canonical.com>
Mon, 23 Feb 2015 14:00:13 +0000 (15:00 +0100)
commit390b7db95d1a96f14b62d61f491cfafbcc50ba35
treef7fe428f49cbc308df956e7e6da655ce8d67b168
parentaa3a27d5cdad9dd43b9fe79a13fd09b50d4b7682
tagstruct: Refactor writing/reading basic types

While adding functions for writing and reading pa_bvolume structs, I
found myself wondering if I could make it simpler to write and read
the basic types that a pa_bvolume consists of, without having to worry
about network byte ordering, remembering to call extend() and getting
the length and read index adjustments just right. This is what I came
up with.

There is a functional change too: previously the
pa_tagstruct_get_foo() functions didn't modify the read index in case
of errors, but now, due to read_tag() modifying the read index at an
early stage, the read index gets modified also in case of errors. I
have checked the call sites, and I believe there's no code that would
rely on the "no read index modification on error" property of the old
functions. If reading anything from a tagstruct fails, the whole
tagstruct is considered invalid (typically resulting in a protocol
error and client connection teardown).
src/pulsecore/tagstruct.c