blob: 5a47a42475ad41d84e836c8f083c78d5a78a8450 [file] [log] [blame]
Bryan Duxburydef30a62009-04-08 00:19:37 +00001Thrift OCaml Software Library
2
3License
4=======
5
6Licensed to the Apache Software Foundation (ASF) under one
7or more contributor license agreements. See the NOTICE file
8distributed with this work for additional information
9regarding copyright ownership. The ASF licenses this file
10to you under the Apache License, Version 2.0 (the
11"License"); you may not use this file except in compliance
12with the License. You may obtain a copy of the License at
13
14 http://www.apache.org/licenses/LICENSE-2.0
15
16Unless required by applicable law or agreed to in writing,
17software distributed under the License is distributed on an
18"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19KIND, either express or implied. See the License for the
20specific language governing permissions and limitations
21under the License.
22
23
iproctor9a41a0c2007-07-16 21:59:24 +000024Library
Bryan Duxburydef30a62009-04-08 00:19:37 +000025=======
26
iproctore470aa32007-08-10 20:48:12 +000027The library abstract classes, exceptions, and general use functions
28are mostly jammed in Thrift.ml (an exception being
David Reiss0c90f6f2008-02-06 22:18:40 +000029TServer).
iproctor9a41a0c2007-07-16 21:59:24 +000030
iproctore470aa32007-08-10 20:48:12 +000031Generally, classes are used, however they are often put in their own
32module along with other relevant types and functions. The classes
33often called t, exceptions are called E.
34
35Implementations live in their own files. There is TBinaryProtocol,
36TSocket, TThreadedServer, TSimpleServer, and TServerSocket.
37
38A note on making the library: Running make should create native, debug
39code libraries, and a toplevel.
iproctor9a41a0c2007-07-16 21:59:24 +000040
41
42Struct format
43-------------
iproctore470aa32007-08-10 20:48:12 +000044Structs are turned into classes. The fields are all option types and
45are initially None. Write is a method, but reading is done by a
46separate function (since there is no such thing as a static
47class). The class type is t and is in a module with the name of the
48struct.
iproctor9a41a0c2007-07-16 21:59:24 +000049
50
David Reiss0c90f6f2008-02-06 22:18:40 +000051enum format
iproctor9a41a0c2007-07-16 21:59:24 +000052-----------
iproctore470aa32007-08-10 20:48:12 +000053Enums are put in their own module along with
54functions to_i and of_i which convert the ocaml types into ints. For
55example:
iproctor9a41a0c2007-07-16 21:59:24 +000056
57enum Numberz
58{
59 ONE = 1,
60 TWO,
61 THREE,
62 FIVE = 5,
63 SIX,
64 EIGHT = 8
65}
66
67==>
68
iproctore470aa32007-08-10 20:48:12 +000069module Numberz =
iproctor9a41a0c2007-07-16 21:59:24 +000070struct
71type t =
72| ONE
73| TWO
74| THREE
75| FIVE
76| SIX
77| EIGHT
78
79let of_i = ...
80let to_i = ...
81end
82
83typedef format
84--------------
85Typedef turns into the type declaration:
86typedef i64 UserId
87
88==>
89
90type userid Int64.t
91
92exception format
93----------------
iproctore470aa32007-08-10 20:48:12 +000094The same as structs except that the module also has an exception type
95E of t that is raised/caught.
iproctor9a41a0c2007-07-16 21:59:24 +000096
iproctore470aa32007-08-10 20:48:12 +000097For example, with an exception Xception,
98raise (Xception.E (new Xception.t))
99and
100try
101 ...
102with Xception.E e -> ...
iproctor9a41a0c2007-07-16 21:59:24 +0000103
104list format
105-----------
iproctore470aa32007-08-10 20:48:12 +0000106Lists are turned into OCaml native lists.
iproctor9a41a0c2007-07-16 21:59:24 +0000107
108Map/Set formats
109---------------
iproctore470aa32007-08-10 20:48:12 +0000110These are both turned into Hashtbl.t's. Set values are bool.
iproctor9a41a0c2007-07-16 21:59:24 +0000111
112Services
113--------
iproctore470aa32007-08-10 20:48:12 +0000114The client is a class "client" parametrized on input and output
115protocols. The processor is a class parametrized on a handler. A
116handler is a class inheriting the iface abstract class. Unlike other
117implementations, client does not implement iface since iface functions
118must take option arguments so as to deal with the case where a client
119does not send all the arguments.