Merge: doc: fixed some typos and other misc. corrections
[nit.git] / lib / core / protocol.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or is a part of
9 # another product.
10
11 import stream
12
13 # Stream class used as a Decorator over a stream
14 class Protocol
15 super Stream
16
17 type STREAM: Stream
18
19 var origin: STREAM
20
21 redef fun close do origin.close
22 end
23
24 # Reader decorator over a read-capable stream
25 class ReaderProtocol
26 super Reader
27 super Protocol
28
29 redef type STREAM: Reader
30
31 redef fun raw_read_byte do
32 return origin.read_byte
33 end
34
35 redef fun raw_read_bytes(ns, len) do
36 return origin.read_bytes_to_cstring(ns, len)
37 end
38 end
39
40 # Writer decorator over a write-capable stream
41 class WriterProtocol
42 super Writer
43 super Protocol
44
45 redef type STREAM: Writer
46
47 redef fun write_byte(b) do
48 origin.write_byte(b)
49 end
50
51 redef fun write_bytes_from_cstring(ns, len) do
52 origin.write_bytes_from_cstring(ns, len)
53 end
54 end
55
56 # Reader/Writer decorator over a duplex-capable stream
57 class DuplexProtocol
58 super Duplex
59 super WriterProtocol
60 super ReaderProtocol
61
62 redef type STREAM: Duplex
63 end