Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Dealing with binary data
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
====Incremental parsing==== If you have to deal with a protocol which isn't length prefixed, or otherwise chunkable, from the network then you are faced with the problem of knowing when you have enough data to parse something semantically useful. You could run a strict <tt>Get</tt> over what you have and catch the truncation result, but that means that you're parsing the data multiple times etc. Instead, you can use an incremental parser. There's an incremental version of the <tt>Get</tt> monad in <tt>Data.Binary.Strict.IncrementalGet</tt> (you'll need the <tt>binary-strict</tt> package). You use it as normal, but rather than returning an <tt>Either</tt> value, you get a [http://hackage.haskell.org/package/binary-strict/docs/Data-Binary-Strict-IncrementalGet.html#t%3AResult Result]. You need to go follow that link and look at the documentation for <tt>Result</tt>. It reflects the three outcomes of parsing possibly truncated data. Either the data is invalid as is, or it's complete, or it's truncated. In the truncated case you are given a function (called a continuation), to which you can pass more data, when you get it, and continue the parse. The continuation, again, returns a <tt>Result</tt> depending on the result of parsing the additional data as well.
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width