I need to read a binary format in Haskell. The format is fairly simple: four octets indicating the length of the data, followed by the data. The four octets represent an integer in network byte-order.
How can I convert a ByteString
of four bytes to an integer? I want a direct cast (in C, that would be *(int*)&data
), not a lexicographical conversion. Also, how would I go about endianness? The serialized integer is in network byte-order, but the machine may use a different byte-order.
I tried Googling but that only yold results about lexicographical conversion.