From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 1D9F5BC57 for ; Tue, 8 Jun 2010 21:10:29 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlIBAN8yDkzVhjEYkGdsb2JhbACDHps5AQEBAQkJDAcRAx+uXpBzgSaDAm4E X-IronPort-AV: E=Sophos;i="4.53,385,1272837600"; d="scan'208";a="52695222" Received: from ihsmtp02voda.lis.interhost.com (HELO ihsmtp02cons.lis.interhost.com) ([213.134.49.24]) by mail2-smtp-roc.national.inria.fr with ESMTP; 08 Jun 2010 21:10:28 +0200 Received: from [192.168.1.64] ([95.136.106.136]) by ihsmtp02cons.lis.interhost.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 8 Jun 2010 20:10:28 +0100 Message-ID: <4C0E95A4.1050103@inescporto.pt> Date: Tue, 08 Jun 2010 20:10:28 +0100 From: Hugo Ferreira User-Agent: Thunderbird 2.0.0.24 (X11/20100317) MIME-Version: 1.0 To: Paolo Donadeo Cc: caml-list caml-list Subject: Re: [Caml-list] Escaped string in sexplib References: <4C0E6561.20207@inescporto.pt> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 08 Jun 2010 19:10:28.0822 (UTC) FILETIME=[4214D760:01CB073E] X-Spam: no; 0.00; sig:01 val:01 val:01 struct:01 sexp:01 sexp:01 blog:98 blog:98 wrote:01 cryptokit:01 cryptokit:01 encode:01 encode:01 caml-list:01 functions:01 Hi Paolo, Paolo Donadeo wrote: > I'm using Sexplib to store and retrieve the sessions of a web > application into a data base. A "session" has this signature: > > module type SESSION_DATA = > sig > type t > val default : t > val string_of_t : t -> string (* Is this what you want? *) > val t_of_string : string -> t (* Is this what you want? *) > end > > and the concrete session, which is a blog session, is: > > module Blog_session = > struct > type user = > { > email : string; > passwd : string; > first_name : string option; > last_name : string option; > displ_name : string option; > website : string option > } with sexp > > type t = > | Anonymous > | Logged of user > with sexp > > let default = Anonymous > > let string_of_t = sexp_of_t |- Sexplib.Sexp.to_string_hum |- hex_encode > > let t_of_string s = > try s |> hex_decode |> Sexplib.Sexp.of_string |> t_of_sexp > with Sexplib.Conv.Of_sexp_error (_, _) -> default > end > My be a solution. Going to see if I can find an alternate implementation of hex encoding so as not to require another library. Thanks, Hugo F. > Functions "hex_encode" and "hex_decode" are trivially implemented > using Cryptokit: > > let hex_encode = Cryptokit.transform_string (Cryptokit.Hexa.encode ()) > let hex_decode = Cryptokit.transform_string (Cryptokit.Hexa.decode ()) > > The operators (|-) and (|>) are defined as always: > > http://thelema.github.com/batteries-included/hdoc/BatPervasives.html#6_Fundamentalfunctionsandoperators > > > Hope this helps, > >