4 ms·
I like Perl's Data::ParseBinary (https://metacpan.org/pod/Data::ParseBinary https://metacpan.org/pod/Data::ParseBinary) my $s = Struct("foo", UBInt
by gabiruh 5y ago
I like Perl's Data::ParseBinary (https://metacpan.org/pod/Data::ParseBinary https://metacpan.org/pod/Data::ParseBinary)
my $s = Struct("foo",
UBInt8("a"),
UBInt16("b"),
Struct("bar",
UBInt8("a"),
UBInt16("b"),
)
);
my $data = $s->parse("ABBabb");
# $data is { a => 65, b => 16962, bar => { a => 97, b => 25186 } }
- matheusmoreira 5y agoHow does it handle length-prefixed data? length u32 data u32[length] This is a huge problem for traditional parsers since the input modifies the grammar dynamically.
- boardwaalk 5y agoIt’s right here: https://metacpan.org/pod/Data::ParseBinary#Meta-Primitives https://metacpan.org/pod/Data::ParseBinary#Meta-Primitives
- matheusmoreira 5y agoI see, you can pass in a function that computes the length. I wonder if a declarative or formal solution will ever exist.