DMX/Binary

From Valve Developer Community
< DMX
Jump to: navigation, search
class Binary
{
	string header = "<!-- dmx encoding binary %i format %s %i -->\n";
	
	// String table exists for version 2 and above.
	int			stringCount;	// The number of strings in the string table.
	string[]	stringTable;	// List of null terminated strings.

	int			elementCount;	// The number of elements in the data model.
	DmElement[]	elements;		// List of elements in the data model.

	// For each element, it reads all the attributes attached to it.
	// It begins by reading an int value to determine the count of attributes the element possesses.
	// Subsequently, it reads all the DmAttribute instances based on the count and pushes each attribute to the element's attributes list.
};

class DmElement
{
	// This is an int value index to the string table if version is greater than 1 else it's a null terminated string.
	string		type;	// The type of the element.
	// This is an int value index to the string table if version is greater than 3 else it's a null terminated string.
	string		name;	// The name of the element.
	char[16]	id;		// The UUID of the element.

	DmAttribute[]	attributes;	// The attributes the element has.
};

class DmAttribute
{
	// This is an int value index to the string table if version is greater than 1 else it's a null terminated string.
	string	name;	// The name of the attribute.
	char	type;	// The type of attribute, see below.
	void*	value;	// see below
};

Attribute Types

Check DmAttributeType_t in public/datamodel/dmattributetypes.h to get the index of each attribute type.

Note.pngNote:DmAttributeType_t is different for each engine version, so make sure that you're looking at the right version!

Attribute Values

Most values are stored in their native binary format (check tier0 for the layout of the fancier types). Exceptions are:

Elements
Element values are represented by an int. The value is the element's position in the element index.
  • -1 means "no value"
  • -2 followed by an ASCII UUID (yes, ASCII!) means a "external element" which exists but was excluded from the DMX
Strings
String values are stored as an int index in the string dictionary when version 4 or higher. String array values are stored inline as a null-terminated char array.
Binary (AT_VOID)
Binary values are stored with an int count, then that many bytes immediately after.
Object Id
A UUID object stored if the version is lower than 3.
Time
Time values are float in memory but are stored in binary DMX as (int)(this*10000).
Color
Color values are objects with four ints in memory but stored in binary DMX as char[4].
Matrix
A 4 by 4 float matrix.
Arrays
Arrays start with an int defining the number of items they contained and are tightly-packed.

Previous versions

Version Changes
Binary_v2 Earliest known version. Header is <!-- DMXVersion binary_v2 -->\n.
1 Standard DMX header introduced: <!-- dmx encoding binary %i format %s %i -->\n.
2 String dictionary added for element types and attribute names; length and indices are short.
3 Object Id attribute type replaced with Time attribute type.
4

String dictionary length is now int, even though indices are still short. String values (non-array) and element names moved to string dictionary.

5

String dictionary indices are now int too.