Commit 47a232fe authored by Stephane Glondu's avatar Stephane Glondu

Serialization of string sets

parent 26f67a28
......@@ -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)
......@@ -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
Serializable_builtin_t
Serializable_builtin_j
Serializable_t
Serializable_j
......
......@@ -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
......@@ -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
(**************************************************************************)
(* 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
......@@ -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
Serializable_builtin_t
Serializable_builtin_j
Serializable_j
Common
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment