How to serialize / deserialize objects sent over the network in Haskell?

I see that there are many ways to serialize / deserialize Haskell objects:

In my application, I want to configure a simple TCP client server where the client can send serial objects to a Haskell record. How do you decide between these serialization alternatives?

In addition, when objects serialized into strings are sent over the network using Network.Socket , strings are returned. Is there a higher level library that works at the level of whole TCP messages? In other words, is there a way to avoid writing parsing code at the end of the receive, which:

  • collects the results of a recv () call sequence,
  • detects that the entire object is received, and
  • then parse it for haskell type?

In my application, the objects should not be too large (maybe about ~ 1 MB max.).

+4
source share
2 answers

Regarding the second part of your question, two things are required:

  • , , , , . , , " " .

  • "pushback", " " , .

, (1), attoparsec. (2), (conduit, io-streams pipes) pushback ( pipes-parse). attoparsec (. , ).

( , , , .)

+1

( ), , , , . (1MB) , , - . , cereal, , , . (http://hackage.haskell.org/package/aeson-0.8.0.2/docs/Data-Aeson.html), GHC Generics, - :

data Shape = Rect Int Int | Circle Double | Other String Int
  deriving (Generic)
instance FromJSON Shape  -- uses a default
instance ToJSON Shape    -- uses a default

, bam!, encode decode. TCP . , - .

+1
source

All Articles