iproctor | 9a41a0c | 2007-07-16 21:59:24 +0000 | [diff] [blame] | 1 | Library |
| 2 | ------- |
iproctor | e470aa3 | 2007-08-10 20:48:12 +0000 | [diff] [blame] | 3 | The library abstract classes, exceptions, and general use functions |
| 4 | are mostly jammed in Thrift.ml (an exception being |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame^] | 5 | TServer). |
iproctor | 9a41a0c | 2007-07-16 21:59:24 +0000 | [diff] [blame] | 6 | |
iproctor | e470aa3 | 2007-08-10 20:48:12 +0000 | [diff] [blame] | 7 | Generally, classes are used, however they are often put in their own |
| 8 | module along with other relevant types and functions. The classes |
| 9 | often called t, exceptions are called E. |
| 10 | |
| 11 | Implementations live in their own files. There is TBinaryProtocol, |
| 12 | TSocket, TThreadedServer, TSimpleServer, and TServerSocket. |
| 13 | |
| 14 | A note on making the library: Running make should create native, debug |
| 15 | code libraries, and a toplevel. |
iproctor | 9a41a0c | 2007-07-16 21:59:24 +0000 | [diff] [blame] | 16 | |
| 17 | |
| 18 | Struct format |
| 19 | ------------- |
iproctor | e470aa3 | 2007-08-10 20:48:12 +0000 | [diff] [blame] | 20 | Structs are turned into classes. The fields are all option types and |
| 21 | are initially None. Write is a method, but reading is done by a |
| 22 | separate function (since there is no such thing as a static |
| 23 | class). The class type is t and is in a module with the name of the |
| 24 | struct. |
iproctor | 9a41a0c | 2007-07-16 21:59:24 +0000 | [diff] [blame] | 25 | |
| 26 | |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame^] | 27 | enum format |
iproctor | 9a41a0c | 2007-07-16 21:59:24 +0000 | [diff] [blame] | 28 | ----------- |
iproctor | e470aa3 | 2007-08-10 20:48:12 +0000 | [diff] [blame] | 29 | Enums are put in their own module along with |
| 30 | functions to_i and of_i which convert the ocaml types into ints. For |
| 31 | example: |
iproctor | 9a41a0c | 2007-07-16 21:59:24 +0000 | [diff] [blame] | 32 | |
| 33 | enum Numberz |
| 34 | { |
| 35 | ONE = 1, |
| 36 | TWO, |
| 37 | THREE, |
| 38 | FIVE = 5, |
| 39 | SIX, |
| 40 | EIGHT = 8 |
| 41 | } |
| 42 | |
| 43 | ==> |
| 44 | |
iproctor | e470aa3 | 2007-08-10 20:48:12 +0000 | [diff] [blame] | 45 | module Numberz = |
iproctor | 9a41a0c | 2007-07-16 21:59:24 +0000 | [diff] [blame] | 46 | struct |
| 47 | type t = |
| 48 | | ONE |
| 49 | | TWO |
| 50 | | THREE |
| 51 | | FIVE |
| 52 | | SIX |
| 53 | | EIGHT |
| 54 | |
| 55 | let of_i = ... |
| 56 | let to_i = ... |
| 57 | end |
| 58 | |
| 59 | typedef format |
| 60 | -------------- |
| 61 | Typedef turns into the type declaration: |
| 62 | typedef i64 UserId |
| 63 | |
| 64 | ==> |
| 65 | |
| 66 | type userid Int64.t |
| 67 | |
| 68 | exception format |
| 69 | ---------------- |
iproctor | e470aa3 | 2007-08-10 20:48:12 +0000 | [diff] [blame] | 70 | The same as structs except that the module also has an exception type |
| 71 | E of t that is raised/caught. |
iproctor | 9a41a0c | 2007-07-16 21:59:24 +0000 | [diff] [blame] | 72 | |
iproctor | e470aa3 | 2007-08-10 20:48:12 +0000 | [diff] [blame] | 73 | For example, with an exception Xception, |
| 74 | raise (Xception.E (new Xception.t)) |
| 75 | and |
| 76 | try |
| 77 | ... |
| 78 | with Xception.E e -> ... |
iproctor | 9a41a0c | 2007-07-16 21:59:24 +0000 | [diff] [blame] | 79 | |
| 80 | list format |
| 81 | ----------- |
iproctor | e470aa3 | 2007-08-10 20:48:12 +0000 | [diff] [blame] | 82 | Lists are turned into OCaml native lists. |
iproctor | 9a41a0c | 2007-07-16 21:59:24 +0000 | [diff] [blame] | 83 | |
| 84 | Map/Set formats |
| 85 | --------------- |
iproctor | e470aa3 | 2007-08-10 20:48:12 +0000 | [diff] [blame] | 86 | These are both turned into Hashtbl.t's. Set values are bool. |
iproctor | 9a41a0c | 2007-07-16 21:59:24 +0000 | [diff] [blame] | 87 | |
| 88 | Services |
| 89 | -------- |
iproctor | e470aa3 | 2007-08-10 20:48:12 +0000 | [diff] [blame] | 90 | The client is a class "client" parametrized on input and output |
| 91 | protocols. The processor is a class parametrized on a handler. A |
| 92 | handler is a class inheriting the iface abstract class. Unlike other |
| 93 | implementations, client does not implement iface since iface functions |
| 94 | must take option arguments so as to deal with the case where a client |
| 95 | does not send all the arguments. |