We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
我查了很多资料,只能找到 Ragel (www.complang.org/ragel),它也可以生成 Java 代码。
它对我来说太复杂了,所以我开始了一些将 Construct 移植到 Java 的工作。
我怀疑在 Scala、Groovy 或 JavaScript 中制作类似的东西会更容易。
在 GitHub 上构造:https://github.com/MostAwesomeDude/construct
java 构造:https://github.com/ZiglioNZ/construct
我花了几天时间,主要是寻找 python 的等价物表达类。
我发现的最有用的 java 类是:java.util.Scanner、java.util.Formatter 和 java.nio.ByteBuffer。
这是一项艰巨的任务,因此我想专注于一些小事情,例如为 ByteBuffers 创建简单的解析器和格式化程序。
[更新]
我已经移植了足够的代码来解析和构建 Python Construct 附带的一些协议,例如以太网、arp 和 ipv4。请访问 https://github.com/ZiglioNZ/construct
[更新:新版本]
Java Construct 1.1.2 现已推出,请参阅发行说明。
I've looked a lot around and all I could find was Ragel (www.complang.org/ragel), that can also produce Java code.
It looked too complex for me so I've started some work to port Construct to Java.
I suspect it would be easier to make something like that in Scala, Groovy or JavaScript.
Construct on GitHub: https://github.com/MostAwesomeDude/construct
java construct: https://github.com/ZiglioNZ/construct
I've spent a couple of days on it, mostly looking for equivalents of python's expressive classes.
The most useful java classes I've found are: java.util.Scanner, java.util.Formatter and java.nio.ByteBuffer.
It's a big task so I want to focus on something small like creating simple parsers and formatters for ByteBuffers.
[Update]
I've ported enough code to parse and build some of the protocols that come with Python Construct, such as ethernet, arp and ipv4. Check it out at https://github.com/ZiglioNZ/construct
[Update: new Release]
Java Construct 1.1.2 is now available, see release notes.
您可以使用
DataInput
/DataOutput
(及其实现)将任何一组值从一组字节转换为一组字节。不过,这并没有为您提供一个可以使用名称来访问各个字段的对象 - 您必须自己创建这样的对象。这在一定程度上取决于您想要做什么 - 您是否有固定的数据格式可以在线发送/接收,或者是否会不时变化?
You can use
DataInput
/DataOutput
(and their implementations) to convert any set of values from/to a set of bytes. This doesn't give you an object where you can use names to access the individual fields, though - you would have to create such yourself.It depends a bit on what you want to do - do you have a fixed data format to send/receive on wire, or does this vary from time to time?