17 July 2012

Java Construct 1.1.2 Release

Java Construct 1.1.2 is now available!

You can download it from https://github.com/ZiglioUK/construct/tags

Also available from Maven Central

 <dependency>  
  <groupId>com.sirtrack</groupId>  
  <artifactId>javaconstruct</artifactId>  
  <version>1.1.2</version>  
 </dependency>  

New features:

  1. a CRC/Checksum Construct, see example on how to use it: IPv4 
  2. Implemented Restreams (dynamic Structs) - only parsing for now
  3. Implemented MetaArray, Sequence, more Adapters and Macros
  4. Added an experimental BeanAdapter for typesafe conversion from/to a Container
TODOs:
  1. Improve formatting. I'm sorry but each new release of Eclipse loses my settings. It looks good on Eclipse, but for anyone else tabs are all over the place
  2. Implement Restream.build() at a certain point 
Nice to have:
  1. Do some performance testing, using the Jvm Serializers benchmark
  2. Cleanup the low level, possibly moving away from ByteBuffer, in similar way as Kryo 2 did.

About Construct

Python Construct is a library for parsing and building binary messages. 
Java Construct is an "as faithful as possible" translation to Java of Python Construct 2.x. 
See the docs for explanations and examples. 


20 January 2012

Java Construct 1.0.0 Release


I'm pleased to announce release 1.0.0 of Java Construct, a faithful
port to Java of Python Construct.

About Python Construct: http://construct.wikispaces.com/
"Construct is a python library for parsing and building of data
structures (binary or textual). It is based on the concept of defining
data structures in a declarative manner, rather than procedural code:
more complex constructs are composed of a hierarchy of simpler ones.
It's the first library that makes parsing fun, instead of the usual
headache it is today."

About Java Construct: https://github.com/ZiglioUK/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.

Example of a Construct:

 import static construct.Core.*;  
   import static construct.Macros.*;  
   import static construct.Adapters.*;  
   import static construct.lib.Containers.*;  
   Construct struct = BitStruct(  
     "foo",  
     BitField("a", 3),  
     Flag("b"),  
     Padding(3),  
     Nibble("c"),  
     Struct("bar",  
       Nibble("d"),  
       Bit("e")  
     )  
   );  
A 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:
   Container c1 = Container(  
     "a", 7,  
     "b", false,  
     "bar",  
     Container(  
       "d", 15 ,  
       "e", 1  
      ),  
      "c",8  
   );  
   Container c2 = struct.parse( ByteArray( 0xe1, 0x1f ));  
   assertEquals( c1, c2 );  
Currently Java Construct supports enough Macros, Adapters and Repeaters to parse and build these protocols: Full ipstack example: https://github.com/ZiglioUK/construct/blob/master/src/main/construct/protocols/ipstack.java Notes: 1. I haven't tested for threadsafety but it's a priority 2. Streams are not supported so a message has to be contained in memory. If there are segments, they have to re-assambled prior to parsing 3. Text protocols like http are not supported, it's questionable whether Construct would be the right tool for text parsing.