]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/src-isv/spec/Binary Format.mediawiki
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / src-isv / spec / Binary Format.mediawiki
diff --git a/bundles/org.simantics.databoard/src-isv/spec/Binary Format.mediawiki b/bundles/org.simantics.databoard/src-isv/spec/Binary Format.mediawiki
new file mode 100644 (file)
index 0000000..d97fa14
--- /dev/null
@@ -0,0 +1,181 @@
+=Binary Format=\r
+''Binary serialization'' is used in files and network communication.\r
+This document gives a specification how Datatypes and Datavalues are written in binary format. \r
+\r
+All numeric values are in [http://en.wikipedia.org/wiki/Endianness Big Endian] order, aka Network byte order.\r
+\r
+===Boolean===\r
+Boolean is an <code>UINT8</code>, with one of the following values.\r
+\r
+{| border="1" cellpadding="3" cellspacing="0" align="center"\r
+|'''Value'''\r
+|'''Description'''\r
+|- style="background-color: #f9f9f9;"\r
+|<code>0</code>\r
+|false\r
+|-\r
+|<code>1</code>\r
+|true\r
+|- style="background-color: #f9f9f9;"\r
+|<code>2..255</code>\r
+|''Invalid value''\r
+|}\r
+\r
+===Numbers===\r
+{| border="1" cellpadding="3" cellspacing="0" align="center"\r
+|'''Type'''\r
+|'''Description'''\r
+|- style="background-color: #f9f9f9;"\r
+|Byte\r
+|Int8\r
+|-\r
+|Integer\r
+|Int32\r
+|- style="background-color: #f9f9f9;"\r
+|Long\r
+|Int64\r
+|-\r
+|Float\r
+|Float\r
+|- style="background-color: #f9f9f9;"\r
+|Double\r
+|Double\r
+|}\r
+\r
+===Optional===\r
+There is a Boolean that describes whether there is an actual value.\r
+If false no data follows, true the content ensues.\r
+\r
+{| border="1" cellpadding="3" cellspacing="0" align="center"\r
+|'''Field'''\r
+|'''Description'''\r
+|- style="background-color: #f9f9f9;"\r
+|<code>hasValue : Boolean</code>\r
+|Tells whether there is a ''value''\r
+|-\r
+|''value''\r
+|The actual value, available only if hasValue == true.\r
+|}\r
+\r
+===String===\r
+String is a series of bytes encoded as [http://download.oracle.com/javase/6/docs/api/java/io/DataInput.html#modified-utf-8 Modified-UTF-8]. \r
+\r
+{| border="1" cellpadding="3" cellspacing="0" align="center"\r
+|'''Field'''\r
+|'''Description'''\r
+|- style="background-color: #f9f9f9;"\r
+|<code>length : Length</code>\r
+|Describes the number of bytes in the string using packed integer encoding (1-5 bytes).\r
+|-\r
+|''data''\r
+|Modified-UTF-8 encoded String.  \r
+|}\r
+\r
+The length is encoded as UInt32 of 1 to 5 bytes. \r
+{| border="1" cellpadding="3" cellspacing="0" align="center"\r
+|'''Value'''\r
+|'''Encoding'''\r
+|- style="background-color: #f9f9f9;"\r
+| <code>0x00000000..0x0000007F</code>\r
+| ''value'' (1 byte)\r
+|-\r
+| <code>0x00000080..0x00003FFF</code>\r
+| ''value & 0x3f | 0x80'', ''value>>6 & 0xff'' (2 bytes)\r
+|- style="background-color: #f9f9f9;"\r
+| <code>0x00004000..0x001FFFFF</code>\r
+| ''value & 0x1f | 0xC0'', ''value>>5 & 0xff'', ''value>>13 & 0xff'' (3 bytes)\r
+|-\r
+| <code>0x02000000..0x0FFFFFFF</code>\r
+| ''value & 0x1f | 0xE0'', ''value>>3 & 0xff'', ''value>>12 & 0xff'', ''value>>20 & 0xff'' (4 bytes)\r
+|- style="background-color: #f9f9f9;"\r
+| <code>0x10000000..0xFFFFFFFF</code>\r
+| ''value & 0x07 | 0xF0'', ''value>>3 & 0xff'', ''value>>11 & 0xff'', ''value>>19 & 0xff'', ''value>>27 & 0xff'' (5 bytes)\r
+|}\r
+\r
+\r
+\r
+===Array===\r
+{| border="1" cellpadding="3" cellspacing="0" align="center"\r
+|'''Field'''\r
+|'''Description'''\r
+|- style="background-color: #f9f9f9;"\r
+|<code>length : UInt32</code>\r
+|Describes the number of elements as unsigned integer. This field is omited if the range is constant.\r
+|-\r
+|''&lt;elements&gt;''\r
+|Array elements\r
+|}\r
+\r
+===Generic Record===\r
+{| border="1" cellpadding="3" cellspacing="0" align="center"\r
+|'''Field'''\r
+|'''Description'''\r
+|- style="background-color: #f9f9f9;"\r
+|''&lt;fields&gt;''\r
+|Component fields in the order specified in datatype.\r
+|}\r
+\r
+===Referable Record===\r
+Referable records are objects that are referenced else where in the datavalue. The way they are serialized is that, when a record is serialized the first time, a 0 is written and then the actual record value. The serializer object gives it a next id number and takes a note of it. Id is not written, it is implicit and only interpretable by reading the stream. When a refereable record the second time, or afterwards, only it's id number is written, not the whole content.\r
+{| border="1" cellpadding="3" cellspacing="0" align="center"\r
+|'''Field'''\r
+|'''Description'''\r
+|- style="background-color: #f9f9f9;"\r
+|<code>recordId : Integer</code>\r
+|Identity that refers in this serialiation to this instance.\r
+|-\r
+|''&lt;fields&gt;''\r
+|Component fields in the order specified in datatype.\r
+|}\r
+\r
+===Generic Union===\r
+{| border="1" cellpadding="3" cellspacing="0" align="center"\r
+|'''Field'''\r
+|'''Description'''\r
+|- style="background-color: #f9f9f9;"\r
+|<code>tag : Byte, Short or Integer</code>\r
+|Number that indicates that type in the UnionType's ''components'' array. Type depends on the number of cases.\r
+|-\r
+|''value''\r
+|The value of the component type.\r
+|}\r
+\r
+===Variant===\r
+{| border="1" cellpadding="3" cellspacing="0" align="center"\r
+|'''Field'''\r
+|'''Description'''\r
+|- style="background-color: #f9f9f9;"\r
+|<code>type : DataType</code>\r
+|Describes the datatype of the following value.\r
+|-\r
+|''value''\r
+|The value serialized according to the type\r
+|}\r
+\r
+===Map===\r
+{| border="1" cellpadding="3" cellspacing="0" align="center"\r
+|'''Field'''\r
+|'''Description'''\r
+|- style="background-color: #f9f9f9;"\r
+|<code>length : UInt32</code>\r
+|Describes the number of entries in the map using integer encoding.\r
+|-\r
+|''&lt;entries&gt;''\r
+|Map Entries\r
+|- style="background-color: #f9f9f9;"\r
+|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>key : K</code>\r
+|The key serializes according to the Key type\r
+|-\r
+|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>value : V</code>\r
+|The value serialized according to the Value type\r
+|}\r
+Entries are written in ascending of the key (See [[typesystem.html#Comparison]])\r
+\r
+\r
+=File types=\r
+{| border="1" cellpadding="3" cellspacing="0" align="center"\r
+|'''Extension'''\r
+|'''Description'''\r
+|- \r
+|<tt>.dbb</tt> ||Databoard Binary File. Concatenation of Datatype + value\r
+|}\r