Data.Binary.GetT or ... ?

Hello, I'm thinking about using Data.Binary to parse binary stream of data. Binary data stream consists of messages which can have one or more (sometimes couple of hundreds) sub-messages. The stream is spitting out data slowly. I would like to parse this data with Data.Binary.Get monad, but I would like to send sub-messages to a STM channel while parsing, so "observers" could handle them during parsing process. I believe I could achieve this with a Data.Binary.GetT transformer, but I'm not aware it exists. Implementing GetT would take me a huge amount of time (I'm not that good haskeller). Splitting processing to message level and sub-message level and handling them by two separate "get"s in IO monad is a possibility, but not really appealing one (at least to me). Is there another (preferably cheap) way of doing what I want? Thanks, Juraj

On 13/03/10 10:06, Juraj Hercek wrote:
Hello,
I'm thinking about using Data.Binary to parse binary stream of data. Binary data stream consists of messages which can have one or more (sometimes couple of hundreds) sub-messages. The stream is spitting out data slowly.
I would like to parse this data with Data.Binary.Get monad, but I would like to send sub-messages to a STM channel while parsing, so "observers" could handle them during parsing process.
I think you could do this by having your top-level Get action return a list of IO actions, like this: bigGet :: Get ([IO ()]) Then arrange for the parser for each smaller sub-message to return the corresponding action. In this case these actions will be calls to "atomic" to run the appropriate STM action. The trick is in lazyness: the lazy bytestring is read as it comes in, and hence is translated to a lazy list of IO actions, which are also executed as they come in. Hope this helps, Paul.

On 03/13/2010 12:35 PM, Paul Johnson wrote:
On 13/03/10 10:06, Juraj Hercek wrote:
Hello,
I'm thinking about using Data.Binary to parse binary stream of data. Binary data stream consists of messages which can have one or more (sometimes couple of hundreds) sub-messages. The stream is spitting out data slowly.
I would like to parse this data with Data.Binary.Get monad, but I would like to send sub-messages to a STM channel while parsing, so "observers" could handle them during parsing process.
I think you could do this by having your top-level Get action return a list of IO actions, like this:
bigGet :: Get ([IO ()])
Then arrange for the parser for each smaller sub-message to return the corresponding action. In this case these actions will be calls to "atomic" to run the appropriate STM action.
The trick is in lazyness: the lazy bytestring is read as it comes in, and hence is translated to a lazy list of IO actions, which are also executed as they come in.
That's neat idea. I'll try it and see how it behaves. Thanks, Juraj
participants (2)
-
Juraj Hercek
-
Paul Johnson