Finish port to cstruct

NB: the unit tests currently fail.

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