Initial commit of alternative erlang lib


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@666374 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/alterl/src/thrift_processor.erl b/lib/alterl/src/thrift_processor.erl
new file mode 100644
index 0000000..ea6ea2d
--- /dev/null
+++ b/lib/alterl/src/thrift_processor.erl
@@ -0,0 +1,64 @@
+%%%-------------------------------------------------------------------
+%%% File    : thrift_processor.erl
+%%% Author  :  <todd@lipcon.org>
+%%% Description : 
+%%%
+%%% Created : 28 Jan 2008 by  <todd@lipcon.org>
+%%%-------------------------------------------------------------------
+-module(thrift_processor).
+
+-export([start/4,init/4]).
+
+-include("thrift_constants.hrl").
+-include("thrift_protocol.hrl").
+
+-record(state, {handler, in_protocol, out_protocol, service}).
+
+start(IProt, OProt, Service, Handler) ->
+    spawn(thrift_processor, init, [IProt, OProt, Service, Handler]).
+
+init(IProt, OProt, Service, Handler) ->
+    io:format("Processor started~n"),
+    loop(#state{in_protocol = IProt,
+                out_protocol = OProt,
+                service = Service,
+                handler = Handler}).
+
+loop(State = #state{in_protocol = IProto,
+                    out_protocol = OProto}) ->
+    MessageBegin = thrift_protocol:read(IProto, message_begin),
+    io:format("Got message begin: ~p~n", [MessageBegin]),
+
+    [ok, ok, ok, ok] = [thrift_protocol:read(IProto, X)
+                    || X <- [struct_begin, field_stop, struct_end, message_end]],
+    io:format("Read everything okay!"),
+
+    Packets =
+        [
+         #protocol_message_begin{name = "getServiceStatus",
+                                 type = ?tMessageType_REPLY,
+                                 seqid = 0},
+         struct_begin,
+         #protocol_field_begin{name = "success",
+                               type = ?tType_MAP,
+                               id = 0},
+         #protocol_map_begin{ktype = ?tType_STRING,
+                             vtype = ?tType_STRING,
+                             size  = 2},
+         {string, "Hello"},
+         {string, "World"},
+         {string, "foo"},
+         {string, "bar"},
+         field_stop,
+         map_end,
+         field_end,
+         field_stop,
+         struct_end,
+         message_end
+         ],
+               
+    Results = [thrift_protocol:write(OProto, Packet) || Packet <- Packets],
+    receive
+        _ ->
+            loop(State)
+    end.