Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2021-04-23 16:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?