Rewrite reader to allow runtime protocol version choice

Signed-off-by: John Else <john.else@citrix.com>
Rewrite writer to allow runtime protocol version choice

Signed-off-by: John Else <john.else@citrix.com>
Deduplicate some code

Signed-off-by: John Else <john.else@citrix.com>