Does Raku have a similar function to Python's Struct?

Viewed 179

Unpacking binary data in Python:

import struct

bytesarray = "01234567".encode('utf-8')
# Return a new Struct object which writes and reads binary data according to the format string. 
s = struct.Struct('=BI3s')
s = s.unpack(bytesarray) # Output: (48, 875770417, b'567')

Does Raku have a similar function to Python's Struct? How can I unpack binary data according to a format string in Raku?

1 Answers

There's the experimental unpack

use experimental :pack;

my $bytearray = "01234567".encode('utf-8');

say $bytearray.unpack("A1 L H"); 

It's not exactly the same, though; this outputs "(0 875770417 35)". You can tweak your way through it a bit, maybe.

There's also an implementation of Perl's pack / unpack in P5pack

Related