bert

BERT implementation https://github.com/feuerbach/bert

Latest on Hackage:1.2.2.5

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

BSD3 licensed by marius a. eriksen, Roman Cheplyaka
Maintained by Roman Cheplyaka

BERT[-RPC] for Haskell

Originally written by marius a. eriksen (marius@monkey.org)

This is a BERT serializer/deserializer and BERT-RPC client and server for Haskell. BERT-RPC currently supports synchronous (call) requests.

The primitives provided are fairly elementary: for the client, call provides the capability to perform the RPC call, while the server's serve is provided with a dispatch function providing the dispatching logic for the server. Thus, one can imagine building higher level abstractions on top of these primitives.

Installation

It's a cabal package, so

$ cabal install bert

should do the trick.

BERT

import qualified Data.ByteString.Lazy.Char8 as C
import Data.BERT

Creating BERT terms is simple.

TupleTerm [BytelistTerm (C.pack "hello"), IntTerm 123]

Or by using the BERT typeclass.

showBERT $ ("hello", 123)

The BERT class can also read terms back.

Right ("hello", 123) = readBERT . showBERT $ ("hello", 123)

BERT-RPC client

import Data.BERT
import Network.BERT.Client

Create a transport to the server endpoint, and issue a (synchronous) call with it.

t <- tcpClient "localhost" 8080
r <- call t "calc" "add" ([123, 3000]::[Int])
case r of
  Right res -> print (res :: Int)
  Left _    -> putStrLn "error"

BERT-RPC server

import Data.BERT
import Network.BERT.Server

Create a transport from which to accept connections, and provide a dispatch function for incoming RPCs. The dispatch function is issued in a new thread for each incoming request.

main = do
  s <- tcpServer 8080
  serve s dispatch

dispatch "calc" "add" [IntTerm a, IntTerm b] = 
  return $ Success $ IntTerm (a + b)
dispatch "calc" _ _ =
  return NoSuchFunction
dispatch _ _ _ = 
  return NoSuchModule

Maintainers

Roman Cheplyaka is the primary maintainer.

Oleksandr Manzyuk is the backup maintainer. Please get in touch with him if the primary maintainer cannot be reached.

Changes

Version 1.2.2.5

  • Fix a list deserialization bug
  • Serialize small ints compactly

Version 1.2.2.4

Fix compatibility with GHC 7.10

Version 1.2.2.3

Fix compatibility with recent conduit.

Version 1.2.2.2

Migrate from network-conduit (which is deprecated) to conduit-extra

Version 1.2.2.1

Fix build on GHC 7.4

Version 1.2.2

  • Show and Read instances for Term now use Haskell, not Erlang syntax. To get the Erlang-syntax-formatted terms, showTerm and parseTerm are now exposed.

Version 1.2.1.2

  • Fix Windows compatibility

Version 1.2.1.1

  • Fix integer (de)serialization on 64-bit platforms

Version 1.2.1

  • Fix the docs
  • Export the Error data type

Version 1.2

  • Drop the bert command-line tool
  • Remove support for the (non-standard) bert:// URI
  • Change the way transports are represented
  • Instead of fromURI or fromHostPort, you should now use tcpClient and tcpServer
  • Both the client and the server now support persistent connections
  • The default TCP backlog is increased for the server
comments powered byDisqus