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