1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556(************************************************************************)(* The λΠ-modulo Interactive Proof Assistant *)(************************************************************************)(************************************************************************)(* λΠ-modulo serialization Toplevel *)(* Copyright 2018 MINES ParisTech -- Dual License LGPL 2.1 / GPL3+ *)(* Written by: Emilio J. Gallego Arias *)(************************************************************************)(* Status: Very Experimental *)(************************************************************************)moduleF=FormatmoduleJ=Yojson.Basicletdebug_fmt=refF.err_formatterletlog_errorhdrmsg=F.fprintf!debug_fmt"[%s]: @[%s@]@\n%!"hdrmsgletlog_objecthdrobj=F.fprintf!debug_fmt"[%s]: @[%a@]@\n%!"hdrJ.(pretty_print~std:false)objexceptionReadErrorofstringletread_requestic=letcl=input_lineicinletsin=Scanf.Scanning.from_stringclintryletraw_obj=Scanf.bscanfsin"Content-Length: %d\r"(funsize->letbuf=Bytes.createsizein(* Consume the second \r\n *)let_=input_lineicinreally_inputicbuf0size;Bytes.to_stringbuf)inJ.from_stringraw_objwith(* if the end of input is encountered while some more characters are needed
to read the current conversion specification. *)|End_of_file->raise(ReadError"EOF")(* if the input does not match the format. *)|Scanf.Scan_failuremsg(* if a conversion to a number is not possible. *)|Failuremsg(* if the format string is invalid. *)|Invalid_argumentmsg->raise(ReadErrormsg)letsend_jsonfmtobj=log_object"send"obj;letmsg=F.asprintf"%a"J.(pretty_print~std:true)objinletsize=String.lengthmsginF.fprintffmt"Content-Length: %d\r\n\r\n%s%!"sizemsg