1 // Licensed to the Apache Software Foundation(ASF) under one
2 // or more contributor license agreements.See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership.The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17 
18 const char* snapshot(R"""(
19 open Thrift
20 open Service_types
21 
22 (* HELPER FUNCTIONS AND STRUCTURES *)
23 
24 class ping_args =
25 object (self)
26   method copy =
27       let _new = Oo.copy self in
28     _new
29   method write (oprot : Protocol.t) =
30     oprot#writeStructBegin "ping_args";
31     oprot#writeFieldStop;
32     oprot#writeStructEnd
33 end
34 let rec read_ping_args (iprot : Protocol.t) =
35   let _str2 = new ping_args in
36     ignore(iprot#readStructBegin);
37     (try while true do
38         let (_,_t3,_id4) = iprot#readFieldBegin in
39         if _t3 = Protocol.T_STOP then
40           raise Break
41         else ();
42         (match _id4 with
43           | _ -> iprot#skip _t3);
44         iprot#readFieldEnd;
45       done; ()
46     with Break -> ());
47     iprot#readStructEnd;
48     _str2
49 
50 class ping_result =
51 object (self)
52   val mutable _serverError : Errors_types.serverError option = None
53   method get_serverError = _serverError
54   method grab_serverError = match _serverError with None->raise (Field_empty "ping_result.serverError") | Some _x5 -> _x5
55   method set_serverError _x5 = _serverError <- Some _x5
56   method unset_serverError = _serverError <- None
57   method reset_serverError = _serverError <- None
58 
59   method copy =
60       let _new = Oo.copy self in
61       if _serverError <> None then
62         _new#set_serverError self#grab_serverError#copy;
63     _new
64   method write (oprot : Protocol.t) =
65     oprot#writeStructBegin "ping_result";
66     (match _serverError with None -> () | Some _v ->
67       oprot#writeFieldBegin("serverError",Protocol.T_STRUCT,1);
68       _v#write(oprot);
69       oprot#writeFieldEnd
70     );
71     oprot#writeFieldStop;
72     oprot#writeStructEnd
73 end
74 let rec read_ping_result (iprot : Protocol.t) =
75   let _str8 = new ping_result in
76     ignore(iprot#readStructBegin);
77     (try while true do
78         let (_,_t9,_id10) = iprot#readFieldBegin in
79         if _t9 = Protocol.T_STOP then
80           raise Break
81         else ();
82         (match _id10 with
83           | 1 -> (if _t9 = Protocol.T_STRUCT then
84               _str8#set_serverError (Errors_types.read_serverError iprot)
85             else
86               iprot#skip _t9)
87           | _ -> iprot#skip _t9);
88         iprot#readFieldEnd;
89       done; ()
90     with Break -> ());
91     iprot#readStructEnd;
92     _str8
93 
94 class virtual iface =
95 object (self)
96   method virtual ping : unit
97 end
98 
99 class client (iprot : Protocol.t) (oprot : Protocol.t) =
100 object (self)
101   val mutable seqid = 0
102   method ping  =
103     self#send_ping;
104     self#recv_ping
105   method private send_ping  =
106     oprot#writeMessageBegin ("ping", Protocol.CALL, seqid);
107     let args = new ping_args in
108       args#write oprot;
109       oprot#writeMessageEnd;
110       oprot#getTransport#flush
111   method private recv_ping  =
112     let (fname, mtype, rseqid) = iprot#readMessageBegin in
113       (if mtype = Protocol.EXCEPTION then
114         let x = Application_Exn.read iprot in
115           (iprot#readMessageEnd;           raise (Application_Exn.E x))
116       else ());
117       let result = read_ping_result iprot in
118         iprot#readMessageEnd;
119         (match result#get_serverError with None -> () | Some _v ->
120           raise (Errors_types.ServerError _v));
121         ()
122 end
123 
124 class processor (handler : iface) =
125 object (self)
126   inherit Processor.t
127 
128   val processMap = Hashtbl.create 1
129   method process iprot oprot =
130     let (name, typ, seqid)  = iprot#readMessageBegin in
131       if Hashtbl.mem processMap name then
132         (Hashtbl.find processMap name) (seqid, iprot, oprot)
133       else (
134         iprot#skip(Protocol.T_STRUCT);
135         iprot#readMessageEnd;
136         let x = Application_Exn.create Application_Exn.UNKNOWN_METHOD ("Unknown function "^name) in
137           oprot#writeMessageBegin(name, Protocol.EXCEPTION, seqid);
138           x#write oprot;
139           oprot#writeMessageEnd;
140           oprot#getTransport#flush
141       );
142       true
143   method private process_ping (seqid, iprot, oprot) =
144     let _ = read_ping_args iprot in
145       iprot#readMessageEnd;
146       let result = new ping_result in
147         (try
148           (handler#ping);
149         with
150           | Errors_types.ServerError serverError ->
151               result#set_serverError serverError
152         );
153         oprot#writeMessageBegin ("ping", Protocol.REPLY, seqid);
154         result#write oprot;
155         oprot#writeMessageEnd;
156         oprot#getTransport#flush
157   initializer
158     Hashtbl.add processMap "ping" self#process_ping;
159 end
160 
161 )""");
162