Difference between revisions of "Data types"
Jump to navigation
Jump to search
(bool moved before byte as that it carries less information quantity) |
Drainedsoul (talk | contribs) (Minecraft actually uses UTF-16) |
||
Line 50: | Line 50: | ||
| class="col1 centeralign" | ≥ 2 <br />≤ 240 | | class="col1 centeralign" | ≥ 2 <br />≤ 240 | ||
| class="col2" | N/A | | class="col2" | N/A | ||
− | | class="col3" | [http://en.wikipedia.org/wiki/UTF-16 | + | | class="col3" | [http://en.wikipedia.org/wiki/UTF-16 UTF-16] big-endian string prefixed by a short containing the length of the string in [http://en.wikipedia.org/wiki/Code_unit code units] (as a UTF-16 code unit is 2 bytes, multiply the length by two to get the length in bytes). UTF-16 is a variable-width encoding so each [http://en.wikipedia.org/wiki/Code_point code point] may be 1 or 2 code units. Accordingly the specified length (in code units) does not necessarily map onto the logical length of the string (in code points). |
|- class="row9" | |- class="row9" | ||
! class="col0 centeralign" | metadata | ! class="col0 centeralign" | metadata |
Revision as of 18:52, 26 August 2013
All data sent over the network is big-endian, that is the bytes are sent from most significant byte to least significant byte. The majority of everyday computers are little-endian, therefore it may be necessary to change the endianness before sending data over the network.
Other than 'String' and 'Metadata', which are decoded with a custom function, these data formats are identical to those provided by the Java classes DataInputStream and DataOutputStream.
Size | Range | Notes | |
---|---|---|---|
bool | 1 | 0 or 1 | Value can be either true (0x01) or false (0x00) |
byte | 1 | -128 to 127 | Signed, two's complement |
short | 2 | -32768 to 32767 | Signed, two's complement |
int | 4 | -2147483648 to 2147483647 | Signed, two's complement |
long | 8 | -9223372036854775808 to 9223372036854775807 | Signed, two's complement |
float | 4 |
See this |
Single-precision 32-bit IEEE 754 floating point |
double | 8 |
See this |
Double-precision 64-bit IEEE 754 floating point |
string | ≥ 2 ≤ 240 |
N/A | UTF-16 big-endian string prefixed by a short containing the length of the string in code units (as a UTF-16 code unit is 2 bytes, multiply the length by two to get the length in bytes). UTF-16 is a variable-width encoding so each code point may be 1 or 2 code units. Accordingly the specified length (in code units) does not necessarily map onto the logical length of the string (in code points). |
metadata | Varies | See this |
Some data may be stored as an "absolute integer", which is a more precise kind of integer, and a less precise kind of double. The conversion from double to absolute integer is like so:
abs_int = (int)double * 32;
And back again:
double = (double)abs_int / 32;