codec-libevent-0.1: Cross-platform structure serialisation



This module generates Haskell code for serialising and deserialising libevent tagged data structures, as implemented in libevent-1.4.0-beta.

A single .rpc file (containing one or more structures) is mapped to a single Haskell file. Take this example:

 struct test {
   required int a = 1;
   optional string b = 2;
   repeated struct[test2] c = 3;

This will result in a data decl for Test, having named members: test_a, test_b and test_c. Required elements are simple, optional elements are wrapped in a Maybe and repeated elements in a list.

Types are mapped thus:

  • int -> Word32
  • string -> String
  • bytes -> ByteString (strict)
  • bytes[n] -> ByteString (with runtime checks on the size)
  • struct[name] -> Name (the struct must be defined in the same file)

In the example above, test2 is required to be in the same .rpc file.

For a structure named test, the following would also be generated:

  • testEmpty - a Test filled with default values
  • testDeserialise - a strict Get instance to deserialise a test. Note that these structures are self-deliminating, so additional garbage at the end will be consumed and will probably result in an error
  • testDeserialiseBS - a function with type ByteString -> Either String Test where the String is an error message
  • testSerialise - a Put Test function. Again, recall that these structures aren't self deliminating
  • testSerialiseBS - a function with type Test -> ByteString

Each structure will also be an instance of the TaggedStructure class that you can find in Codec.Libevent.Class





:: String

the name of the module in the output

-> RPCFile

the RPC file to generate code for

-> IO () 

Generate the Haskell code for the given RPC file and write to standard out. The generated module will export everything and takes the given name