2 Licensed to the Apache Software Foundation (ASF) under one
3 or more contributor license agreements. See the NOTICE file
4 distributed with this work for additional information
5 regarding copyright ownership. The ASF licenses this file
6 to you under the Apache License, Version 2.0 (the
7 "License"); you may not use this file except in compliance
8 with the License. You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing,
13 software distributed under the License is distributed on an
14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 KIND, either express or implied. See the License for the
16 specific language governing permissions and limitations
21 exception Thrift_error;;
22 exception Field_empty of string;;
26 val mutable message = ""
27 method get_message = message
28 method set_message s = message <- s
40 exception E of exn_type * string
44 method virtual isOpen : bool
45 method virtual opn : unit
46 method virtual close : unit
47 method virtual read : string -> int -> int -> int
48 method readAll buf off len =
52 ret := self#read buf (off+(!got)) (len - (!got));
54 raise (E (UNKNOWN, "Cannot read. Remote side has closed."));
58 method virtual write : string -> int -> int -> unit
59 method virtual flush : unit
64 method getTransport (t : t) = t
67 class virtual server_t =
69 method virtual listen : unit
70 method accept = self#acceptImpl
71 method virtual close : unit
72 method virtual acceptImpl : t
101 let t_type_to_i = function
121 let t_type_of_i = function
138 | _ -> raise Thrift_error
146 let message_type_to_i = function
152 let message_type_of_i = function
157 | _ -> raise Thrift_error
159 class virtual t (trans: Transport.t) =
161 val mutable trans_ = trans
162 method getTransport = trans_
163 (* writing methods *)
164 method virtual writeMessageBegin : string * message_type * int -> unit
165 method virtual writeMessageEnd : unit
166 method virtual writeStructBegin : string -> unit
167 method virtual writeStructEnd : unit
168 method virtual writeFieldBegin : string * t_type * int -> unit
169 method virtual writeFieldEnd : unit
170 method virtual writeFieldStop : unit
171 method virtual writeMapBegin : t_type * t_type * int -> unit
172 method virtual writeMapEnd : unit
173 method virtual writeListBegin : t_type * int -> unit
174 method virtual writeListEnd : unit
175 method virtual writeSetBegin : t_type * int -> unit
176 method virtual writeSetEnd : unit
177 method virtual writeBool : bool -> unit
178 method virtual writeByte : int -> unit
179 method virtual writeI16 : int -> unit
180 method virtual writeI32 : Int32.t -> unit
181 method virtual writeI64 : Int64.t -> unit
182 method virtual writeDouble : float -> unit
183 method virtual writeString : string -> unit
184 method virtual writeBinary : string -> unit
185 (* reading methods *)
186 method virtual readMessageBegin : string * message_type * int
187 method virtual readMessageEnd : unit
188 method virtual readStructBegin : string
189 method virtual readStructEnd : unit
190 method virtual readFieldBegin : string * t_type * int
191 method virtual readFieldEnd : unit
192 method virtual readMapBegin : t_type * t_type * int
193 method virtual readMapEnd : unit
194 method virtual readListBegin : t_type * int
195 method virtual readListEnd : unit
196 method virtual readSetBegin : t_type * int
197 method virtual readSetEnd : unit
198 method virtual readBool : bool
199 method virtual readByte : int
200 method virtual readI16 : int
201 method virtual readI32: Int32.t
202 method virtual readI64 : Int64.t
203 method virtual readDouble : float
204 method virtual readString : string
205 method virtual readBinary : string
209 | T_BOOL -> ignore self#readBool
211 | T_I08 -> ignore self#readByte
212 | T_I16 -> ignore self#readI16
213 | T_I32 -> ignore self#readI32
215 | T_I64 -> ignore self#readI64
216 | T_DOUBLE -> ignore self#readDouble
217 | T_STRING -> ignore self#readString
219 | T_STRUCT -> ignore ((ignore self#readStructBegin);
222 let (_,t,_) = self#readFieldBegin in
231 | T_MAP -> ignore (let (k,v,s) = self#readMapBegin in
237 | T_SET -> ignore (let (t,s) = self#readSetBegin in
242 | T_LIST -> ignore (let (t,s) = self#readListBegin in
249 | _ -> raise (Protocol.E (Protocol.INVALID_DATA, "Invalid data"))
252 class virtual factory =
254 method virtual getProtocol : Transport.t -> t
266 exception E of exn_type * string;;
275 method virtual process : Protocol.t -> Protocol.t -> bool
278 class factory (processor : t) =
280 val processor_ = processor
281 method getProcessor (trans : Transport.t) = processor_
287 module Application_Exn =
292 | INVALID_MESSAGE_TYPE
300 | UNSUPPORTED_CLIENT_TYPE
302 let typ_of_i = function
304 | 1l -> UNKNOWN_METHOD
305 | 2l -> INVALID_MESSAGE_TYPE
306 | 3l -> WRONG_METHOD_NAME
307 | 4l -> BAD_SEQUENCE_ID
308 | 5l -> MISSING_RESULT
309 | 6l -> INTERNAL_ERROR
310 | 7l -> PROTOCOL_ERROR
311 | 8l -> INVALID_TRANSFORM
312 | 9l -> INVALID_PROTOCOL
313 | 10l -> UNSUPPORTED_CLIENT_TYPE
314 | _ -> raise Thrift_error;;
315 let typ_to_i = function
317 | UNKNOWN_METHOD -> 1l
318 | INVALID_MESSAGE_TYPE -> 2l
319 | WRONG_METHOD_NAME -> 3l
320 | BAD_SEQUENCE_ID -> 4l
321 | MISSING_RESULT -> 5l
322 | INTERNAL_ERROR -> 6l
323 | PROTOCOL_ERROR -> 7l
324 | INVALID_TRANSFORM -> 8l
325 | INVALID_PROTOCOL -> 9l
326 | UNSUPPORTED_CLIENT_TYPE -> 10l
331 val mutable typ = UNKNOWN
332 method get_type = typ
333 method set_type t = typ <- t
334 method write (oprot : Protocol.t) =
335 oprot#writeStructBegin "TApplicationExeception";
336 if self#get_message != "" then
337 (oprot#writeFieldBegin ("message",Protocol.T_STRING, 1);
338 oprot#writeString self#get_message;
341 oprot#writeFieldBegin ("type",Protocol.T_I32,2);
342 oprot#writeI32 (typ_to_i typ);
344 oprot#writeFieldStop;
354 let read (iprot : Protocol.t) =
357 ignore iprot#readStructBegin;
360 let (name,ft,id) =iprot#readFieldBegin in
361 if ft = Protocol.T_STOP
365 | 1 -> (if ft = Protocol.T_STRING
366 then msg := (iprot#readString)
368 | 2 -> (if ft = Protocol.T_I32
369 then typ := iprot#readI32
371 | _ -> iprot#skip ft);
377 e#set_type (typ_of_i !typ);