lib/io: Changed the semantics of read/write byte to use Byte instead of Int
authorLucas Bajolet <r4pass@hotmail.com>
Wed, 8 Jul 2015 20:38:25 +0000 (16:38 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Wed, 8 Jul 2015 20:49:37 +0000 (16:49 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/binary/binary.nit
lib/libevent.nit
lib/socket/socket_c.nit
lib/standard/file.nit
lib/standard/stream.nit

index f4be1eb..6268832 100644 (file)
@@ -18,7 +18,7 @@
 # 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)
@@ -28,7 +28,7 @@
 # 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
 #
@@ -70,7 +70,7 @@ redef abstract class Writer
        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
        #
@@ -97,7 +97,7 @@ redef abstract class Writer
        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`
@@ -178,7 +178,7 @@ redef abstract class Reader
                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
 
index 7ba6763..1ce2762 100644 (file)
@@ -186,7 +186,7 @@ extern class NativeBufferEvent `{ struct bufferevent * `}
        `}
 
        # 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);
        `}
index 03d9ddc..7930276 100644 (file)
@@ -131,7 +131,7 @@ extern class NativeSocket `{ int* `}
        `}
 
        # 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);
        `}
index 97a3a3b..cc6711c 100644 (file)
@@ -1164,7 +1164,7 @@ private extern class NativeFile `{ FILE* `}
                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);
        `}
index ecda97e..0bfd4b0 100644 (file)
@@ -47,7 +47,7 @@ abstract class Reader
        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
@@ -360,7 +360,7 @@ abstract class Writer
        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