Skip to content

Binary parsing in Java

Well, PackBSP 2.0.4 may be delayed a bit due to extra complications in parsing the MDL files... In addition, I'm revisiting the idea of using Preon to more-easily program in the parsing rules. I tried it out a few months ago but decided to avoid it due to some blocking bugs. Now, however, with it getting a bit more activity and I want to see if it can replace some of my serviceable but-not-that-pretty code.

Here's a quick (incomplete) bit of sample code for MDL parsing. The Java class is being annotated so that the Preon framework can semi-magically shove data into it.

public class Mdl {

    @BoundString(match = "IDST", size = "4")
    protected String magicHeader;
    protected int version;
    protected int checksum;
    @BoundString(size = "64")
    protected String modelName;
    protected int dataLength;
    protected Vector3f eyePosition;
    protected Vector3f illumposition;
    protected Vector3f hull_min;
    protected Vector3f hull_max;
    protected Vector3f view_bbmin;
    protected Vector3f view_bbmax;

    protected byte[] flags; //FIXME: Use boolean or bitset

    protected int boneCount;
    protected int boneIndex;

    protected Bone[] bones;

Posted in Programming.

Tagged with , .

One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Wilfred Springer says

    Regarding this:

    “protected byte[] flags; //FIXME: Use boolean or bitset”

    … this should now be fixed. (That is, in the current head. There is no support for Bitset yet though.)