You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2010/08/31 00:05:19 UTC

svn commit: r990972 - in /incubator/thrift/trunk/lib/erl: include/thrift_protocol_impl.hrl src/thrift_binary_protocol.erl src/thrift_client.erl src/thrift_protocol.erl

Author: dreiss
Date: Mon Aug 30 22:05:18 2010
New Revision: 990972

URL: http://svn.apache.org/viewvc?rev=990972&view=rev
Log:
erlang: Add some initial specs to thrift_client and thrift_protocol

Also add a special header for use in thrift_protocol implementations
that gives specs for the callbacks.

Added:
    incubator/thrift/trunk/lib/erl/include/thrift_protocol_impl.hrl
Modified:
    incubator/thrift/trunk/lib/erl/src/thrift_binary_protocol.erl
    incubator/thrift/trunk/lib/erl/src/thrift_client.erl
    incubator/thrift/trunk/lib/erl/src/thrift_protocol.erl

Added: incubator/thrift/trunk/lib/erl/include/thrift_protocol_impl.hrl
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/erl/include/thrift_protocol_impl.hrl?rev=990972&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/erl/include/thrift_protocol_impl.hrl (added)
+++ incubator/thrift/trunk/lib/erl/include/thrift_protocol_impl.hrl Mon Aug 30 22:05:18 2010
@@ -0,0 +1,31 @@
+%%
+%% Licensed to the Apache Software Foundation (ASF) under one
+%% or more contributor license agreements. See the NOTICE file
+%% distributed with this work for additional information
+%% regarding copyright ownership. The ASF licenses this file
+%% to you under the Apache License, Version 2.0 (the
+%% "License"); you may not use this file except in compliance
+%% with the License. You may obtain a copy of the License at
+%%
+%%   http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing,
+%% software distributed under the License is distributed on an
+%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+%% KIND, either express or implied. See the License for the
+%% specific language governing permissions and limitations
+%% under the License.
+%%
+
+%% Signature specifications for protocol implementations.
+
+-ifndef(THRIFT_PROTOCOL_IMPL_INCLUDED).
+-define(THRIFT_PROTOCOL_IMPL_INCLUDED, true).
+
+-spec flush_transport(state()) -> ok.
+-spec close_transport(state()) -> ok.
+-spec write(state(), term()) -> ok | {error, _Reason}.
+-spec read(state(), term()) -> term().
+
+
+-endif.

Modified: incubator/thrift/trunk/lib/erl/src/thrift_binary_protocol.erl
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/erl/src/thrift_binary_protocol.erl?rev=990972&r1=990971&r2=990972&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/erl/src/thrift_binary_protocol.erl (original)
+++ incubator/thrift/trunk/lib/erl/src/thrift_binary_protocol.erl Mon Aug 30 22:05:18 2010
@@ -37,6 +37,8 @@
                           strict_read=true,
                           strict_write=true
                          }).
+-type state() :: #binary_protocol{}.
+-include("thrift_protocol_impl.hrl").
 
 -define(VERSION_MASK, 16#FFFF0000).
 -define(VERSION_1, 16#80010000).

Modified: incubator/thrift/trunk/lib/erl/src/thrift_client.erl
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/erl/src/thrift_client.erl?rev=990972&r1=990971&r2=990972&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/erl/src/thrift_client.erl (original)
+++ incubator/thrift/trunk/lib/erl/src/thrift_client.erl Mon Aug 30 22:05:18 2010
@@ -140,6 +140,7 @@ start(ProtocolFactory, Service, ClientOp
             Started
     end.
 
+-spec call(term(), atom(), list()) -> {ok, term()} | {error, term()}.
 call(Client, Function, Args)
   when is_pid(Client), is_atom(Function), is_list(Args) ->
     case gen_server:call(Client, {call, Function, Args}) of
@@ -148,6 +149,7 @@ call(Client, Function, Args)
         {exception, Exception} -> throw(Exception)
     end.
 
+-spec cast(term(), atom(), list()) -> ok.
 cast(Client, Function, Args)
   when is_pid(Client), is_atom(Function), is_list(Args) ->
     gen_server:cast(Client, {call, Function, Args}).
@@ -155,10 +157,12 @@ cast(Client, Function, Args)
 %% Sends a function call but does not read the result. This is useful
 %% if you're trying to log non-oneway function calls to write-only
 %% transports like thrift_disk_log_transport.
+-spec send_call(term(), atom(), list()) -> ok.
 send_call(Client, Function, Args)
   when is_pid(Client), is_atom(Function), is_list(Args) ->
     gen_server:call(Client, {send_call, Function, Args}).
 
+-spec close(term()) -> ok.
 close(Client) when is_pid(Client) ->
     gen_server:cast(Client, close).
 

Modified: incubator/thrift/trunk/lib/erl/src/thrift_protocol.erl
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/erl/src/thrift_protocol.erl?rev=990972&r1=990971&r2=990972&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/erl/src/thrift_protocol.erl (original)
+++ incubator/thrift/trunk/lib/erl/src/thrift_protocol.erl Mon Aug 30 22:05:18 2010
@@ -49,10 +49,12 @@ new(Module, Data) when is_atom(Module) -
     {ok, #protocol{module = Module,
                    data = Data}}.
 
+-spec flush_transport(#protocol{}) -> ok.
 flush_transport(#protocol{module = Module,
                           data = Data}) ->
     Module:flush_transport(Data).
 
+-spec close_transport(#protocol{}) -> ok.
 close_transport(#protocol{module = Module,
                           data = Data}) ->
     Module:close_transport(Data).
@@ -86,6 +88,7 @@ term_to_typeid({list, _}) -> ?tType_LIST
 
 %% Structure is like:
 %%    [{Fid, Type}, ...]
+-spec read(#protocol{}, {struct, _StructDef}, atom()) -> {ok, tuple()}.
 read(IProto, {struct, Structure}, Tag)
   when is_list(Structure), is_atom(Tag) ->
 
@@ -112,6 +115,8 @@ read(IProto, {struct, Structure}, Tag)
     RTuple2 = read_struct_loop(IProto, SDict, RTuple1),
     {ok, RTuple2}.
 
+-spec read(#protocol{}, term()) -> term().
+
 read(IProto, {struct, {Module, StructureName}}) when is_atom(Module),
                                                      is_atom(StructureName) ->
     read(IProto, Module:struct_info(StructureName), StructureName);
@@ -183,6 +188,7 @@ skip_field(FType, IProto, SDict, RTuple)
     read(IProto, field_end),
     read_struct_loop(IProto, SDict, RTuple).
 
+-spec skip(#protocol{}, term()) -> ok.
 
 skip(Proto, struct) ->
     ok = read(Proto, struct_begin),
@@ -271,6 +277,8 @@ skip_list_loop(Proto, Map = #protocol_li
 %%
 %% Description:
 %%--------------------------------------------------------------------
+-spec write(#protocol{}, term()) -> ok | {error, _Reason}.
+
 write(Proto, {{struct, StructDef}, Data})
   when is_list(StructDef), is_tuple(Data), length(StructDef) == size(Data) - 1 ->