Incremental commit: rationalise the marshalling and unmarshalling

The unit tests currently don't build. Quite a lot of fixups still
required.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>