Variable-length integer used in Apple `'dcmp' (0)` and `'dcmp' (1)` compressed resource formats: GraphViz block diagram (.dot) source

A variable-length integer, in the format used by the 0xfe chunks in the 'dcmp' (0) and 'dcmp' (1) resource compression formats. See the dcmp_0 and dcmp_1 specs for more information about these compression formats.

This variable-length integer format can store an integer x in any of the following ways:

  • In a single byte, if 0 <= x <= 0x7f (7-bit unsigned integer)
  • In 2 bytes, if -0x4000 <= x <= 0x3eff (15-bit signed integer with the highest 0x100 values unavailable)
  • In 5 bytes, if -0x80000000 <= x <= 0x7fffffff (32-bit signed integer)

In practice, values are always stored in the smallest possible format, but technically any of the larger formats could be used as well.

Application

Mac OS

KS implementation details

License: MIT
Minimal Kaitai Struct required: 0.8

This page hosts a formal specification of Variable-length integer used in Apple `'dcmp' (0)` and `'dcmp' (1)` compressed resource formats using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

GraphViz block diagram source

dcmp_variable_length_integer.dot

digraph {
	rankdir=LR;
	node [shape=plaintext];
	subgraph cluster__dcmp_variable_length_integer {
		label="DcmpVariableLengthInteger";
		graph[style=dotted];

		dcmp_variable_length_integer__seq [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">pos</TD><TD BGCOLOR="#E0FFE0">size</TD><TD BGCOLOR="#E0FFE0">type</TD><TD BGCOLOR="#E0FFE0">id</TD></TR>
			<TR><TD PORT="first_pos">0</TD><TD PORT="first_size">1</TD><TD>u1</TD><TD PORT="first_type">first</TD></TR>
			<TR><TD PORT="more_pos">1</TD><TD PORT="more_size">...</TD><TD>switch (first)</TD><TD PORT="more_type">more</TD></TR>
		</TABLE>>];
		dcmp_variable_length_integer__inst__value [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>value</TD><TD>(first == 255 ? more : (first &gt;= 128 ? (((first &lt;&lt; 8) | more) - 49152) : first))</TD></TR>
		</TABLE>>];
dcmp_variable_length_integer__seq_more_switch [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
	<TR><TD BGCOLOR="#F0F2E4">case</TD><TD BGCOLOR="#F0F2E4">type</TD></TR>
</TABLE>>];
	}
	dcmp_variable_length_integer__seq:more_type -> dcmp_variable_length_integer__seq_more_switch [style=bold];
	dcmp_variable_length_integer__seq:first_type -> dcmp_variable_length_integer__seq:more_type [color="#404040"];
	dcmp_variable_length_integer__seq:first_type -> dcmp_variable_length_integer__inst__value [color="#404040"];
	dcmp_variable_length_integer__seq:more_type -> dcmp_variable_length_integer__inst__value [color="#404040"];
	dcmp_variable_length_integer__seq:first_type -> dcmp_variable_length_integer__inst__value [color="#404040"];
	dcmp_variable_length_integer__seq:first_type -> dcmp_variable_length_integer__inst__value [color="#404040"];
	dcmp_variable_length_integer__seq:more_type -> dcmp_variable_length_integer__inst__value [color="#404040"];
	dcmp_variable_length_integer__seq:first_type -> dcmp_variable_length_integer__inst__value [color="#404040"];
}