Hi Paul.
Paul LeoNerd Evans wrote:
I find lately I've been doing a lot of binary protocol work, taking
messages that live in TCP streams or files or similar, and doing lots of
pack()/unpack() on them.
this strikes me as more than a little inelegant. That 4 floating about
there is a "magic" constant. Things like this get worse
( not every day I get to brag about my module, so please be patient... :-) )
How about my module, Data::ParseBinary? it gives you a lot of options.
If you are reading from a string, then you can use a string reader
stream, and it will remember the current location, so the next parse
will start from it.
If you have a "live" string, that you want to add binary data to the end
and delete from the beginning, you can use StringRef stream reader,
adding add new data to the end. For deleting data from the beginning,
you can ask where it is now ($stream->tell), substr from the beginning,
and then $stream->seek(0).
Or, if you are reading from the network, maybe you should just write a
custom network stream, and parse directly off it.
And finally, if you are reading from file, there is a File stream
reader, that does it for you.
Warning: if you are looking for performance, this module is the wrong one.
Shmuel.