MessagePack (msgpack) serialization format: GraphViz block diagram (.dot) source

MessagePack (msgpack) is a system to serialize arbitrary structured data into a compact binary stream.

KS implementation details

License: CC0-1.0

This page hosts a formal specification of MessagePack (msgpack) serialization format using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

GraphViz block diagram source

msgpack.dot

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

		msgpack__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="b1_pos">0</TD><TD PORT="b1_size">1</TD><TD>u1</TD><TD PORT="b1_type">b1</TD></TR>
			<TR><TD PORT="int_extra_pos">1</TD><TD PORT="int_extra_size">...</TD><TD>switch (b1)</TD><TD PORT="int_extra_type">int_extra</TD></TR>
			<TR><TD PORT="float_32_value_pos">...</TD><TD PORT="float_32_value_size">4</TD><TD>f4be</TD><TD PORT="float_32_value_type">float_32_value</TD></TR>
			<TR><TD PORT="float_64_value_pos">...</TD><TD PORT="float_64_value_size">8</TD><TD>f8be</TD><TD PORT="float_64_value_type">float_64_value</TD></TR>
			<TR><TD PORT="str_len_8_pos">...</TD><TD PORT="str_len_8_size">1</TD><TD>u1</TD><TD PORT="str_len_8_type">str_len_8</TD></TR>
			<TR><TD PORT="str_len_16_pos">...</TD><TD PORT="str_len_16_size">2</TD><TD>u2be</TD><TD PORT="str_len_16_type">str_len_16</TD></TR>
			<TR><TD PORT="str_len_32_pos">...</TD><TD PORT="str_len_32_size">4</TD><TD>u4be</TD><TD PORT="str_len_32_type">str_len_32</TD></TR>
			<TR><TD PORT="str_value_pos">...</TD><TD PORT="str_value_size">str_len</TD><TD>str(UTF-8)</TD><TD PORT="str_value_type">str_value</TD></TR>
			<TR><TD PORT="num_array_elements_16_pos">...</TD><TD PORT="num_array_elements_16_size">2</TD><TD>u2be</TD><TD PORT="num_array_elements_16_type">num_array_elements_16</TD></TR>
			<TR><TD PORT="num_array_elements_32_pos">...</TD><TD PORT="num_array_elements_32_size">4</TD><TD>u4be</TD><TD PORT="num_array_elements_32_type">num_array_elements_32</TD></TR>
			<TR><TD PORT="array_elements_pos">...</TD><TD PORT="array_elements_size">...</TD><TD>Msgpack</TD><TD PORT="array_elements_type">array_elements</TD></TR>
			<TR><TD COLSPAN="4" PORT="array_elements__repeat">repeat num_array_elements times</TD></TR>
			<TR><TD PORT="num_map_elements_16_pos">...</TD><TD PORT="num_map_elements_16_size">2</TD><TD>u2be</TD><TD PORT="num_map_elements_16_type">num_map_elements_16</TD></TR>
			<TR><TD PORT="num_map_elements_32_pos">...</TD><TD PORT="num_map_elements_32_size">4</TD><TD>u4be</TD><TD PORT="num_map_elements_32_type">num_map_elements_32</TD></TR>
			<TR><TD PORT="map_elements_pos">...</TD><TD PORT="map_elements_size">...</TD><TD>MapTuple</TD><TD PORT="map_elements_type">map_elements</TD></TR>
			<TR><TD COLSPAN="4" PORT="map_elements__repeat">repeat num_map_elements times</TD></TR>
		</TABLE>>];
		msgpack__inst__is_array_32 [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_array_32</TD><TD>b1 == 221</TD></TR>
		</TABLE>>];
		msgpack__inst__int_value [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>int_value</TD><TD>(is_pos_int7 ? pos_int7_value : (is_neg_int5 ? neg_int5_value : 4919))</TD></TR>
		</TABLE>>];
		msgpack__inst__str_len [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>str_len</TD><TD>(is_fix_str ? (b1 &amp; 31) : (is_str_8 ? str_len_8 : (is_str_16 ? str_len_16 : str_len_32)))</TD></TR>
		</TABLE>>];
		msgpack__inst__is_fix_array [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_fix_array</TD><TD>(b1 &amp; 240) == 144</TD></TR>
		</TABLE>>];
		msgpack__inst__is_map [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_map</TD><TD> ((is_fix_map) || (is_map_16) || (is_map_32)) </TD></TR>
		</TABLE>>];
		msgpack__inst__is_array [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_array</TD><TD> ((is_fix_array) || (is_array_16) || (is_array_32)) </TD></TR>
		</TABLE>>];
		msgpack__inst__is_float [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_float</TD><TD> ((is_float_32) || (is_float_64)) </TD></TR>
		</TABLE>>];
		msgpack__inst__is_str_8 [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_str_8</TD><TD>b1 == 217</TD></TR>
		</TABLE>>];
		msgpack__inst__is_fix_map [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_fix_map</TD><TD>(b1 &amp; 240) == 128</TD></TR>
		</TABLE>>];
		msgpack__inst__is_int [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_int</TD><TD> ((is_pos_int7) || (is_neg_int5)) </TD></TR>
		</TABLE>>];
		msgpack__inst__is_bool [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_bool</TD><TD> ((b1 == 194) || (b1 == 195)) </TD></TR>
		</TABLE>>];
		msgpack__inst__is_str_16 [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_str_16</TD><TD>b1 == 218</TD></TR>
		</TABLE>>];
		msgpack__inst__is_float_64 [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_float_64</TD><TD>b1 == 203</TD></TR>
		</TABLE>>];
		msgpack__inst__is_map_16 [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_map_16</TD><TD>b1 == 222</TD></TR>
		</TABLE>>];
		msgpack__inst__is_neg_int5 [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_neg_int5</TD><TD>(b1 &amp; 224) == 224</TD></TR>
		</TABLE>>];
		msgpack__inst__pos_int7_value [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>pos_int7_value</TD><TD>b1</TD></TR>
		</TABLE>>];
		msgpack__inst__is_nil [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_nil</TD><TD>b1 == 192</TD></TR>
		</TABLE>>];
		msgpack__inst__float_value [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>float_value</TD><TD>(is_float_32 ? float_32_value : float_64_value)</TD></TR>
		</TABLE>>];
		msgpack__inst__num_array_elements [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>num_array_elements</TD><TD>(is_fix_array ? (b1 &amp; 15) : (is_array_16 ? num_array_elements_16 : num_array_elements_32))</TD></TR>
		</TABLE>>];
		msgpack__inst__neg_int5_value [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>neg_int5_value</TD><TD>-((b1 &amp; 31))</TD></TR>
		</TABLE>>];
		msgpack__inst__bool_value [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>bool_value</TD><TD>b1 == 194</TD></TR>
		</TABLE>>];
		msgpack__inst__is_pos_int7 [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_pos_int7</TD><TD>(b1 &amp; 128) == 0</TD></TR>
		</TABLE>>];
		msgpack__inst__is_array_16 [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_array_16</TD><TD>b1 == 220</TD></TR>
		</TABLE>>];
		msgpack__inst__is_str [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_str</TD><TD> ((is_fix_str) || (is_str_8) || (is_str_16) || (is_str_32)) </TD></TR>
		</TABLE>>];
		msgpack__inst__is_fix_str [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_fix_str</TD><TD>(b1 &amp; 224) == 160</TD></TR>
		</TABLE>>];
		msgpack__inst__is_str_32 [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_str_32</TD><TD>b1 == 219</TD></TR>
		</TABLE>>];
		msgpack__inst__num_map_elements [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>num_map_elements</TD><TD>(is_fix_map ? (b1 &amp; 15) : (is_map_16 ? num_map_elements_16 : num_map_elements_32))</TD></TR>
		</TABLE>>];
		msgpack__inst__is_float_32 [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_float_32</TD><TD>b1 == 202</TD></TR>
		</TABLE>>];
		msgpack__inst__is_map_32 [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">id</TD><TD BGCOLOR="#E0FFE0">value</TD></TR>
			<TR><TD>is_map_32</TD><TD>b1 == 223</TD></TR>
		</TABLE>>];
msgpack__seq_int_extra_switch [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
	<TR><TD BGCOLOR="#F0F2E4">case</TD><TD BGCOLOR="#F0F2E4">type</TD></TR>
</TABLE>>];
		subgraph cluster__map_tuple {
			label="Msgpack::MapTuple";
			graph[style=dotted];

			map_tuple__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="key_pos">0</TD><TD PORT="key_size">...</TD><TD>Msgpack</TD><TD PORT="key_type">key</TD></TR>
				<TR><TD PORT="value_pos">...</TD><TD PORT="value_size">...</TD><TD>Msgpack</TD><TD PORT="value_type">value</TD></TR>
			</TABLE>>];
		}
	}
	msgpack__seq:int_extra_type -> msgpack__seq_int_extra_switch [style=bold];
	msgpack__seq:b1_type -> msgpack__seq:int_extra_type [color="#404040"];
	msgpack__inst__str_len:str_len_type -> msgpack__seq:str_value_size [color="#404040"];
	msgpack__seq:array_elements_type -> msgpack__seq [style=bold];
	msgpack__inst__num_array_elements:num_array_elements_type -> msgpack__seq:array_elements__repeat [color="#404040"];
	msgpack__seq:map_elements_type -> map_tuple__seq [style=bold];
	msgpack__inst__num_map_elements:num_map_elements_type -> msgpack__seq:map_elements__repeat [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__is_array_32 [color="#404040"];
	msgpack__inst__is_pos_int7:is_pos_int7_type -> msgpack__inst__int_value [color="#404040"];
	msgpack__inst__pos_int7_value:pos_int7_value_type -> msgpack__inst__int_value [color="#404040"];
	msgpack__inst__is_neg_int5:is_neg_int5_type -> msgpack__inst__int_value [color="#404040"];
	msgpack__inst__neg_int5_value:neg_int5_value_type -> msgpack__inst__int_value [color="#404040"];
	msgpack__inst__is_fix_str:is_fix_str_type -> msgpack__inst__str_len [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__str_len [color="#404040"];
	msgpack__inst__is_str_8:is_str_8_type -> msgpack__inst__str_len [color="#404040"];
	msgpack__seq:str_len_8_type -> msgpack__inst__str_len [color="#404040"];
	msgpack__inst__is_str_16:is_str_16_type -> msgpack__inst__str_len [color="#404040"];
	msgpack__seq:str_len_16_type -> msgpack__inst__str_len [color="#404040"];
	msgpack__seq:str_len_32_type -> msgpack__inst__str_len [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__is_fix_array [color="#404040"];
	msgpack__inst__is_fix_map:is_fix_map_type -> msgpack__inst__is_map [color="#404040"];
	msgpack__inst__is_map_16:is_map_16_type -> msgpack__inst__is_map [color="#404040"];
	msgpack__inst__is_map_32:is_map_32_type -> msgpack__inst__is_map [color="#404040"];
	msgpack__inst__is_fix_array:is_fix_array_type -> msgpack__inst__is_array [color="#404040"];
	msgpack__inst__is_array_16:is_array_16_type -> msgpack__inst__is_array [color="#404040"];
	msgpack__inst__is_array_32:is_array_32_type -> msgpack__inst__is_array [color="#404040"];
	msgpack__inst__is_float_32:is_float_32_type -> msgpack__inst__is_float [color="#404040"];
	msgpack__inst__is_float_64:is_float_64_type -> msgpack__inst__is_float [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__is_str_8 [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__is_fix_map [color="#404040"];
	msgpack__inst__is_pos_int7:is_pos_int7_type -> msgpack__inst__is_int [color="#404040"];
	msgpack__inst__is_neg_int5:is_neg_int5_type -> msgpack__inst__is_int [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__is_bool [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__is_bool [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__is_str_16 [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__is_float_64 [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__is_map_16 [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__is_neg_int5 [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__pos_int7_value [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__is_nil [color="#404040"];
	msgpack__inst__is_float_32:is_float_32_type -> msgpack__inst__float_value [color="#404040"];
	msgpack__seq:float_32_value_type -> msgpack__inst__float_value [color="#404040"];
	msgpack__seq:float_64_value_type -> msgpack__inst__float_value [color="#404040"];
	msgpack__inst__is_fix_array:is_fix_array_type -> msgpack__inst__num_array_elements [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__num_array_elements [color="#404040"];
	msgpack__inst__is_array_16:is_array_16_type -> msgpack__inst__num_array_elements [color="#404040"];
	msgpack__seq:num_array_elements_16_type -> msgpack__inst__num_array_elements [color="#404040"];
	msgpack__seq:num_array_elements_32_type -> msgpack__inst__num_array_elements [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__neg_int5_value [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__bool_value [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__is_pos_int7 [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__is_array_16 [color="#404040"];
	msgpack__inst__is_fix_str:is_fix_str_type -> msgpack__inst__is_str [color="#404040"];
	msgpack__inst__is_str_8:is_str_8_type -> msgpack__inst__is_str [color="#404040"];
	msgpack__inst__is_str_16:is_str_16_type -> msgpack__inst__is_str [color="#404040"];
	msgpack__inst__is_str_32:is_str_32_type -> msgpack__inst__is_str [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__is_fix_str [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__is_str_32 [color="#404040"];
	msgpack__inst__is_fix_map:is_fix_map_type -> msgpack__inst__num_map_elements [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__num_map_elements [color="#404040"];
	msgpack__inst__is_map_16:is_map_16_type -> msgpack__inst__num_map_elements [color="#404040"];
	msgpack__seq:num_map_elements_16_type -> msgpack__inst__num_map_elements [color="#404040"];
	msgpack__seq:num_map_elements_32_type -> msgpack__inst__num_map_elements [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__is_float_32 [color="#404040"];
	msgpack__seq:b1_type -> msgpack__inst__is_map_32 [color="#404040"];
	map_tuple__seq:key_type -> msgpack__seq [style=bold];
	map_tuple__seq:value_type -> msgpack__seq [style=bold];
}