Raku有没有和Python的Struct类似的功能?
Does Raku have a similar function to Python's Struct?
解压 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')
Raku有没有和Python的Struct类似的功能?如何根据 Raku 中的格式字符串解压二进制数据?
use experimental :pack;
my $bytearray = "01234567".encode('utf-8');
say $bytearray.unpack("A1 L H");
虽然不完全一样;这输出“(0 875770417 35)”。也许你可以稍微调整一下。
在 P5pack
中还有一个 Perl 的 pack
/ unpack
的实现
解压 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')
Raku有没有和Python的Struct类似的功能?如何根据 Raku 中的格式字符串解压二进制数据?
use experimental :pack;
my $bytearray = "01234567".encode('utf-8');
say $bytearray.unpack("A1 L H");
虽然不完全一样;这输出“(0 875770417 35)”。也许你可以稍微调整一下。
在 P5pack
中还有一个 Perl 的pack
/ unpack
的实现