I Wanted Orange (The machine would not make a mistake.)

2Sep/10Off

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;
    @BoundNumber
    protected int version;
    @BoundNumber
    protected int checksum;
    @BoundString(size = "64")
    protected String modelName;
    @BoundNumber
    protected int dataLength;
    @BoundObject
    protected Vector3f eyePosition;
    @BoundObject
    protected Vector3f illumposition;
    @BoundObject
    protected Vector3f hull_min;
    @BoundObject
    protected Vector3f hull_max;
    @BoundObject
    protected Vector3f view_bbmin;
    @BoundObject
    protected Vector3f view_bbmax;

    @BoundList(size="4")
    protected byte[] flags; //FIXME: Use boolean or bitset



    @BoundNumber
    protected int boneCount;
    @BoundNumber
    protected int boneIndex;

    @BoundList(offset="boneIndex",size="boneCount")
    protected Bone[] bones;
}
Comments (1) Trackbacks (0)
  1. 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.)


Trackbacks are disabled.