Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 294 lines (267 sloc) 9.065 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
97fe605 @nrs135 [fix] stdlib: Move stuff.ml into bson.ml. Remove endian.ml. Defaul…
nrs135 authored
93 module type FILLBUF =
94 sig
95 type t
96 val get : t -> int -> char
97 val set : t -> int -> char -> unit
98 end
99
100 module FillbufF :
101 functor (S : FILLBUF) ->
102 sig
103 val lei32 : S.t -> int -> int -> unit
104 val bei32 : S.t -> int -> int -> unit
105 val led : S.t -> int -> float -> unit
106 val bed : S.t -> int -> float -> unit
107 val lei32l : S.t -> int -> int32 -> unit
108 val bei32l : S.t -> int -> int32 -> unit
109 val lei64L : S.t -> int -> int64 -> unit
110 val bei64L : S.t -> int -> int64 -> unit
111 val ldi32 : S.t -> int -> int
112 val bdi32 : S.t -> int -> int
113 val ldi32l : S.t -> int -> int32
114 val bdi32l : S.t -> int -> int32
115 val ldi64L : S.t -> int -> int64
116 val bdi64L : S.t -> int -> int64
117 val ldd : S.t -> int -> float
118 val bdd : S.t -> int -> float
119 end
120
121 module FillbufString :
122 sig
123 val lei32 : string -> int -> int -> unit
124 val bei32 : string -> int -> int -> unit
125 val led : string -> int -> float -> unit
126 val bed : string -> int -> float -> unit
127 val lei32l : string -> int -> int32 -> unit
128 val bei32l : string -> int -> int32 -> unit
129 val lei64L : string -> int -> int64 -> unit
130 val bei64L : string -> int -> int64 -> unit
131 val ldi32 : string -> int -> int
132 val bdi32 : string -> int -> int
133 val ldi32l : string -> int -> int32
134 val bdi32l : string -> int -> int32
135 val ldi64L : string -> int -> int64
136 val bdi64L : string -> int -> int64
137 val ldd : string -> int -> float
138 val bdd : string -> int -> float
139 end
140
141 val add_le_int32 : Buf.buf -> int -> unit
142 val add_be_int32 : Buf.buf -> int -> unit
143 val add_le_d : Buf.buf -> float -> unit
144 val add_be_d : Buf.buf -> float -> unit
145 val add_le_int32l : Buf.buf -> int32 -> unit
146 val add_be_int32l : Buf.buf -> int32 -> unit
147 val add_le_int64L : Buf.buf -> int64 -> unit
148 val add_be_int64L : Buf.buf -> int64 -> unit
149
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
150 module S : S_sig with type t = string
151 module SS : S_sig with type t = BaseStringSlice.t
152
153 val el_eoo : char
154 val el_double : char
155 val el_string : char
156 val el_object : char
157 val el_array : char
158 val el_bindata : char
159 val el_undefined : char
160 val el_oid : char
161 val el_bool : char
162 val el_date : char
163 val el_null : char
f13de22 @nrs135 [fix] stdlib: Added missing minkey and maxkey elements.
nrs135 authored
164 val el_minkey : char
165 val el_maxkey : char
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
166 val el_regex : char
167 val el_dbref : char
168 val el_code : char
169 val el_symbol : char
170 val el_codewscope : char
171 val el_int : char
172 val el_timestamp : char
173 val el_long : char
174 val el_minkey : char
175 val el_maxkey : char
176 val st_bin_binary : char
177 val st_bin_func : char
178 val st_bin_binary_old : char
179 val st_bin_uuid : char
180 val st_bin_md5 : char
181 val st_bin_user : char
182
183 type buf = {
68933f7 @nrs135 [feature] mongo: Partial version of mongo wire protocol.
nrs135 authored
184 buf : Buf.buf;
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
185 mutable stack : int list;
186 mutable finished : bool;
187 }
188
189 module Oid :
190 sig
191 val from_string : string -> S.t
192 val to_string : string -> S.t
193 val counter : int ref
194 val gen : unit -> S.t
195 val generated_time : S.t -> Time.t
196 end
197
198 module Append :
199 sig
200 val init : ?hint:int -> unit -> buf
201 val empty : buf
202 val size : buf -> int
68933f7 @nrs135 [feature] mongo: Partial version of mongo wire protocol.
nrs135 authored
203 val estart : buf -> char -> S.t -> unit
c7ab5eb @nrs135 [fix] stdlib: Fixed some rpoblems with ints. Added overflow checking.
nrs135 authored
204 val int : buf -> S.t -> int32 -> unit
efc8fad @nrs135 [fix] stdlib: Sanitized low-level MongoDB code for 32-bit.
nrs135 authored
205 val long : buf -> S.t -> int64 -> unit
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
206 val double : buf -> S.t -> float -> unit
207 val bool : buf -> S.t -> bool -> unit
208 val null : buf -> S.t -> unit
f13de22 @nrs135 [fix] stdlib: Added missing minkey and maxkey elements.
nrs135 authored
209 val minkey : buf -> S.t -> unit
210 val maxkey : buf -> S.t -> unit
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
211 val undefined : buf -> S.t -> unit
212 val string_base : buf -> S.t -> S.t -> int -> char -> unit
213 val string : buf -> S.t -> S.t -> unit
214 val symbol : buf -> S.t -> S.t -> unit
215 val code : buf -> S.t -> S.t -> unit
216 val string_n : buf -> S.t -> S.t -> int -> unit
217 val symbol_n : buf -> S.t -> S.t -> int -> unit
218 val code_n : buf -> S.t -> S.t -> int -> unit
219 val code_w_scope_n : buf -> S.t -> S.t -> int -> buf -> unit
220 val code_w_scope : buf -> S.t -> S.t -> buf -> unit
221 val start_codewscope : buf -> S.t -> S.t -> unit
222 val finish_codewscope : buf -> S.t -> unit
223 val binary : buf -> S.t -> char -> S.t -> int -> unit
224 val oid : buf -> S.t -> S.t -> unit
225 val new_oid : buf -> S.t -> unit
226 val regex : buf -> S.t -> S.t -> S.t -> unit
227 val bson : buf -> S.t -> buf -> unit
c7ab5eb @nrs135 [fix] stdlib: Fixed some rpoblems with ints. Added overflow checking.
nrs135 authored
228 val timestamp : buf -> S.t -> int32 * int32 -> unit
efc8fad @nrs135 [fix] stdlib: Sanitized low-level MongoDB code for 32-bit.
nrs135 authored
229 val date : buf -> S.t -> int64 -> unit
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
230 val time_t : buf -> S.t -> Time.t -> unit
231 val start_object : buf -> S.t -> unit
232 val start_array : buf -> S.t -> unit
233 val finish_object : buf -> unit
234 val finish_array : buf -> unit
235 val finish : buf -> unit
236 val get : buf -> S.t
237 end
238
239 module type Iterator_sig =
240 sig
241 module S : S_sig
68933f7 @nrs135 [feature] mongo: Partial version of mongo wire protocol.
nrs135 authored
242 type iter = { ibuf : S.t; mutable pos : int; mutable first : bool; }
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
243 val init : buf -> iter
244 val from_buffer : S.t -> iter
245 val iterator_type : iter -> char
10c2eee @nrs135 [feature] libbase: Converted generated values to string in Bson.Iter…
nrs135 authored
246 val key : iter -> string
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
247 val value : iter -> int
c7ab5eb @nrs135 [fix] stdlib: Fixed some rpoblems with ints. Added overflow checking.
nrs135 authored
248 val int_raw : iter -> int32
efc8fad @nrs135 [fix] stdlib: Sanitized low-level MongoDB code for 32-bit.
nrs135 authored
249 val long_raw : iter -> int64
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
250 val double_raw : iter -> float
251 val bool_raw : iter -> bool
10c2eee @nrs135 [feature] libbase: Converted generated values to string in Bson.Iter…
nrs135 authored
252 val oid : iter -> string
253 val string : ?offset:int -> iter -> string
254 val symbol : ?offset:int -> iter -> string
255 val cstring : ?offset:int -> iter -> string
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
256 val string_len : iter -> int
c7ab5eb @nrs135 [fix] stdlib: Fixed some rpoblems with ints. Added overflow checking.
nrs135 authored
257 val int : iter -> int32
efc8fad @nrs135 [fix] stdlib: Sanitized low-level MongoDB code for 32-bit.
nrs135 authored
258 val long : iter -> int64
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
259 val double : iter -> float
c7ab5eb @nrs135 [fix] stdlib: Fixed some rpoblems with ints. Added overflow checking.
nrs135 authored
260 val timestamp : iter -> int32 * int32
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
261 val bool : iter -> bool
10c2eee @nrs135 [feature] libbase: Converted generated values to string in Bson.Iter…
nrs135 authored
262 val code : iter -> string
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
263 val code_scope : iter -> buf
efc8fad @nrs135 [fix] stdlib: Sanitized low-level MongoDB code for 32-bit.
nrs135 authored
264 val date : iter -> int64
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
265 val time_t : iter -> Time.t
266 val bin_type : iter -> char
267 val bin_len : iter -> int
10c2eee @nrs135 [feature] libbase: Converted generated values to string in Bson.Iter…
nrs135 authored
268 val bin_data : iter -> string
269 val regex : iter -> string
270 val regex_opts : iter -> string
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
271 val subobject : iter -> buf
272 val subiterator : iter -> iter
273 val next : iter -> char
10c2eee @nrs135 [feature] libbase: Converted generated values to string in Bson.Iter…
nrs135 authored
274 val find : buf -> string -> iter * char
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
275 end
276
277 module IteratorF(S : S_sig) : Iterator_sig with module S = S
278 module Iterator : Iterator_sig with module S = S
279 module IteratorSS : Iterator_sig with module S = SS
280
68933f7 @nrs135 [feature] mongo: Partial version of mongo wire protocol.
nrs135 authored
281 (*module Element :
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
282 sig
283 val element : buf -> S.t option -> Iterator.iter -> unit
68933f7 @nrs135 [feature] mongo: Partial version of mongo wire protocol.
nrs135 authored
284 end*)
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
285
286 module Print :
287 sig
288 val print : buf -> unit
289 val print_raw : S.t -> int -> int -> unit
d0d36b7 @nrs135 [feature] stdlib: Added logging functions to low-level mongo driver …
nrs135 authored
290 val to_pretty : buf -> string
291 val to_pretty_raw : S.t -> int -> string
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
292 end
293
Something went wrong with that request. Please try again.