caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Romain Bardou <romain.bardou@inria.fr>
To: Kenichi Asai <asai@is.ocha.ac.jp>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Marshall.from_channel and segmentation fault
Date: Fri, 12 Jun 2015 10:55:22 +0200	[thread overview]
Message-ID: <557A9E7A.3010609@inria.fr> (raw)
In-Reply-To: <20150612082626.GA5884@pllab.is.ocha.ac.jp>

If the game is simple and values can easily be seen as sequences of char 
/ bytes, 32-bit integers and fixed-length strings, your students could 
code their own serialization functions using the following functions 
from the Pervasives module:
- output_char / input_char
- output_byte / input_byte
- output_binary_int / input_binary_int
- output_string / really_input_string
Serialization is an important part of network applications, so it may be 
an interesting skill for your students to learn.

If on the other hand you feel that it would make it too complicated, 
there are several libraries which allow some form of serialization. I'm 
actually not that familiar with them as I tend to write serialization 
functions myself, but you may take a look at bin_prot, sexplib, biniou, 
yojson, piqi...

Some of them use human-readable protocols such as JSON or s-expressions. 
They will be easier for your students to debug, but they are less 
efficient, which may be an issue for a game.

Some of them have syntax extensions to generate the serialization 
functions from the source code of the type you want to serialize. Those 
will be the easiest to use. But I believe they tend to confuse students 
a lot, as the language is no longer pure OCaml and the build system 
needs to become aware of the syntax extension.

Cheers,

-- Romain Bardou

On 12/06/2015 10:26, Kenichi Asai wrote:
> Dear Romain,
>
> Thanks for the explanation.  It seems you are suggesting that I should
> use something else that performs runtime type checking rather than the
> Marshall module.  Is there some standard module I can use?
>
> I want to send various data along the Unix socket to create
> interactive games using the Universe library for OCaml:
>
> http://pllab.is.ocha.ac.jp/~asai/Universe/
>
> Because the library is used by beginning students, I want to avoid
> segmentation fault without any useful error messages when they
> mistakenly use the sent data as having different types.
>
> Sincerely,
>


  reply	other threads:[~2015-06-12  8:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-12  5:27 Kenichi Asai
2015-06-12  7:39 ` Romain Bardou
2015-06-12  8:26   ` Kenichi Asai
2015-06-12  8:55     ` Romain Bardou [this message]
2015-06-12  8:41   ` Francois Berenger
2015-06-12  8:38 ` Francois Berenger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=557A9E7A.3010609@inria.fr \
    --to=romain.bardou@inria.fr \
    --cc=asai@is.ocha.ac.jp \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).