Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 235 lines (212 sloc) 7.063 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
f13de22 @nrs135 [fix] stdlib: Added missing minkey and maxkey elements.
nrs135 authored
107 val el_minkey : char
108 val el_maxkey : char
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
109 val el_regex : char
110 val el_dbref : char
111 val el_code : char
112 val el_symbol : char
113 val el_codewscope : char
114 val el_int : char
115 val el_timestamp : char
116 val el_long : char
117 val el_minkey : char
118 val el_maxkey : char
119 val st_bin_binary : char
120 val st_bin_func : char
121 val st_bin_binary_old : char
122 val st_bin_uuid : char
123 val st_bin_md5 : char
124 val st_bin_user : char
125
126 type buf = {
68933f7 @nrs135 [feature] mongo: Partial version of mongo wire protocol.
nrs135 authored
127 buf : Buf.buf;
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
128 mutable stack : int list;
129 mutable finished : bool;
130 }
131
132 module Oid :
133 sig
134 val from_string : string -> S.t
135 val to_string : string -> S.t
136 val counter : int ref
137 val gen : unit -> S.t
138 val generated_time : S.t -> Time.t
139 end
140
141 module Append :
142 sig
143 val init : ?hint:int -> unit -> buf
144 val empty : buf
145 val size : buf -> int
68933f7 @nrs135 [feature] mongo: Partial version of mongo wire protocol.
nrs135 authored
146 val estart : buf -> char -> S.t -> unit
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
147 val int : buf -> S.t -> int -> unit
148 val long : buf -> S.t -> int -> unit
149 val double : buf -> S.t -> float -> unit
150 val bool : buf -> S.t -> bool -> unit
151 val null : buf -> S.t -> unit
f13de22 @nrs135 [fix] stdlib: Added missing minkey and maxkey elements.
nrs135 authored
152 val minkey : buf -> S.t -> unit
153 val maxkey : buf -> S.t -> unit
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
154 val undefined : buf -> S.t -> unit
155 val string_base : buf -> S.t -> S.t -> int -> char -> unit
156 val string : buf -> S.t -> S.t -> unit
157 val symbol : buf -> S.t -> S.t -> unit
158 val code : buf -> S.t -> S.t -> unit
159 val string_n : buf -> S.t -> S.t -> int -> unit
160 val symbol_n : buf -> S.t -> S.t -> int -> unit
161 val code_n : buf -> S.t -> S.t -> int -> unit
162 val code_w_scope_n : buf -> S.t -> S.t -> int -> buf -> unit
163 val code_w_scope : buf -> S.t -> S.t -> buf -> unit
164 val start_codewscope : buf -> S.t -> S.t -> unit
165 val finish_codewscope : buf -> S.t -> unit
166 val binary : buf -> S.t -> char -> S.t -> int -> unit
167 val oid : buf -> S.t -> S.t -> unit
168 val new_oid : buf -> S.t -> unit
169 val regex : buf -> S.t -> S.t -> S.t -> unit
170 val bson : buf -> S.t -> buf -> unit
171 val timestamp : buf -> S.t -> int * int -> unit
172 val date : buf -> S.t -> int -> unit
173 val time_t : buf -> S.t -> Time.t -> unit
174 val start_object : buf -> S.t -> unit
175 val start_array : buf -> S.t -> unit
176 val finish_object : buf -> unit
177 val finish_array : buf -> unit
178 val finish : buf -> unit
179 val get : buf -> S.t
180 end
181
182 module type Iterator_sig =
183 sig
184 module S : S_sig
68933f7 @nrs135 [feature] mongo: Partial version of mongo wire protocol.
nrs135 authored
185 type iter = { ibuf : S.t; mutable pos : int; mutable first : bool; }
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
186 val init : buf -> iter
187 val from_buffer : S.t -> iter
188 val iterator_type : iter -> char
10c2eee @nrs135 [feature] libbase: Converted generated values to string in Bson.Iter…
nrs135 authored
189 val key : iter -> string
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
190 val value : iter -> int
191 val int_raw : iter -> int
192 val long_raw : iter -> int
193 val double_raw : iter -> float
194 val bool_raw : iter -> bool
10c2eee @nrs135 [feature] libbase: Converted generated values to string in Bson.Iter…
nrs135 authored
195 val oid : iter -> string
196 val string : ?offset:int -> iter -> string
197 val symbol : ?offset:int -> iter -> string
198 val cstring : ?offset:int -> iter -> string
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
199 val string_len : iter -> int
200 val int : iter -> int
201 val long : iter -> int
202 val double : iter -> float
203 val timestamp : iter -> int * int
204 val bool : iter -> bool
10c2eee @nrs135 [feature] libbase: Converted generated values to string in Bson.Iter…
nrs135 authored
205 val code : iter -> string
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
206 val code_scope : iter -> buf
207 val date : iter -> int
208 val time_t : iter -> Time.t
209 val bin_type : iter -> char
210 val bin_len : iter -> int
10c2eee @nrs135 [feature] libbase: Converted generated values to string in Bson.Iter…
nrs135 authored
211 val bin_data : iter -> string
212 val regex : iter -> string
213 val regex_opts : iter -> string
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
214 val subobject : iter -> buf
215 val subiterator : iter -> iter
216 val next : iter -> char
10c2eee @nrs135 [feature] libbase: Converted generated values to string in Bson.Iter…
nrs135 authored
217 val find : buf -> string -> iter * char
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
218 end
219
220 module IteratorF(S : S_sig) : Iterator_sig with module S = S
221 module Iterator : Iterator_sig with module S = S
222 module IteratorSS : Iterator_sig with module S = SS
223
68933f7 @nrs135 [feature] mongo: Partial version of mongo wire protocol.
nrs135 authored
224 (*module Element :
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
225 sig
226 val element : buf -> S.t option -> Iterator.iter -> unit
68933f7 @nrs135 [feature] mongo: Partial version of mongo wire protocol.
nrs135 authored
227 end*)
cbec25f @nrs135 [feature] libbase: Added Bson module.
nrs135 authored
228
229 module Print :
230 sig
231 val print : buf -> unit
232 val print_raw : S.t -> int -> int -> unit
233 end
234
Something went wrong with that request. Please try again.