# var w = new FileWriter.open("/tmp/data.bin")
# w.write "hello"
# w.write_int64 123456789
-# w.write_byte 3
+# w.write_byte 3u8
# w.write_float 1.25
# w.write_double 1.234567
# w.write_bits(true, false, true)
# var r = new FileReader.open("/tmp/data.bin")
# assert r.read(5) == "hello"
# assert r.read_int64 == 123456789
-# assert r.read_byte == 3
+# assert r.read_byte == 3u8
# assert r.read_float == 1.25
# assert r.read_double == 1.234567
#
super BinaryStream
# Write a boolean `value` on a byte, using 0 for `false` and 1 for `true`
- fun write_bool(value: Bool) do write_byte if value then 1 else 0
+ fun write_bool(value: Bool) do write_byte if value then 1u8 else 0u8
# Write up to 8 `Bool` in a byte
#
fun write_string(text: Text)
do
write text
- write_byte 0x00
+ write_byte 0x00u8
end
# Write the length as a 64 bits integer, then the content of `text`
loop
var byte = read_byte
if byte == null or byte == 0x00 then return buf.to_s
- buf.chars.add byte.ascii
+ buf.bytes.add byte
end
end
`}
# Write the byte `value`
- fun write_byte(value: Int): Int `{
+ fun write_byte(value: Byte): Int `{
unsigned char byt = (unsigned char)value;
return bufferevent_write(self, &byt, 1);
`}
`}
# Write `value` as a single byte
- fun write_byte(value: Int): Int `{
+ fun write_byte(value: Byte): Int `{
unsigned char byt = (unsigned char)value;
return write(*self, &byt, 1);
`}
return fwrite(buf, 1, len, self);
`}
- fun write_byte(value: Int): Int `{
+ fun write_byte(value: Byte): Int `{
unsigned char b = (unsigned char)value;
return fwrite(&b, 1, 1, self);
`}
fun read_char: nullable Char is abstract
# Reads a byte. Returns `null` on EOF or timeout
- fun read_byte: nullable Int is abstract
+ fun read_byte: nullable Byte is abstract
# Reads a String of at most `i` length
fun read(i: Int): String do return read_bytes(i).to_s
fun write(s: Text) is abstract
# Write a single byte
- fun write_byte(value: Int) is abstract
+ fun write_byte(value: Byte) is abstract
# Can the stream be used to write
fun is_writable: Bool is abstract