I must create a codec for a message that has the following specification The message length is indicated by a byte of which the least significant bit is an extension flag that, when set indicates that the following (optional) byte must be used as the most significant byte. (Hope it make sense) It can be depicted as follows:
+----------------------------------------------------------------------------------+ | LENGTH | | | +----------------------------------+-----+-+---------------------------------------+ | | | | | | Len1 (LSB) | Ext | | Len2 (MSB) - Optional | +----+----+----+----+----+----+----+-----+ +----+----+----+----+----+----+----+----+ | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | +----+----+----+----+----+----+----+--|--+ +----+----+----+----+----+----+----+----+ | | v Boolean: if true then Len2 is used else only Len1
The length of the data that will follow is determined by this field(s). I would like to use the codec along with predefined codecs and combinators. I guess it will involve using flatZip but I am not clear on how to incorporate flatZip into an HList combinator. Any pointers to examples or documentation will be much appreciated.