protobuf-native (hackage):   protobuf-native uses the code generated from protobuf for C++ in Haskell.    [Index]  Package maintainers  For package maintainers and hackage trustees  Candidates    protobuf-native uses the code generated from protobuf for C++ in Haskell to go between Haskell and protobuf data structures.  It makes use of Template Haskell to assist in generating the interface between protobuf and your data structures.  Objects have finalizers so you never need to worry about memory management.  protobuf is a Template Haskell splice that takes the file path to a compiled protobuf object file and the name of the data type you want to build bindings to.  The data type must:  For example, if we have a Person protobuf structure in the file person.proto:  First we run protoc --cpp_out=. person.proto then compile the person.pb.cc file. Unfortunately, at this point, you need to mangle the C++ header file as per the Protobuf Mangling Guide below, ideally this would be automated. Do not re-run protoc unless you want to re-mangle the file. Always check these files in to source control.  Then we can write two Haskell data structures to represent these types:  If you get any of this wrong, you will get a compiler error.  Note that NameT is the type of the name field in PersonT. With data kinds you may get confusing error messages here.  Now we can:  The C++ are ForeignPtrs with finalizers, so you do not need to free anything.  Working with Cabal requires extra build steps. See this project's Setup.hs for an example on how to run protoc and clang++ in the build phase.  The property above is used by QuickCheck to test the library works. The tests are located in tests/Tests.hs. Namely, for all types in Protobuf the following property holds:  By profiling the tests you can verify the library does not leak memory.  This is a temporary measure until we make a post-processor for protobuf header files.  This is an inline function that must be un-inlined.  Go to the header file and search for that function name (in this case clear_firstname). You will find two occurances:  Remove the inline from both of these.  Go to the header file and find set_lastname and remove the inline. It may also look like an field name, such as:  Remove the inline from:  When dealing with a string setter, you only need to un-inline the std::string function. I.e.  This is currently another work around that is fixable.  If your problem has performance constraints you may want to consider using this library. When working with large protobuf files, you may want to write file iterators / network operations in C++ and process the data in Haskell. This library lets you only pay for converting the parts of the data structure you need. You can, for example, iterate over a large file 20 elements at a time and only pull out the components of the protobuf structure you need to pass to Haskell.
Keywords: bsd3|data|library|program