blob: ea6ea2d3ad6dbae98f71267dc5034e173088cc1d [file] [log] [blame]
David Reissac549552008-06-10 22:56:59 +00001%%%-------------------------------------------------------------------
2%%% File : thrift_processor.erl
3%%% Author : <todd@lipcon.org>
4%%% Description :
5%%%
6%%% Created : 28 Jan 2008 by <todd@lipcon.org>
7%%%-------------------------------------------------------------------
8-module(thrift_processor).
9
10-export([start/4,init/4]).
11
12-include("thrift_constants.hrl").
13-include("thrift_protocol.hrl").
14
15-record(state, {handler, in_protocol, out_protocol, service}).
16
17start(IProt, OProt, Service, Handler) ->
18 spawn(thrift_processor, init, [IProt, OProt, Service, Handler]).
19
20init(IProt, OProt, Service, Handler) ->
21 io:format("Processor started~n"),
22 loop(#state{in_protocol = IProt,
23 out_protocol = OProt,
24 service = Service,
25 handler = Handler}).
26
27loop(State = #state{in_protocol = IProto,
28 out_protocol = OProto}) ->
29 MessageBegin = thrift_protocol:read(IProto, message_begin),
30 io:format("Got message begin: ~p~n", [MessageBegin]),
31
32 [ok, ok, ok, ok] = [thrift_protocol:read(IProto, X)
33 || X <- [struct_begin, field_stop, struct_end, message_end]],
34 io:format("Read everything okay!"),
35
36 Packets =
37 [
38 #protocol_message_begin{name = "getServiceStatus",
39 type = ?tMessageType_REPLY,
40 seqid = 0},
41 struct_begin,
42 #protocol_field_begin{name = "success",
43 type = ?tType_MAP,
44 id = 0},
45 #protocol_map_begin{ktype = ?tType_STRING,
46 vtype = ?tType_STRING,
47 size = 2},
48 {string, "Hello"},
49 {string, "World"},
50 {string, "foo"},
51 {string, "bar"},
52 field_stop,
53 map_end,
54 field_end,
55 field_stop,
56 struct_end,
57 message_end
58 ],
59
60 Results = [thrift_protocol:write(OProto, Packet) || Packet <- Packets],
61 receive
62 _ ->
63 loop(State)
64 end.