Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
belenios
belenios
Commits
47a232fe
Commit
47a232fe
authored
Apr 03, 2014
by
Stephane Glondu
Browse files
Serialization of string sets
parent
26f67a28
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/lib/common.ml
View file @
47a232fe
...
...
@@ -196,5 +196,4 @@ let save_to filename writer x =
Bi_outbuf
.
flush_channel_writer
ob
;
close_out
oc
;;
module
SSet
=
Set
.
Make
(
String
)
module
SMap
=
Map
.
Make
(
String
)
src/lib/common.mli
View file @
47a232fe
...
...
@@ -63,5 +63,4 @@ val pbkdf2 :
val
save_to
:
string
->
(
Bi_outbuf
.
t
->
'
a
->
unit
)
->
'
a
->
unit
module
SSet
:
Set
.
S
with
type
elt
=
string
module
SMap
:
Map
.
S
with
type
key
=
string
src/lib/lib.mllib
View file @
47a232fe
Serializable_builtin_t
Serializable_builtin_j
Serializable_t
Serializable_j
...
...
src/lib/serializable_builtin_j.ml
View file @
47a232fe
...
...
@@ -129,3 +129,29 @@ let read_int_or_null state buf =
let
int_or_null_of_string
s
=
int_or_null_of_json
(
Yojson
.
Safe
.
from_string
s
)
(** {1 Serializers for type string_set} *)
let
write_string_set
buf
set
=
`List
(
SSet
.
elements
set
|>
List
.
map
(
fun
x
->
`String
x
))
|>
Yojson
.
Safe
.
to_outbuf
buf
let
string_of_string_set
?
(
len
=
100
)
set
=
let
buf
=
Bi_outbuf
.
create
len
in
write_string_set
buf
set
;
Bi_outbuf
.
contents
buf
let
string_set_of_json
=
function
|
`List
xs
->
List
.
fold_left
(
fun
accu
x
->
match
x
with
|
`String
y
->
SSet
.
add
y
accu
|
_
->
assert
false
)
SSet
.
empty
xs
|
_
->
assert
false
let
read_string_set
state
buf
=
Yojson
.
Safe
.
from_lexbuf
~
stream
:
true
state
buf
|>
string_set_of_json
let
string_set_of_string
s
=
Yojson
.
Safe
.
from_string
s
|>
string_set_of_json
src/lib/serializable_builtin_j.mli
View file @
47a232fe
...
...
@@ -48,3 +48,10 @@ val write_int_or_null : Bi_outbuf.t -> int_or_null -> unit
val
string_of_int_or_null
:
?
len
:
int
->
int_or_null
->
string
val
read_int_or_null
:
Yojson
.
Safe
.
lexer_state
->
Lexing
.
lexbuf
->
int_or_null
val
int_or_null_of_string
:
string
->
int_or_null
(** {1 Serializers for type string_set} *)
val
write_string_set
:
Bi_outbuf
.
t
->
string_set
->
unit
val
string_of_string_set
:
?
len
:
int
->
string_set
->
string
val
read_string_set
:
Yojson
.
Safe
.
lexer_state
->
Lexing
.
lexbuf
->
string_set
val
string_set_of_string
:
string
->
string_set
src/lib/serializable_builtin_t.ml
0 → 100644
View file @
47a232fe
(**************************************************************************)
(* BELENIOS *)
(* *)
(* Copyright © 2012-2014 Inria *)
(* *)
(* This program is free software: you can redistribute it and/or modify *)
(* it under the terms of the GNU Affero General Public License as *)
(* published by the Free Software Foundation, either version 3 of the *)
(* License, or (at your option) any later version, with the additional *)
(* exemption that compiling, linking, and/or using OpenSSL is allowed. *)
(* *)
(* This program is distributed in the hope that it will be useful, but *)
(* WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)
(* Affero General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Affero General Public *)
(* License along with this program. If not, see *)
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
type
number
=
Z
.
t
type
uuid
=
Uuidm
.
t
type
datetime
=
CalendarLib
.
Fcalendar
.
Precise
.
t
*
string
option
type
int_or_null
=
int
option
module
SSet
=
Set
.
Make
(
String
)
type
string_set
=
SSet
.
t
src/lib/serializable_builtin_t.mli
View file @
47a232fe
...
...
@@ -23,3 +23,7 @@ type number = Z.t
type
uuid
=
Uuidm
.
t
type
datetime
=
CalendarLib
.
Fcalendar
.
Precise
.
t
*
string
option
type
int_or_null
=
int
option
module
SSet
:
Set
.
S
with
type
elt
=
string
type
string_set
=
SSet
.
t
src/web/server.mllib
View file @
47a232fe
Serializable_builtin_t
Serializable_builtin_j
Serializable_j
Common
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment