Coverage for src/lib.mys : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1trait Reader:
3 func read(self, size: i64) -> bytes:
4 """Read given number of bytes. Always returns size number of bytes,
5 unless the connection was closed, in which case the remaining
6 data is returned.
8 """
10 func read_into(self, data: bytes, start: i64, size: i64) -> i64:
11 """Read given number of bytes into given buffer. Always returns size
12 number of bytes, unless the connection was closed, in which
13 case the number of read bytes is returned.
15 """
17 chunk = self.read(size)
18 data.copy_into(chunk, 0, chunk.length(), start)
20 return chunk.length()
22 func try_read_into(self, data: bytes, start: i64, size: i64) -> i64:
23 """Try to read given number of bytes into given buffer. Returns number
24 of read bytes, which is at least one and at most given size
25 bytes, unless the connection was closed, in which case the
26 number of read bytes is returned.
28 """
30 return self.read_into(data, start, 1)
32trait Writer:
34 func write(self, data: bytes) -> i64:
35 """Write given data. Returns number of bytes written, or zero if
36 the connection was closed.
38 """
40 func write_from(self, data: bytes, start: i64, size: i64) -> i64:
41 """Write from given buffer. Returns number of bytes written, or zero
42 if the connection was closed.
44 """
46 value = bytes(u64(size))
47 value.copy_into(data, start, size, 0)
49 return self.write(value)