David Reiss | ac54955 | 2008-06-10 22:56:59 +0000 | [diff] [blame] | 1 | -module(thrift_transport). |
| 2 | |
| 3 | -export([behaviour_info/1, |
| 4 | |
| 5 | new/2, |
| 6 | write/2, |
David Reiss | 90b4083 | 2008-06-10 22:58:52 +0000 | [diff] [blame] | 7 | read/2, |
| 8 | flush/1 |
David Reiss | ac54955 | 2008-06-10 22:56:59 +0000 | [diff] [blame] | 9 | ]). |
| 10 | |
| 11 | behaviour_info(callbacks) -> |
| 12 | [{write/2, |
David Reiss | 90b4083 | 2008-06-10 22:58:52 +0000 | [diff] [blame] | 13 | read/2, |
| 14 | flush/1}]; |
David Reiss | ac54955 | 2008-06-10 22:56:59 +0000 | [diff] [blame] | 15 | behaviour_info(_Else) -> undefined. |
| 16 | |
| 17 | |
| 18 | -record(transport, { module, data }). |
| 19 | |
| 20 | |
| 21 | new(Module, Data) when is_atom(Module) -> |
| 22 | {ok, #transport{module = Module, |
| 23 | data = Data}}. |
| 24 | |
| 25 | write(Transport, Data) when is_binary(Data) -> |
| 26 | Module = Transport#transport.module, |
| 27 | Module:write(Transport#transport.data, Data). |
| 28 | |
| 29 | read(Transport, Len) when is_integer(Len) -> |
| 30 | Module = Transport#transport.module, |
| 31 | Module:read(Transport#transport.data, Len). |
David Reiss | 90b4083 | 2008-06-10 22:58:52 +0000 | [diff] [blame] | 32 | |
| 33 | flush(#transport{module = Module, data = Data}) -> |
| 34 | Module:flush(Data). |