Merge: Read/Write binary data
authorJean Privat <jean@pryen.org>
Wed, 20 May 2015 00:30:25 +0000 (20:30 -0400)
committerJean Privat <jean@pryen.org>
Wed, 20 May 2015 00:30:25 +0000 (20:30 -0400)
commitecc38fae3f0095a8f054289750c96bc900005e33
tree8ac6359b7c39ce6df8582f37de107943c08c5f91
parent42c96a218048ec556e098270db2829d552f15bee
parent69666c691507c1bc1f63546666b7dc086b270975
Merge: Read/Write binary data

The module `binary` adds services to `Writer` and `Reader` to read/write binary data.

The services offer different size for each kind of data. They can be used to save space on a stream or for compatibility with external programs. They use type names from C:
* `write_float` write a Nit `Float` on 32 bits, with loss of precision.
* `write_double` write a Nit `Float` on 64 bits.
* `write_int64` write a Nit `Int` on 64 bits, with usually no loss of data, but it may still happen per platform.
* `write_bool` and `write_bits` to write booleans as a byte.
* There's a TODO for other suggested methods.

The endianess of each stream is configurable.

I tried to avoid touching too much to the main stream code knowing that @R4PaSs is working on reading/writing bytes. The binary module will have to be updated when we have a `Byte` type. Also, all the others types of `Writer` must be modified to implement `write_byte`.

I'll use this to write a binary alternative to json_serialization.

Pull-Request: #1354
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>