| Binary Markup Language |
Binary Markup Language, or BML is a platform-independent binary file meta-format with semantics inspired by XML.
BML currently does not implement support for storing floating-point numbers. That is an issue which will need to be addressed soon. (Need to select a standard, machine-independent way to encode them.)
A BML stream consists of a set of opcodes which can reconstruct this tree, either as a series of nested events (as in SAX) or as an in-memory structure (as in DOM).
Each element node and attribute has an associated identifier. In the case of a node, the identifier indicates the "type" of the node. It is equivalent to the element name in XML. In the case of the attribute, the identifier indicates the name of the attribute.
Negative integers are stored similarly, but using a different opcode.
In many cases, if a number is very small (<64), it will be stored directly in the opcode.
Strings are stored as a VarInt containing the length of the string, followed by the actual string bytes. The terminating null character is not stored.
The signature should be followed by a version number, which is a varInt. This is the version number of BML, not the version number of the encoded elements. It is recommended that the top-most element of a BML stream have a "version" attribute for purposes of versioning the actual data contained within.#define BML_SIGNATURE "\211BML\r\n\032\n"
The current BML version number is 1.
class BinaryMarkupWriterInterface { public:/** Add a string-valued attribute to the current element. */ void putStringAttribute( const char *name, const char *val );/** Add an enum-valued attribute to the current element. (This is semantically identical to putStringAttribute, except the value is stored as a token.) */ void putEnumAttribute( const char *name, const char *val );/** Add an integer-valued attribute to the current element */ void putIntegerAttribute( const char *name, long val );/** Add an double-valued attribute to the current element */ void putDoubleAttribute( const char *name, double val );/** Add an boolean-valued attribute to the current element */ void putBooleanAttribute( const char *name, bool val );/** Add an boolean-valued attribute to the current element */ void putBinaryAttribute( const char *name, const char *data, size_t len );/** Start a new nested element */ void startElement( const char *className );/** Pop the current element */ void endElement();/** Write an end-of-stream marker */ void end(); };
class BinaryMarkupInputHandler {
public:
virtual bool onStringAttribute( const char *name, const char *val ) = 0;
virtual bool onEnumAttribute( const char *name, const char *val ) = 0;
virtual bool onIntegerAttribute( const char *name, long val ) = 0;
virtual bool onDoubleAttribute( const char *name, double val ) = 0;
virtual bool onBooleanAttribute( const char *name, bool val ) = 0;
virtual bool onBinaryAttribute( const char *name,
const char *data,
size_t length ) = 0;
virtual bool onStartElement( const char *name ) = 0;
virtual bool onEndElement( const char *name ) = 0;
};
enum {
// End of stream marker // format: op() BMOp_End = 0,
// Define a token for later use. The token is assigned the next available token id, // starting from 1 and incrementing by 1 for each token defined. // format: op( nameLength:varInt, name:uint8[ len ] ) BMOp_DefineToken = 0x01,
// A string-valued property // format: op( nameToken:varInt, strLength:varInt, strVal:uint8[ len ] ) BMOp_StringAttribute = 0x02,
// An integer-valued property // format: op( nameToken:varInt, value:varInt ) BMOp_IntegerAttribute = 0x03,
// An integer-valued property (stored as negative of real value) // format: op( nameToken:varInt, value:varInt ) BMOp_NegativeIntegerAttribute = 0x04,
// An double-valued property // format: op( nameToken:varInt, value:double[encoded?] ) BMOp_DoubleAttribute = 0x05,
// An boolean-valued property with value "true" // format: op( token:varInt ) BMOp_BooleanTrueAttribute = 0x06,
// An boolean-valued property with value "true" // format: op( token:varInt ) BMOp_BooleanFalseAttribute = 0x07,
// A string-valued property, stored as a token // format: op( token:varInt, valueToken:varInt ) BMOp_EnumAttribute = 0x08,
// An binary-valued property // format: op( token:varInt, length:varInt, data:uint8[ length ] ) BMOp_BinaryAttribute = 0x09,
// Start an element // format: op( elementNameToken:varInt ) BMOp_StartElement = 0x0a,
// Finish an object // format: op() BMOp_EndElement = 0x0b,
// Ox0c - 0x1f reserved for future expansion and fixing boneheaded mistakes
// A property for short negative integers // Token name length stored in low 5 bits. // format: op+len( token:varInt ) BMOp_SmallNegIntegerAttribute = 0x20,
// A property for short token names // Token name length stored in low 6 bits. // format: op+len( name:uint8[ len ] ) BMOp_DefineSmallToken = 0x40,
// A property for short strings // String length stored in low 6 bits. // format: op+len( val:uint8[ len ] ); BMOp_SmallStringAttribute = 0x80
// A property for small integer values // Integer stored in low 6 bits. // format: op+val( token:varInt ); BMOp_SmallIntegerAttribute = 0xc0,
};
|
|
Return to Talin's project page.
Return to Talin's home page.