Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Unpacking byte stream long/quad little/big endian fields

by salva (Canon)
on Jan 22, 2021 at 08:22 UTC ( #11127261=note: print w/replies, xml ) Need Help??

in reply to Unpacking byte stream long/quad little/big endian fields

I faced a similar problem while writting Net::SFTP::Foreign.

My solution was to create a set of functions which pop the data from the buffer, allowing me to write code as the following:

my $buffer = read ...; my $len = get_int32($buffer); my $cmd = get_int8($buffer); my $txt = get_string($buffer);
This is the module implementing those functions: Net::SFTP::Foreign::Buffer.

Replies are listed 'Best First'.
Re^2: Unpacking byte stream long/quad little/big endian fields
by GrandFather (Saint) on Jan 22, 2021 at 08:32 UTC

    Sure, that's essentially what I'm doing too. But sometimes people peek under the hood, and I'd like it sparking under there too.

    Tux's answer provides a nice solution for Perl >= 5.10 and that's probably what I'll run with. 5.10 has been around long enough now that I'm not much worried about supporting anything earlier.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11127261]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2022-09-27 04:26 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (118 votes). Check out past polls.