mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 19:25:28 -05:00
easier to use interface for Bij.Sexpr
This commit is contained in:
parent
a570a34951
commit
1e72332ac6
2 changed files with 19 additions and 5 deletions
12
bij.ml
12
bij.ml
|
|
@ -395,11 +395,19 @@ module SexpStr = struct
|
||||||
module SexpEncodeBuf = SexpEncode(SinkBuf)
|
module SexpEncodeBuf = SexpEncode(SinkBuf)
|
||||||
module SexpDecodeString = SexpDecode(SourceStr)
|
module SexpDecodeString = SexpDecode(SourceStr)
|
||||||
|
|
||||||
let to_string ~bij x =
|
let to_string ?(bufsize=64) ~bij x =
|
||||||
let b = Buffer.create 15 in
|
let b = Buffer.create bufsize in
|
||||||
SexpEncodeBuf.encode ~bij b x;
|
SexpEncodeBuf.encode ~bij b x;
|
||||||
Buffer.contents b
|
Buffer.contents b
|
||||||
|
|
||||||
let of_string ~bij s =
|
let of_string ~bij s =
|
||||||
SexpDecodeString.decode ~bij (SourceStr.create s)
|
SexpDecodeString.decode ~bij (SourceStr.create s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module SexpChan = struct
|
||||||
|
module SexpEncodeChan = SexpEncode(SinkChan)
|
||||||
|
module SexpDecodeChan = SexpDecode(SourceChan)
|
||||||
|
|
||||||
|
include SexpEncodeChan
|
||||||
|
include SexpDecodeChan
|
||||||
|
end
|
||||||
|
|
|
||||||
12
bij.mli
12
bij.mli
|
|
@ -94,9 +94,9 @@ module type SINK = sig
|
||||||
val write_float : t -> float -> unit
|
val write_float : t -> float -> unit
|
||||||
end
|
end
|
||||||
|
|
||||||
module SinkBuf : SINK with type t := Buffer.t
|
module SinkBuf : SINK with type t = Buffer.t
|
||||||
|
|
||||||
module SinkChan : SINK with type t := out_channel
|
module SinkChan : SINK with type t = out_channel
|
||||||
|
|
||||||
(** {2 Encoding/decoding} *)
|
(** {2 Encoding/decoding} *)
|
||||||
|
|
||||||
|
|
@ -115,6 +115,12 @@ module SexpDecode(Source : SOURCE) : DECODE with type source = Source.t
|
||||||
|
|
||||||
(** Specific instance for encoding to/from strings *)
|
(** Specific instance for encoding to/from strings *)
|
||||||
module SexpStr : sig
|
module SexpStr : sig
|
||||||
val to_string : bij:'a t -> 'a -> string
|
val to_string : ?bufsize:int -> bij:'a t -> 'a -> string
|
||||||
val of_string : bij:'a t -> string -> 'a
|
val of_string : bij:'a t -> string -> 'a
|
||||||
end
|
end
|
||||||
|
|
||||||
|
(** Specific instance for encoding to/from channels *)
|
||||||
|
module SexpChan : sig
|
||||||
|
include ENCODE with type sink = SinkChan.t
|
||||||
|
include DECODE with type source = SourceChan.t
|
||||||
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue