| constructor | |
|---|---|
| constructor data/ByteArray | Constructs a new reader that uses the given data as source. |
import io
main:
reader := io.Reader #[0x12, 0x34, 0x56, 0x78]
number := reader.big-endian.read-int32
// The most significant byte 0x12 was at index 0.
print "0x$(%x number)" // => 0x12345678
import io
main:
reader := io.Reader #[0x78, 0x56, 0x34, 0x12]
number := reader.little-endian.read-int32
// The least significant byte 0x78 was at index 0.
print "0x$(%x number)" // => 0x12345678
class Pin:
number/int
constructor .number:
operator == other:
if other is not Pin: return false
return number == other.number
hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).
class MyReader implements Reader:
read -> ByteArray?: return "hellø".to-byte-array
main:
reader := BufferedReader MyReader
print
reader.peek-string 6 // >> Hellø
print
reader.peek-string 5 // >> Error!
read-exactly-or-drain reader/BufferedReader n/int -> ByteArray?:
if can-ensure n: return reader.read-bytes n
reader.buffer-all
if reader.buffered == 0: return null
return reader.read-bytes reader.buffered
class MyReader implements Reader:
read -> ByteArray?: return "hellø".to-byte-array
main:
reader := BufferedReader MyReader
print
reader.read-string 6 // >> Hellø
print
reader.read-string 5 // >> Error!