blob: f901f74db36f1e6b5f8cae5072ee26389c348c61 [file] [log] [blame]
David Reissac549552008-06-10 22:56:59 +00001-module(thrift_transport).
2
David Reiss3b9c3422008-06-11 00:59:19 +00003-export([behaviour_info/1]).
David Reissac549552008-06-10 22:56:59 +00004
David Reiss3b9c3422008-06-11 00:59:19 +00005-export([new/2,
David Reissac549552008-06-10 22:56:59 +00006 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) ->
David Reiss3b9c3422008-06-11 00:59:19 +000012 [{read, 2},
13 {write, 2},
14 {flush, 1}
15 ].
David Reissac549552008-06-10 22:56:59 +000016
17-record(transport, { module, data }).
18
David Reissac549552008-06-10 22:56:59 +000019new(Module, Data) when is_atom(Module) ->
20 {ok, #transport{module = Module,
21 data = Data}}.
22
23write(Transport, Data) when is_binary(Data) ->
24 Module = Transport#transport.module,
25 Module:write(Transport#transport.data, Data).
26
27read(Transport, Len) when is_integer(Len) ->
28 Module = Transport#transport.module,
29 Module:read(Transport#transport.data, Len).
David Reiss90b40832008-06-10 22:58:52 +000030
31flush(#transport{module = Module, data = Data}) ->
32 Module:flush(Data).