diff options
author | iproctor <dev-null@apache.org> | 2007-07-24 19:47:55 +0000 |
---|---|---|
committer | iproctor <dev-null@apache.org> | 2007-07-24 19:47:55 +0000 |
commit | d4de1e93c653c048f54944b331f8350dc45b81c0 (patch) | |
tree | 7cfba8728af773d0370bca1a71460b4cd3c665dd /lib/ocaml | |
parent | 873726035af15c467770ca56a99f90f3f0ffd5a6 (diff) | |
download | thrift-d4de1e93c653c048f54944b331f8350dc45b81c0.tar.gz |
Thrift: OCaml library binary protocol fix
Summary: Binary protocol wasn't dealing with messages properly. Also
there was a math bug in readI32.
Reviewed by: mcslee
Test plan: Yes
Revert plan: yes
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665171 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'lib/ocaml')
-rw-r--r-- | lib/ocaml/src/TBinaryProtocol.ml | 25 | ||||
-rw-r--r-- | lib/ocaml/src/Thrift.ml | 9 |
2 files changed, 25 insertions, 9 deletions
diff --git a/lib/ocaml/src/TBinaryProtocol.ml b/lib/ocaml/src/TBinaryProtocol.ml index 44433d6a9..748423f96 100644 --- a/lib/ocaml/src/TBinaryProtocol.ml +++ b/lib/ocaml/src/TBinaryProtocol.ml @@ -11,13 +11,12 @@ let vt = P.t_type_of_i let comp_int b n = - let s = ref 0 in - let sb = Sys.word_size - 8*n in + let s = ref 0l in + let sb = 32 - 8*n in for i=0 to (n-1) do - s:=!s lor ((int_of_char b.[i]) lsl (8*(n-1-i))) + s:= Int32.logor !s (Int32.shift_left (Int32.of_int (int_of_char b.[i])) (8*(n-1-i))) done; - s:=(!s lsl sb) asr sb; - !s + Int32.to_int (Int32.shift_right (Int32.shift_left !s sb) sb) let comp_int64 b n = let s = ref 0L in @@ -26,6 +25,9 @@ let comp_int64 b n = done; !s +let version_mask = 0xffff0000 +let version_1 = 0x80010000 + class t trans = object (self) inherit P.t trans @@ -61,8 +63,8 @@ object (self) trans#write s 0 n method writeBinary a = self#writeString a method writeMessageBegin (n,t,s) = + self#writeI32 (version_1 lor (P.message_type_to_i t)); self#writeString n; - self#writeByte (P.message_type_to_i t); self#writeI32 s method writeMessageEnd = () method writeStructBegin s = () @@ -109,9 +111,14 @@ object (self) buf method readBinary = self#readString method readMessageBegin = - let s = self#readString in - let mt = P.message_type_of_i (self#readByte) in - (s,mt, self#readI32) + let ver = self#readI32 in + if (ver land version_mask != version_1) then + (print_int ver; + raise (P.TProtocolExn (P.BAD_VERSION, "Missing version identifier"))) + else + let s = self#readString in + let mt = P.message_type_of_i (ver land 0xFF) in + (s,mt, self#readI32) method readMessageEnd = () method readStructBegin = "" diff --git a/lib/ocaml/src/Thrift.ml b/lib/ocaml/src/Thrift.ml index 224febbc5..8ff5fa9d5 100644 --- a/lib/ocaml/src/Thrift.ml +++ b/lib/ocaml/src/Thrift.ml @@ -252,6 +252,15 @@ struct object method virtual getProtocol : Transport.t -> t end + + type exn_type = + | UNKNOWN + | INVALID_DATA + | NEGATIVE_SIZE + | SIZE_LIMIT + | BAD_VERSION + + exception TProtocolExn of exn_type * string;; end;; |