fix endian macros on linux
refactor to allow writing with parsers