blob: c47d90f81dd7326b6815caf772639349f4684e51 [file] [log] [blame]
David Reissac549552008-06-10 22:56:59 +00001-module(thrift_transport).
2
3-export([behaviour_info/1,
4
5 new/2,
6 write/2,
David Reiss90b40832008-06-10 22:58:52 +00007 read/2,
8 flush/1
David Reissac549552008-06-10 22:56:59 +00009 ]).
10
11behaviour_info(callbacks) ->
12 [{write/2,
David Reiss90b40832008-06-10 22:58:52 +000013 read/2,
14 flush/1}];
David Reissac549552008-06-10 22:56:59 +000015behaviour_info(_Else) -> undefined.
16
17
18-record(transport, { module, data }).
19
20
21new(Module, Data) when is_atom(Module) ->
22 {ok, #transport{module = Module,
23 data = Data}}.
24
25write(Transport, Data) when is_binary(Data) ->
26 Module = Transport#transport.module,
27 Module:write(Transport#transport.data, Data).
28
29read(Transport, Len) when is_integer(Len) ->
30 Module = Transport#transport.module,
31 Module:read(Transport#transport.data, Len).
David Reiss90b40832008-06-10 22:58:52 +000032
33flush(#transport{module = Module, data = Data}) ->
34 Module:flush(Data).