使用 Perl6 语法解析二进制结构 [英] Parsing binary structure with Perl6 Grammar

查看:43
本文介绍了使用 Perl6 语法解析二进制结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Perl6 解析二进制结构的最佳选择是什么.

What is the best option to parse a binary structure with Perl6 .

在 Perl5 中,我们在 Perl6 上有打包/解包方法,它们似乎是实验性的

in Perl5 we have the pack/unpack methods on Perl6 they seems experimental

是否可以使用 Perl6 语法来解析二进制数据,假设我有一个文件,其中包含以下二进制格式的记录:

is it possible to use Perl6 grammar to parse binary data let's say i have a file which have records on the following binary format :

struct record {
short int ut_type;

char ut_line[UT_LINESIZE];
char ut_id[4];
char ut_user[UT_NAMESIZE];
char ut_host[UT_HOSTSIZE];


}

是否可以用 Perl6 语法解析这个文件?

is it possible to parse this file with Perl6 grammar ?

推荐答案

使用 Perl6 解析二进制结构的最佳选择是什么?

What is the best option to parse a binary structure with Perl6?

特别是考虑到您了解 P5 的打包/解包,新的 P5pack 模块似乎是合适的解决方案.(我没有测试过它.它是新的.Aiui 它没有实现所有功能,也没有盲目地模仿 P5 的包.但它是 Liz.)

Especially given that you know about P5's pack/unpack, the new P5pack module is plausibly the appropriate solution. (I haven't tested it. It's new. Aiui it doesn't implement everything and it doesn't mimic P5's pack slavishly. But it's Liz.)

如果上面链接的 P5 包接口的新纯 P6 实现不能满足您的需求,另一个明显的解决方案是在您的 P6 代码中使用由常规 perl 5 二进制文件执行的原始 P5 函数.以下内容不完整/未经测试,但我的意思大致如下:

If the new pure P6 implementation of P5's pack interface linked above does not do what you need done, another obvious solution is using the original P5 functions, executed by a regular perl 5 binary, in your P6 code. The following is incomplete / untested but I mean something roughly like:

use Inline::Perl5 ; my \P5 = Inline::Perl5.new ;

my $mem = Buf ... ;

my $hex = P5.call('unpack', 'H*', $mem) ;

(或者,相反,将主线编写为 P5 代码,通过 Inline 添加 P6 代码::Perl6.)

(Or, conversely, write the mainline as P5 code, adding P6 code via Inline::Perl6.)

在当前版本的 P6 中,6.c,语法只能处理文本.

In the current version of P6, which is 6.c, grammars can only process text.

2 年前 P6er "skids" 写道:

2 years ago P6er "skids" wrote:

"我认为有足够多的人想要二进制语法是"(写于 2016 年).

"There are enough people wanting binary grammars that I think it will come to be" (written in 2016).

当时他们还整理了以下相关链接:

At that time they also put together the following related links:

ShimmerFairy 的 关于 P6 中可能的二进制语法的想法(不完整)"

ShimmerFairy's "thoughts on possible binary grammars in P6 (incomplete)"

Juerd 的 "RFC:更像 Perl6 的"解包".

smls 的 Perl 6 中的二进制解析".

masak 的 在 Perl 6 中打包/解包的第一种方法".

jnthn 的 关于语法的演讲::生成"(视频).

这篇关于使用 Perl6 语法解析二进制结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆