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, |
| 7 | read/2 |
| 8 | ]). |
| 9 | |
| 10 | behaviour_info(callbacks) -> |
| 11 | [{write/2, |
| 12 | read/2}]; |
| 13 | behaviour_info(_Else) -> undefined. |
| 14 | |
| 15 | |
| 16 | -record(transport, { module, data }). |
| 17 | |
| 18 | |
| 19 | new(Module, Data) when is_atom(Module) -> |
| 20 | {ok, #transport{module = Module, |
| 21 | data = Data}}. |
| 22 | |
| 23 | write(Transport, Data) when is_binary(Data) -> |
| 24 | Module = Transport#transport.module, |
| 25 | Module:write(Transport#transport.data, Data). |
| 26 | |
| 27 | read(Transport, Len) when is_integer(Len) -> |
| 28 | Module = Transport#transport.module, |
| 29 | Module:read(Transport#transport.data, Len). |