UpstandingHackers / hammer

Parser combinators for binary formats, in C. Yes, in C. What? Don't look at me like that.
GNU General Public License v2.0
430 stars 40 forks source link

implement h_with_endianness combinator #103

Closed pesco closed 10 years ago

pesco commented 10 years ago

fixed a bug in h_read_bits along the way.

pesco commented 10 years ago

NB: i considered having the endianness to switch to be produced by a parser argument (akin to how h_length_value gets its length), but decided against it because i think the more flexible solution is to use h_choice and maybe h_and. e.g. (pseudocode):

be(p) = with_endianness(BYTE_BIG_ENDIAN, p)
le(p) = with_endianness(BYTE_LITTLE_ENDIAN, p)
stuff = ...  // actual parser
wrap = choice(seq(token("BE"), be(stuff)), seq(token("LE"), le(stuff)))