Hide keyboard shortcuts

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: 

2 

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. 

7 

8 """ 

9 

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. 

14 

15 """ 

16 

17 chunk = self.read(size) 

18 data.copy_into(chunk, 0, chunk.length(), start) 

19 

20 return chunk.length() 

21 

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. 

27 

28 """ 

29 

30 return self.read_into(data, start, 1) 

31 

32trait Writer: 

33 

34 func write(self, data: bytes) -> i64: 

35 """Write given data. Returns number of bytes written, or zero if 

36 the connection was closed. 

37 

38 """ 

39 

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. 

43 

44 """ 

45 

46 value = bytes(u64(size)) 

47 value.copy_into(data, start, size, 0) 

48 

49 return self.write(value)