From 1e72332ac6024187b10f6945dbb5f1cc6a2336a1 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 15 May 2013 11:23:32 +0200 Subject: [PATCH] easier to use interface for Bij.Sexpr --- bij.ml | 12 ++++++++++-- bij.mli | 12 +++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/bij.ml b/bij.ml index eaf37007..6bf1eb4c 100644 --- a/bij.ml +++ b/bij.ml @@ -395,11 +395,19 @@ module SexpStr = struct module SexpEncodeBuf = SexpEncode(SinkBuf) module SexpDecodeString = SexpDecode(SourceStr) - let to_string ~bij x = - let b = Buffer.create 15 in + let to_string ?(bufsize=64) ~bij x = + let b = Buffer.create bufsize in SexpEncodeBuf.encode ~bij b x; Buffer.contents b let of_string ~bij s = SexpDecodeString.decode ~bij (SourceStr.create s) end + +module SexpChan = struct + module SexpEncodeChan = SexpEncode(SinkChan) + module SexpDecodeChan = SexpDecode(SourceChan) + + include SexpEncodeChan + include SexpDecodeChan +end diff --git a/bij.mli b/bij.mli index cb09f82b..14a4cda9 100644 --- a/bij.mli +++ b/bij.mli @@ -94,9 +94,9 @@ module type SINK = sig val write_float : t -> float -> unit 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} *) @@ -115,6 +115,12 @@ module SexpDecode(Source : SOURCE) : DECODE with type source = Source.t (** Specific instance for encoding to/from strings *) 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 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