Rev 30 | Blame | Compare with Previous | Last modification | View Log | RSS feed
(*Licensed to the Apache Software Foundation (ASF) under oneor more contributor license agreements. See the NOTICE filedistributed with this work for additional informationregarding copyright ownership. The ASF licenses this fileto you under the Apache License, Version 2.0 (the"License"); you may not use this file except in compliancewith the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless 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 ANYKIND, either express or implied. See the License for thespecific language governing permissions and limitationsunder the License.*)exception Break;;exception Thrift_error;;exception Field_empty of string;;class t_exn =objectval mutable message = ""method get_message = messagemethod set_message s = message <- send;;module Transport =structtype exn_type =| UNKNOWN| NOT_OPEN| ALREADY_OPEN| TIMED_OUT| END_OF_FILE;;exception E of exn_type * stringclass virtual t =object (self)method virtual isOpen : boolmethod virtual opn : unitmethod virtual close : unitmethod virtual read : string -> int -> int -> intmethod readAll buf off len =let got = ref 0 inlet ret = ref 0 inwhile !got < len doret := self#read buf (off+(!got)) (len - (!got));if !ret <= 0 thenraise (E (UNKNOWN, "Cannot read. Remote side has closed."));got := !got + !retdone;!gotmethod virtual write : string -> int -> int -> unitmethod virtual flush : unitendclass factory =objectmethod getTransport (t : t) = tendclass virtual server_t =object (self)method virtual listen : unitmethod accept = self#acceptImplmethod virtual close : unitmethod virtual acceptImpl : tendend;;module Protocol =structtype t_type =| T_STOP| T_VOID| T_BOOL| T_BYTE| T_I08| T_I16| T_I32| T_U64| T_I64| T_DOUBLE| T_STRING| T_UTF7| T_STRUCT| T_MAP| T_SET| T_LIST| T_UTF8| T_UTF16let t_type_to_i = functionT_STOP -> 0| T_VOID -> 1| T_BOOL -> 2| T_BYTE -> 3| T_I08 -> 3| T_I16 -> 6| T_I32 -> 8| T_U64 -> 9| T_I64 -> 10| T_DOUBLE -> 4| T_STRING -> 11| T_UTF7 -> 11| T_STRUCT -> 12| T_MAP -> 13| T_SET -> 14| T_LIST -> 15| T_UTF8 -> 16| T_UTF16 -> 17let t_type_of_i = function0 -> T_STOP| 1 -> T_VOID| 2 -> T_BOOL| 3 -> T_BYTE| 6-> T_I16| 8 -> T_I32| 9 -> T_U64| 10 -> T_I64| 4 -> T_DOUBLE| 11 -> T_STRING| 12 -> T_STRUCT| 13 -> T_MAP| 14 -> T_SET| 15 -> T_LIST| 16 -> T_UTF8| 17 -> T_UTF16| _ -> raise Thrift_errortype message_type =| CALL| REPLY| EXCEPTION| ONEWAYlet message_type_to_i = function| CALL -> 1| REPLY -> 2| EXCEPTION -> 3| ONEWAY -> 4let message_type_of_i = function| 1 -> CALL| 2 -> REPLY| 3 -> EXCEPTION| 4 -> ONEWAY| _ -> raise Thrift_errorclass virtual t (trans: Transport.t) =object (self)val mutable trans_ = transmethod getTransport = trans_(* writing methods *)method virtual writeMessageBegin : string * message_type * int -> unitmethod virtual writeMessageEnd : unitmethod virtual writeStructBegin : string -> unitmethod virtual writeStructEnd : unitmethod virtual writeFieldBegin : string * t_type * int -> unitmethod virtual writeFieldEnd : unitmethod virtual writeFieldStop : unitmethod virtual writeMapBegin : t_type * t_type * int -> unitmethod virtual writeMapEnd : unitmethod virtual writeListBegin : t_type * int -> unitmethod virtual writeListEnd : unitmethod virtual writeSetBegin : t_type * int -> unitmethod virtual writeSetEnd : unitmethod virtual writeBool : bool -> unitmethod virtual writeByte : int -> unitmethod virtual writeI16 : int -> unitmethod virtual writeI32 : int -> unitmethod virtual writeI64 : Int64.t -> unitmethod virtual writeDouble : float -> unitmethod virtual writeString : string -> unitmethod virtual writeBinary : string -> unit(* reading methods *)method virtual readMessageBegin : string * message_type * intmethod virtual readMessageEnd : unitmethod virtual readStructBegin : stringmethod virtual readStructEnd : unitmethod virtual readFieldBegin : string * t_type * intmethod virtual readFieldEnd : unitmethod virtual readMapBegin : t_type * t_type * intmethod virtual readMapEnd : unitmethod virtual readListBegin : t_type * intmethod virtual readListEnd : unitmethod virtual readSetBegin : t_type * intmethod virtual readSetEnd : unitmethod virtual readBool : boolmethod virtual readByte : intmethod virtual readI16 : intmethod virtual readI32: intmethod virtual readI64 : Int64.tmethod virtual readDouble : floatmethod virtual readString : stringmethod virtual readBinary : string(* skippage *)method skip typ =match typ with| T_STOP -> ()| T_VOID -> ()| T_BOOL -> ignore self#readBool| T_BYTE| T_I08 -> ignore self#readByte| T_I16 -> ignore self#readI16| T_I32 -> ignore self#readI32| T_U64| T_I64 -> ignore self#readI64| T_DOUBLE -> ignore self#readDouble| T_STRING -> ignore self#readString| T_UTF7 -> ()| T_STRUCT -> ignore ((ignore self#readStructBegin);(trywhile true dolet (_,t,_) = self#readFieldBegin inif t = T_STOP thenraise Breakelse(self#skip t;self#readFieldEnd)donewith Break -> ());self#readStructEnd)| T_MAP -> ignore (let (k,v,s) = self#readMapBegin infor i=0 to s doself#skip k;self#skip v;done;self#readMapEnd)| T_SET -> ignore (let (t,s) = self#readSetBegin infor i=0 to s doself#skip tdone;self#readSetEnd)| T_LIST -> ignore (let (t,s) = self#readListBegin infor i=0 to s doself#skip tdone;self#readListEnd)| T_UTF8 -> ()| T_UTF16 -> ()endclass virtual factory =objectmethod virtual getProtocol : Transport.t -> tendtype exn_type =| UNKNOWN| INVALID_DATA| NEGATIVE_SIZE| SIZE_LIMIT| BAD_VERSIONexception E of exn_type * string;;end;;module Processor =structclass virtual t =objectmethod virtual process : Protocol.t -> Protocol.t -> boolend;;class factory (processor : t) =objectval processor_ = processormethod getProcessor (trans : Transport.t) = processor_end;;end(* Ugly *)module Application_Exn =structtype typ=| UNKNOWN| UNKNOWN_METHOD| INVALID_MESSAGE_TYPE| WRONG_METHOD_NAME| BAD_SEQUENCE_ID| MISSING_RESULTlet typ_of_i = function0 -> UNKNOWN| 1 -> UNKNOWN_METHOD| 2 -> INVALID_MESSAGE_TYPE| 3 -> WRONG_METHOD_NAME| 4 -> BAD_SEQUENCE_ID| 5 -> MISSING_RESULT| _ -> raise Thrift_error;;let typ_to_i = function| UNKNOWN -> 0| UNKNOWN_METHOD -> 1| INVALID_MESSAGE_TYPE -> 2| WRONG_METHOD_NAME -> 3| BAD_SEQUENCE_ID -> 4| MISSING_RESULT -> 5class t =object (self)inherit t_exnval mutable typ = UNKNOWNmethod get_type = typmethod set_type t = typ <- tmethod write (oprot : Protocol.t) =oprot#writeStructBegin "TApplicationExeception";if self#get_message != "" then(oprot#writeFieldBegin ("message",Protocol.T_STRING, 1);oprot#writeString self#get_message;oprot#writeFieldEnd)else ();oprot#writeFieldBegin ("type",Protocol.T_I32,2);oprot#writeI32 (typ_to_i typ);oprot#writeFieldEnd;oprot#writeFieldStop;oprot#writeStructEndend;;let create typ msg =let e = new t ine#set_type typ;e#set_message msg;elet read (iprot : Protocol.t) =let msg = ref "" inlet typ = ref 0 inignore iprot#readStructBegin;(trywhile true dolet (name,ft,id) =iprot#readFieldBegin inif ft = Protocol.T_STOP thenraise Breakelse ();(match id with| 1 -> (if ft = Protocol.T_STRING thenmsg := (iprot#readString)elseiprot#skip ft)| 2 -> (if ft = Protocol.T_I32 thentyp := iprot#readI32elseiprot#skip ft)| _ -> iprot#skip ft);iprot#readFieldEnddonewith Break -> ());iprot#readStructEnd;let e = new t ine#set_type (typ_of_i !typ);e#set_message !msg;e;;exception E of tend;;