Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 232 lines (209 sloc) 6.953 kb
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18
19 (**
20 Bson: Module to allow the creation of BSON values in strings.
21
22 You use module Append to create the values:
23
24 let buf = Append.init ?hint () in
25 Append.int buf 123;
26 <etc...>
27 Append.finish buf
28
29 Use Iterator to scan BSON values:
30
31 let iter = Iterator.init buf;
32 <or...>
33 let iter = Iterator.from_buffer str;
34 let code = Iterator.next iter in
35 let key = Iterator.key iter in
36 match code with
37 | c when c = el_int ->
38 let i = Iterator.int iter in
39 <...>
40
41 There is a second Iterator module, IteratorSS which is founded on
42 BaseStringSlice which may be more efficient on deeply-nested
43 BSON objects (sub is a unit-time operation but note that the
44 returned sub-string will not be a copy, updating the sub-string
45 will cause the parent string to be altered, too).
46
47 **)
48
49 module type S_sig =
50 sig
51 type t
52 val empty : t
53 val length : t -> int
54 val get : t -> int -> char
55 val set : t -> int -> char -> unit
56 val create : int -> t
57 val make : int -> char -> t
58 val copy : t -> t
59 val sub : t -> int -> int -> t
60 val fill : t -> int -> int -> char -> unit
61 val blit : t -> int -> t -> int -> int -> unit
62 val concat : t -> t list -> t
63 val iter : (char -> unit) -> t -> unit
64 val escaped : t -> t
65 val index : t -> char -> int
66 val rindex : t -> char -> int
67 val index_from : t -> int -> char -> int
68 val rindex_from : t -> int -> char -> int
69 val contains : t -> char -> bool
70 val contains_from : t -> int -> char -> bool
71 val rcontains_from : t -> int -> char -> bool
72 val uppercase : t -> t
73 val lowercase : t -> t
74 val capitalize : t -> t
75 val uncapitalize : t -> t
76 val compare : t -> t -> int
77 val unsafe_get : t -> int -> char
78 val unsafe_set : t -> int -> char -> unit
79 val unsafe_blit : t -> int -> t -> int -> int -> unit
80 val unsafe_fill : t -> int -> int -> char -> unit
81 val to_string : t -> string
82 val of_string : string -> t
83 val export : t -> string * int * int
84 val import : string * int * int -> t
85 val widen : t -> unit
86 val normalize : t -> t
87 val real_size : t -> int
88 val set_size : t -> int -> t
89 val rebase : t -> unit
90 val unsafe_sub : t -> int -> int -> t
91 end
92
93 module S : S_sig with type t = string
94 module SS : S_sig with type t = BaseStringSlice.t
95
96 val el_eoo : char
97 val el_double : char
98 val el_string : char
99 val el_object : char
100 val el_array : char
101 val el_bindata : char
102 val el_undefined : char
103 val el_oid : char
104 val el_bool : char
105 val el_date : char
106 val el_null : char
107 val el_regex : char
108 val el_dbref : char
109 val el_code : char
110 val el_symbol : char
111 val el_codewscope : char
112 val el_int : char
113 val el_timestamp : char
114 val el_long : char
115 val el_minkey : char
116 val el_maxkey : char
117 val st_bin_binary : char
118 val st_bin_func : char
119 val st_bin_binary_old : char
120 val st_bin_uuid : char
121 val st_bin_md5 : char
122 val st_bin_user : char
123
124 type buf = {
68933f7 @nrs135 [feature] mongo: Partial version of mongo wire protocol.
nrs135 authored
125 buf : Buf.buf;
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
126 mutable stack : int list;
127 mutable finished : bool;
128 }
129
130 module Oid :
131 sig
132 val from_string : string -> S.t
133 val to_string : string -> S.t
134 val counter : int ref
135 val gen : unit -> S.t
136 val generated_time : S.t -> Time.t
137 end
138
139 module Append :
140 sig
141 val init : ?hint:int -> unit -> buf
142 val empty : buf
143 val size : buf -> int
68933f7 @nrs135 [feature] mongo: Partial version of mongo wire protocol.
nrs135 authored
144 val estart : buf -> char -> S.t -> unit
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
145 val int : buf -> S.t -> int -> unit
146 val long : buf -> S.t -> int -> unit
147 val double : buf -> S.t -> float -> unit
148 val bool : buf -> S.t -> bool -> unit
149 val null : buf -> S.t -> unit
150 val undefined : buf -> S.t -> unit
151 val string_base : buf -> S.t -> S.t -> int -> char -> unit
152 val string : buf -> S.t -> S.t -> unit
153 val symbol : buf -> S.t -> S.t -> unit
154 val code : buf -> S.t -> S.t -> unit
155 val string_n : buf -> S.t -> S.t -> int -> unit
156 val symbol_n : buf -> S.t -> S.t -> int -> unit
157 val code_n : buf -> S.t -> S.t -> int -> unit
158 val code_w_scope_n : buf -> S.t -> S.t -> int -> buf -> unit
159 val code_w_scope : buf -> S.t -> S.t -> buf -> unit
160 val start_codewscope : buf -> S.t -> S.t -> unit
161 val finish_codewscope : buf -> S.t -> unit
162 val binary : buf -> S.t -> char -> S.t -> int -> unit
163 val oid : buf -> S.t -> S.t -> unit
164 val new_oid : buf -> S.t -> unit
165 val regex : buf -> S.t -> S.t -> S.t -> unit
166 val bson : buf -> S.t -> buf -> unit
167 val timestamp : buf -> S.t -> int * int -> unit
168 val date : buf -> S.t -> int -> unit
169 val time_t : buf -> S.t -> Time.t -> unit
170 val start_object : buf -> S.t -> unit
171 val start_array : buf -> S.t -> unit
172 val finish_object : buf -> unit
173 val finish_array : buf -> unit
174 val finish : buf -> unit
175 val get : buf -> S.t
176 end
177
178 module type Iterator_sig =
179 sig
180 module S : S_sig
68933f7 @nrs135 [feature] mongo: Partial version of mongo wire protocol.
nrs135 authored
181 type iter = { ibuf : S.t; mutable pos : int; mutable first : bool; }
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
182 val init : buf -> iter
183 val from_buffer : S.t -> iter
184 val iterator_type : iter -> char
185 val key : iter -> S.t
186 val value : iter -> int
187 val int_raw : iter -> int
188 val long_raw : iter -> int
189 val double_raw : iter -> float
190 val bool_raw : iter -> bool
191 val oid : iter -> S.t
192 val string : ?offset:int -> iter -> S.t
193 val symbol : ?offset:int -> iter -> S.t
194 val bslen : S.t -> int -> int
195 val cstring : ?offset:int -> iter -> S.t
196 val string_len : iter -> int
197 val int : iter -> int
198 val long : iter -> int
199 val double : iter -> float
200 val timestamp : iter -> int * int
201 val bool : iter -> bool
202 val code : iter -> S.t
203 val code_scope : iter -> buf
204 val date : iter -> int
205 val time_t : iter -> Time.t
206 val bin_type : iter -> char
207 val bin_len : iter -> int
208 val bin_data : iter -> S.t
209 val regex : iter -> S.t
210 val regex_opts : iter -> S.t
211 val subobject : iter -> buf
212 val subiterator : iter -> iter
213 val next : iter -> char
214 val find : buf -> S.t -> iter * char
215 end
216
217 module IteratorF(S : S_sig) : Iterator_sig with module S = S
218 module Iterator : Iterator_sig with module S = S
219 module IteratorSS : Iterator_sig with module S = SS
220
68933f7 @nrs135 [feature] mongo: Partial version of mongo wire protocol.
nrs135 authored
221 (*module Element :
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
222 sig
223 val element : buf -> S.t option -> Iterator.iter -> unit
68933f7 @nrs135 [feature] mongo: Partial version of mongo wire protocol.
nrs135 authored
224 end*)
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
225
226 module Print :
227 sig
228 val print : buf -> unit
229 val print_raw : S.t -> int -> int -> unit
230 end
231
Something went wrong with that request. Please try again.