First part of support for optional types

Added optional val, and encode and decode.

The decode is a bit nasty since for anything that isn't a string we want to decode "" as None. However, for string we decode it as Some("").
as per comment about `Option` above