From: David Reiss Date: Mon, 30 Aug 2010 22:05:23 +0000 (+0000) Subject: erlang: Separate out thrift_binary_protocol:read_data X-Git-Tag: 0.5.0~130 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=48b8124e3289484193833049fde3fb4c584cd457;p=common%2Fthrift.git erlang: Separate out thrift_binary_protocol:read_data By giving a different name to the function that reads bytes from the transport, we can get a slightly more detailed spec. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@990975 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/erl/include/thrift_protocol_impl.hrl b/lib/erl/include/thrift_protocol_impl.hrl index e816d790..fe9d20d3 100644 --- a/lib/erl/include/thrift_protocol_impl.hrl +++ b/lib/erl/include/thrift_protocol_impl.hrl @@ -28,7 +28,6 @@ -spec write(state(), term()) -> ok | {error, _Reason}. -spec read - (state(), non_neg_integer()) -> {ok, binary()} | {error, _Reason}; (state(), tprot_empty_tag()) -> ok | {error, _Reason}; (state(), tprot_header_tag()) -> tprot_header_val() | {error, _Reason}; (state(), tprot_data_tag()) -> {ok, term()} | {error, _Reason}. diff --git a/lib/erl/src/thrift_binary_protocol.erl b/lib/erl/src/thrift_binary_protocol.erl index a898dfe6..00300bad 100644 --- a/lib/erl/src/thrift_binary_protocol.erl +++ b/lib/erl/src/thrift_binary_protocol.erl @@ -187,7 +187,7 @@ read(This, message_begin) -> {ok, Sz} when This#binary_protocol.strict_read =:= false -> %% strict_read is false, so just read the old way - {ok, Name} = read(This, Sz), + {ok, Name} = read_data(This, Sz), {ok, Type} = read(This, byte), {ok, SeqId} = read(This, i32), #protocol_message_begin{name = binary_to_list(Name), @@ -252,19 +252,19 @@ read(This, bool) -> end; read(This, byte) -> - case read(This, 1) of + case read_data(This, 1) of {ok, <>} -> {ok, Val}; Else -> Else end; read(This, i16) -> - case read(This, 2) of + case read_data(This, 2) of {ok, <>} -> {ok, Val}; Else -> Else end; read(This, i32) -> - case read(This, 4) of + case read_data(This, 4) of {ok, <>} -> {ok, Val}; Else -> Else end; @@ -273,19 +273,19 @@ read(This, i32) -> %% of the packet version header. Without this special function BEAM works fine %% but hipe thinks it received a bad version header. read(This, ui32) -> - case read(This, 4) of + case read_data(This, 4) of {ok, <>} -> {ok, Val}; Else -> Else end; read(This, i64) -> - case read(This, 8) of + case read_data(This, 8) of {ok, <>} -> {ok, Val}; Else -> Else end; read(This, double) -> - case read(This, 8) of + case read_data(This, 8) of {ok, <>} -> {ok, Val}; Else -> Else end; @@ -293,10 +293,11 @@ read(This, double) -> % returns a binary directly, call binary_to_list if necessary read(This, string) -> {ok, Sz} = read(This, i32), - {ok, Bin} = read(This, Sz); + {ok, Bin} = read_data(This, Sz). -read(This, 0) -> {ok, <<>>}; -read(This, Len) when is_integer(Len), Len >= 0 -> +-spec read_data(#binary_protocol{}, non_neg_integer()) -> {ok, binary()} | {error, _Reason}. +read_data(This, 0) -> {ok, <<>>}; +read_data(This, Len) when is_integer(Len), Len >= 0 -> thrift_transport:read(This#binary_protocol.transport, Len).