资源说明:A Java version of "Construct" a python library for parsing and building of data structures (binary or textual)
h2. Python Construct Construct is a powerful declarative parser for binary data. It is based on the concept of defining data structures in a declarative manner, rather than procedural code: Simple constructs can be combined hierarchically to form increasingly complex data structures. It's the first library that makes parsing fun, instead of the usual headache it is today. Construct features bit and byte granularity, symmetrical operation (parsing and building), component-oriented declarative design, easy debugging and testing, an easy-to-extend subclass system, and lots of primitive constructs to make your work easier: * Fields * Structs * Unions * Repeaters * Meta constructs * Switches * On-demand parsing * Pointers * And more! h2. Java Construct This Java version employs some syntactic sugar (i.e. static methods) to make the syntax as close as possible to the original Construct library in Python. See for "example":https://github.com/ZiglioNZ/construct/blob/master/src/test/construct/BitTest.javaA Java Construct can parse byte arrays and produces Objects like Containers. Viceversa, it can take Objects to produce byte arrays. @public Object parse(byte[] data);@ @public byte[] build( Object obj);@ Parsing example:Construct struct = BitStruct("foo", BitField("a", 3), Flag("b"), Padding(3), Nibble("c"), Struct("bar", Nibble("d"), Bit("e")));
h3. Features Currently Java Construct supports enough Macros, Adapters and repeaters to parse and build these protocols: * Layer 2: "ethernet":https://github.com/ZiglioNZ/construct/blob/master/src/main/java/com/sirtrack/construct/protocols/layer2/ethernet.java, "arp":https://github.com/ZiglioNZ/construct/blob/master/src/main/java/com/sirtrack/construct/protocols/layer2/arp.java * Layer 3: "ipv4":https://github.com/ZiglioNZ/construct/blob/master/src/main/java/com/sirtrack/construct/protocols/layer3/ipv4.java, "ipv6":https://github.com/ZiglioNZ/construct/blob/master/src/main/java/com/sirtrack/construct/protocols/layer3/ipv6.java * Layer 4: "udp":https://github.com/ZiglioNZ/construct/blob/master/src/main/java/com/sirtrack/construct/protocols/layer4/udp.java, "tcp":https://github.com/ZiglioNZ/construct/blob/master/src/main/java/com/sirtrack/construct/protocols/layer4/tcp.java * "ipstack":https://github.com/ZiglioNZ/construct/blob/master/src/main/java/com/sirtrack/construct/protocols/ipstack.javaContainer c1 = Container( "a", 7, "b", false, "bar", Container( "d", 15 , "e", 1), "c",8); Container c2 = struct.parse( ByteArray( 0xe1, 0x1f )); assertEquals( c1, c2 );
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。