Polymorph Data Encoding

Jakob Jenkov
Last update: 2024-08-14

The Polymorph Data format uses a compact, fast to read and write, versatile binary encoding. This text specifies how that encoding looks. As mentioned, Polymorph Data uses a binary encoding - also sometimes referred to as Polymorph Binary - or Pinary for short.

Polymorph also contains a textual data format which can be converted to Polymorph binary easily. That way you can more easily create Pinary files. This textual-to-binary data format is also referred to as Textual Binary or Tinary.

Polymorph Data Encoding

The Polymorph Data Encoding uses a simple Type-Length-Value format. All data is encoded into fields. A field has a type. The very first byte of a field tells the type. Depending on the field type (the first byte) the rest of the field's bytes are interpreted differently. Polymorph Data Encoding has the following archetype field encodings:

  1. Type => Value
  2. Type => Length Bytes => Value

Type => Value

Fields that follow the [Type => Value] encoding will have:

  • 1 Type byte
  • N Value bytes

The number of value bytes depends on the type of the field. For instance, the type INT_POS_1_BYTES means a "positive integer of 1 bytes in length". Thus, the length of the field value is implicitly derived from the field type.

Type => Length => Value

Fields that follow the [Type => Length => Value] encoding will have:

  • 1 Type byte
  • 0 to 15 Length bytes
  • N Value bytes

The number of length bytes depends on the type of the field. For instance, the type BYTES_2_LENGTH_BYTES means a "byte field with 2 length bytes - meaning a possible field value length of 0 to 65535 bytes".

Little Endian Integer Encoding

All integer numbers that require more than 1 byte to represent, are encoded using a Little Endian encoding, meaning the first byte contains the least significant byte of the number.

Polymorph Data Field Types

Remember, the first byte of a Polymorph Data field is the field type.

Polymorph contains the following field types:

Field TypeType CodeDescription
BOOLEAN_NULL0A single byte with the value 0 - representing a boolean field with a null value.
BOOLEAN_TRUE1A single byte with the value 1 - representing a boolean field with the value True.
BOOLEAN_FALSE2A single byte with the value 2 - representing a boolean field with the value False.
INT_NULL3A single byte with the value 3 - representing a null value of type integer.
INT_POS_1_BYTES41 type byte + 1 value byte - containing a positive integer value of 1 byte (0 to 255)
INT_POS_2_BYTES51 type byte + 2 value bytes - containing a positive integer value of 2 bytes (0 to 65535)
INT_POS_3_BYTES61 type byte + 3 value bytes - containing a positive integer value of 3 bytes (0 to 2^24-1)
INT_POS_4_BYTES71 type byte + 4 value bytes - containing a positive integer value of 4 bytes (0 to 2^32-1)
INT_POS_5_BYTES81 type byte + 5 value bytes - containing a positive integer value of 5 bytes (0 to 2^40-1)
INT_POS_6_BYTES91 type byte + 6 value bytes - containing a positive integer value of 6 bytes (0 to 2^48-1)
INT_POS_7_BYTES101 type byte + 7 value bytes - containing a positive integer value of 7 bytes (0 to 2^56-1)
INT_POS_8_BYTES111 type byte + 8 value bytes - containing a positive integer value of 8 bytes (0 to 2^64-1)
INT_NEG_1_BYTES121 type byte + 1 value byte - containing a positive integer representing a negative integer value of 1 byte (0 to 255 meaning -1 to -256)
INT_NEG_2_BYTES131 type byte + 2 value bytes - containing a positive integer representing a negative integer value of 2 bytes (0 to 2^16-1 meaning -1 to -2^16)
INT_NEG_3_BYTES141 type byte + 3 value bytes - containing a positive integer representing a negative integer value of 3 bytes (0 to 2^24-1 meaning -1 to -2^24)
INT_NEG_4_BYTES151 type byte + 4 value bytes - containing a positive integer representing a negative integer value of 4 bytes (0 to 2^32-1 meaning -1 to -2^32)
INT_NEG_5_BYTES161 type byte + 5 value bytes - containing a positive integer representing a negative integer value of 5 bytes (0 to 2^40-1 meaning -1 to -2^40)
INT_NEG_6_BYTES171 type byte + 6 value bytes - containing a positive integer representing a negative integer value of 6 bytes (0 to 2^48-1 meaning -1 to -2^48)
INT_NEG_7_BYTES181 type byte + 7 value bytes - containing a positive integer representing a negative integer value of 7 bytes (0 to 2^56-1 meaning -1 to -2^56)
INT_NEG_8_BYTES191 type byte + 8 value bytes - containing a positive integer representing a negative integer value of 8 bytes (0 to 2^64-1 meaning -1 to -2^64)
FLOAT_NULL201 type byte representing a float field with a null value
FLOAT_4_BYTES211 type byte + 4 value bytes - containing a 4 byte float value. Encoding is the same as in Java.
FLOAT_8_BYTES221 type byte + 8 value bytes - containing an 8 byte float value (AKA double). Encoding is the same as in Java.
BYTES_NULL231 type byte representing a field of type byte sequence - with a null value.
BYTES_0_BYTES241 type byte + 0 value bytes - representing field of type byte sequence - with a zero length.
BYTES_1_BYTES251 type byte + 1 value bytes - representing field of type byte sequence - with a 1 byte length (a 1 byte byte array).
BYTES_2_BYTES261 type byte + 2 value bytes - representing field of type byte sequence - with a 2 byte length (a 2 byte byte array).
BYTES_3_BYTES271 type byte + 3 value bytes - representing field of type byte sequence - with a 3 byte length (a 3 byte byte array).
BYTES_4_BYTES281 type byte + 4 value bytes - representing field of type byte sequence - with a 4 byte length (a 4 byte byte array).
BYTES_5_BYTES291 type byte + 5 value bytes - representing field of type byte sequence - with a 5 byte length (a 5 byte byte array).
BYTES_6_BYTES301 type byte + 6 value bytes - representing field of type byte sequence - with a 6 byte length (a 6 byte byte array).
BYTES_7_BYTES311 type byte + 7 value bytes - representing field of type byte sequence - with a 7 byte length (a 7 byte byte array).
BYTES_8_BYTES321 type byte + 8 value bytes - representing field of type byte sequence - with a 8 byte length (a 8 byte byte array).
BYTES_9_BYTES331 type byte + 9 value bytes - representing field of type byte sequence - with a 9 byte length (a 9 byte byte array).
BYTES_10_BYTES341 type byte + 10 value bytes - representing field of type byte sequence - with a 10 byte length (a 10 byte byte array).
BYTES_11_BYTES351 type byte + 11 value bytes - representing field of type byte sequence - with a 11 byte length (a 11 byte byte array).
BYTES_12_BYTES361 type byte + 12 value bytes - representing field of type byte sequence - with a 12 byte length (a 12 byte byte array).
BYTES_13_BYTES371 type byte + 13 value bytes - representing field of type byte sequence - with a 13 byte length (a 13 byte byte array).
BYTES_14_BYTES381 type byte + 14 value bytes - representing field of type byte sequence - with a 14 byte length (a 14 byte byte array).
BYTES_15_BYTES391 type byte + 15 value bytes - representing field of type byte sequence - with a 15 byte length (a 15 byte byte array).
BYTES_1_LENGTH_BYTES401 type byte + 1 length byte + N length bytes - representing field of type byte sequence with a max length of 2^8-1 bytes.
BYTES_2_LENGTH_BYTES411 type byte + 2 length byte + N length bytes - representing field of type byte sequence with a max length of 2^16-1 bytes.
BYTES_3_LENGTH_BYTES421 type byte + 3 length byte + N length bytes - representing field of type byte sequence with a max length of 2^24-1 bytes.
BYTES_4_LENGTH_BYTES431 type byte + 4 length byte + N length bytes - representing field of type byte sequence with a max length of 2^32-1 bytes.
BYTES_5_LENGTH_BYTES441 type byte + 5 length byte + N length bytes - representing field of type byte sequence with a max length of 2^40-1 bytes.
BYTES_6_LENGTH_BYTES451 type byte + 5 length byte + N length bytes - representing field of type byte sequence with a max length of 2^48-1 bytes.
BYTES_7_LENGTH_BYTES461 type byte + 5 length byte + N length bytes - representing field of type byte sequence with a max length of 2^56-1 bytes.
BYTES_8_LENGTH_BYTES471 type byte + 5 length byte + N length bytes - representing field of type byte sequence with a max length of 2^64-1 bytes.
UTF_8_NULL481 type byte representing a field of type UTF-8 - with a null value.
UTF_8_0_BYTES491 type byte + 0 value bytes - representing field of type UTF-8 sequence - with a zero length.
UTF_8_1_BYTES501 type byte + 1 value bytes - representing field of type UTF-8 sequence - with a 1 byte length (a 1 byte byte array).
UTF_8_2_BYTES511 type byte + 2 value bytes - representing field of type UTF-8 sequence - with a 2 byte length (a 2 byte byte array).
UTF_8_3_BYTES521 type byte + 3 value bytes - representing field of type UTF-8 sequence - with a 3 byte length (a 3 byte byte array).
UTF_8_4_BYTES531 type byte + 4 value bytes - representing field of type UTF-8 sequence - with a 4 byte length (a 4 byte byte array).
UTF_8_5_BYTES541 type byte + 5 value bytes - representing field of type UTF-8 sequence - with a 5 byte length (a 5 byte byte array).
UTF_8_6_BYTES551 type byte + 6 value bytes - representing field of type UTF-8 sequence - with a 6 byte length (a 6 byte byte array).
UTF_8_7_BYTES561 type byte + 7 value bytes - representing field of type UTF-8 sequence - with a 7 byte length (a 7 byte byte array).
UTF_8_8_BYTES571 type byte + 8 value bytes - representing field of type UTF-8 sequence - with a 8 byte length (a 8 byte byte array).
UTF_8_9_BYTES581 type byte + 9 value bytes - representing field of type UTF-8 sequence - with a 9 byte length (a 9 byte byte array).
UTF_8_10_BYTES591 type byte + 10 value bytes - representing field of type UTF-8 sequence - with a 10 byte length (a 10 byte byte array).
UTF_8_11_BYTES601 type byte + 11 value bytes - representing field of type UTF-8 sequence - with a 11 byte length (a 11 byte byte array).
UTF_8_12_BYTES611 type byte + 12 value bytes - representing field of type UTF-8 sequence - with a 12 byte length (a 12 byte byte array).
UTF_8_13_BYTES621 type byte + 13 value bytes - representing field of type UTF-8 sequence - with a 13 byte length (a 13 byte byte array).
UTF_8_14_BYTES631 type byte + 14 value bytes - representing field of type UTF-8 sequence - with a 14 byte length (a 14 byte byte array).
UTF_8_15_BYTES641 type byte + 15 value bytes - representing field of type UTF-8 sequence - with a 15 byte length (a 15 byte byte array).
UTF_8_1_LENGTH_BYTES651 type byte + 1 length byte + N length bytes - representing field of type UTF-8 sequence with a max length of 2^8-1 bytes.
UTF_8_2_LENGTH_BYTES661 type byte + 2 length byte + N length bytes - representing field of type UTF-8 sequence with a max length of 2^16-1 bytes.
UTF_8_3_LENGTH_BYTES671 type byte + 3 length byte + N length bytes - representing field of type UTF-8 sequence with a max length of 2^24-1 bytes.
UTF_8_4_LENGTH_BYTES681 type byte + 4 length byte + N length bytes - representing field of type UTF-8 sequence with a max length of 2^32-1 bytes.
UTF_8_5_LENGTH_BYTES691 type byte + 5 length byte + N length bytes - representing field of type UTF-8 sequence with a max length of 2^40-1 bytes.
UTF_8_6_LENGTH_BYTES701 type byte + 6 length byte + N length bytes - representing field of type UTF-8 sequence with a max length of 2^48-1 bytes.
UTF_8_7_LENGTH_BYTES711 type byte + 7 length byte + N length bytes - representing field of type UTF-8 sequence with a max length of 2^56-1 bytes.
UTF_8_8_LENGTH_BYTES721 type byte + 8 length byte + N length bytes - representing field of type UTF-8 sequence with a max length of 2^64-1 bytes.
UTC_NULL731 type byte representing a UTC (Universal Time Coordinated) field with the value null.
UTC_0_BYTES741 type byte + 0 value bytes representing a UTC (Universal Time Coordinated) field with an empty value.
UTC_2_BYTES751 type byte + 2 value bytes representing a UTC (Universal Time Coordinated) field with 2 bytes representing a year (0 to 65535).
UTC_3_BYTES761 type byte + 3 value bytes representing a UTC (Universal Time Coordinated) field with 2 bytes representing a year (0 to 65535), 1 byte representing a month.
UTC_4_BYTES771 type byte + 4 value bytes representing a UTC (Universal Time Coordinated) field with 2 bytes representing a year (0 to 65535), 1 byte representing a month, 1 byte representing the date (day of month)
UTC_5_BYTES781 type byte + 5 value bytes representing a UTC (Universal Time Coordinated) field with 2 bytes representing a year (0 to 65535), 1 byte representing a month, 1 byte representing the date (day of month), 1 byte representing hour of day (0-23).
UTC_6_BYTES791 type byte + 6 value bytes representing a UTC (Universal Time Coordinated) field with 2 bytes representing a year (0 to 65535), 1 byte representing a month, 1 byte representing the date (day of month), 1 byte representing hour of day (0-23), 1 byte representing minutes.
UTC_7_BYTES801 type byte + 7 value bytes representing a UTC (Universal Time Coordinated) field with 2 bytes representing a year (0 to 65535), 1 byte representing a month, 1 byte representing the date (day of month), 1 byte representing hour of day (0-23), 1 byte representing minutes, 1 byte representing seconds.
UTC_8_BYTES811 type byte + 8 value bytes representing a UTC (Universal Time Coordinated) field with an 8 byte timestamp in milliseconds (long format).
UTC_9_BYTES821 type byte + 9 value bytes representing a UTC (Universal Time Coordinated) field with 2 bytes representing a year (0 to 65535), 1 byte representing a month, 1 byte representing the date (day of month), 1 byte representing hour of day (0-23), 1 byte representing minutes, 1 byte representing seconds, 2 bytes representing milliseconds.
UTC_9_BYTES831 type byte + 9 value bytes representing a UTC (Universal Time Coordinated) field with 2 bytes representing a year (0 to 65535), 1 byte representing a month, 1 byte representing the date (day of month), 1 byte representing hour of day (0-23), 1 byte representing minutes, 1 byte representing seconds, 3 bytes representing nanoseconds (no milliseconds in this format).
COPY_1_BYTES841 type byte + 1 value byte representing a 1 byte positive integer. The integer is a relative reference to a field found the integer amount of bytes earlier in the Polymorph Data sequence.
COPY_2_BYTES851 type byte + 2 value bytes representing a 2 byte positive integer. The integer is a relative reference to a field found the integer amount of bytes earlier in the Polymorph Data sequence.
COPY_3_BYTES861 type byte + 3 value bytes representing a 3 byte positive integer. The integer is a relative reference to a field found the integer amount of bytes earlier in the Polymorph Data sequence.
COPY_4_BYTES871 type byte + 4 value bytes representing a 4 byte positive integer. The integer is a relative reference to a field found the integer amount of bytes earlier in the Polymorph Data sequence.
COPY_5_BYTES881 type byte + 5 value bytes representing a 5 byte positive integer. The integer is a relative reference to a field found the integer amount of bytes earlier in the Polymorph Data sequence.
COPY_6_BYTES891 type byte + 6 value bytes representing a 6 byte positive integer. The integer is a relative reference to a field found the integer amount of bytes earlier in the Polymorph Data sequence.
COPY_7_BYTES901 type byte + 7 value bytes representing a 7 byte positive integer. The integer is a relative reference to a field found the integer amount of bytes earlier in the Polymorph Data sequence.
COPY_8_BYTES911 type byte + 8 value bytes representing a 8 byte positive integer. The integer is a relative reference to a field found the integer amount of bytes earlier in the Polymorph Data sequence.
REFERENCE_1_BYTES921 type byte + 1 value byte representing a 1 byte positive integer. The integer is a relative reference to a field found the integer amount of bytes earlier in the Polymorph Data sequence.
REFERENCE_2_BYTES931 type byte + 2 value bytes representing a 2 byte positive integer. The integer is a relative reference to a field found the integer amount of bytes earlier in the Polymorph Data sequence.
REFERENCE_3_BYTES941 type byte + 3 value bytes representing a 3 byte positive integer. The integer is a relative reference to a field found the integer amount of bytes earlier in the Polymorph Data sequence.
REFERENCE_4_BYTES951 type byte + 4 value bytes representing a 4 byte positive integer. The integer is a relative reference to a field found the integer amount of bytes earlier in the Polymorph Data sequence.
REFERENCE_5_BYTES961 type byte + 5 value bytes representing a 5 byte positive integer. The integer is a relative reference to a field found the integer amount of bytes earlier in the Polymorph Data sequence.
REFERENCE_6_BYTES971 type byte + 6 value bytes representing a 6 byte positive integer. The integer is a relative reference to a field found the integer amount of bytes earlier in the Polymorph Data sequence.
REFERENCE_7_BYTES981 type byte + 7 value bytes representing a 7 byte positive integer. The integer is a relative reference to a field found the integer amount of bytes earlier in the Polymorph Data sequence.
REFERENCE_8_BYTES991 type byte + 8 value bytes representing a 8 byte positive integer. The integer is a relative reference to a field found the integer amount of bytes earlier in the Polymorph Data sequence.
KEY_NULL 1001 type byte representing a Key field with the value null.
KEY_0_BYTES1011 type byte + 0 value bytes representing a Key field with an empty value (empty byte array).
KEY_1_BYTES1021 type byte + 1 value bytes representing a Key field with a 1 byte value.
KEY_2_BYTES1031 type byte + 2 value bytes representing a Key field with a 2 byte value.
KEY_3_BYTES1041 type byte + 3 value bytes representing a Key field with a 3 byte value.
KEY_4_BYTES1051 type byte + 4 value bytes representing a Key field with a 4 byte value.
KEY_5_BYTES1061 type byte + 5 value bytes representing a Key field with a 5 byte value.
KEY_6_BYTES1071 type byte + 6 value bytes representing a Key field with a 6 byte value.
KEY_7_BYTES1081 type byte + 7 value bytes representing a Key field with a 7 byte value.
KEY_8_BYTES1091 type byte + 8 value bytes representing a Key field with a 8 byte value.
KEY_9_BYTES1101 type byte + 9 value bytes representing a Key field with a 9 byte value.
KEY_10_BYTES1111 type byte + 10 value bytes representing a Key field with a 10 byte value.
KEY_11_BYTES1121 type byte + 11 value bytes representing a Key field with a 11 byte value.
KEY_12_BYTES1131 type byte + 12 value bytes representing a Key field with a 12 byte value.
KEY_13_BYTES1141 type byte + 13 value bytes representing a Key field with a 13 byte value.
KEY_14_BYTES1151 type byte + 14 value bytes representing a Key field with a 14 byte value.
KEY_15_BYTES1161 type byte + 15 value bytes representing a Key field with a 15 byte value.
KEY_1_LENGTH_BYTES1171 type byte + 1 length byte + N value bytes representing a Key field with an N byte value.
KEY_2_LENGTH_BYTES1181 type byte + 2 length bytes + N value bytes representing a Key field with an N byte value.
OBJECT_NULL1191 type byte representing a field of type Object with the value null.
OBJECT_1_LENGTH_BYTES1201 type byte + 1 length byte + N value bytes (fields nested inside the Object field).
OBJECT_2_LENGTH_BYTES1211 type byte + 2 length byte + N value bytes (fields nested inside the Object field).
OBJECT_3_LENGTH_BYTES1221 type byte + 3 length byte + N value bytes (fields nested inside the Object field).
OBJECT_4_LENGTH_BYTES1231 type byte + 4 length byte + N value bytes (fields nested inside the Object field).
OBJECT_5_LENGTH_BYTES1241 type byte + 5 length byte + N value bytes (fields nested inside the Object field).
OBJECT_6_LENGTH_BYTES1251 type byte + 6 length byte + N value bytes (fields nested inside the Object field).
OBJECT_7_LENGTH_BYTES1261 type byte + 7 length byte + N value bytes (fields nested inside the Object field).
OBJECT_8_LENGTH_BYTES1271 type byte + 8 length byte + N value bytes (fields nested inside the Object field).
TABLE_NULL1281 type byte representing a field of type Table with the value null.
TABLE_1_LENGTH_BYTES1291 type byte + 1 length byte + N value bytes (fields nested inside the Table field).
TABLE_2_LENGTH_BYTES1301 type byte + 2 length byte + N value bytes (fields nested inside the Table field).
TABLE_3_LENGTH_BYTES1311 type byte + 3 length byte + N value bytes (fields nested inside the Table field).
TABLE_4_LENGTH_BYTES1321 type byte + 4 length byte + N value bytes (fields nested inside the Table field).
TABLE_5_LENGTH_BYTES1331 type byte + 5 length byte + N value bytes (fields nested inside the Table field).
TABLE_6_LENGTH_BYTES1341 type byte + 6 length byte + N value bytes (fields nested inside the Table field).
TABLE_7_LENGTH_BYTES1351 type byte + 7 length byte + N value bytes (fields nested inside the Table field).
TABLE_8_LENGTH_BYTES1361 type byte + 8 length byte + N value bytes (fields nested inside the Table field).

Boolean Field Type

The Boolean field types are used to encode boolean values such as true and false. It is also possible to encode a null value of type Boolean.

There are only 3 Boolean field types. One type that represents a null value (0), one type that represents the value true (1), and one type that represents the value false (2).

The Boolean fields have no value bytes. There is only the type byte. That is enough to encode the 3 different Boolean values possible (null, true, false).

Boolean Field Encoding Examples

The following encoding examples are shown using hexadecimal notation - meaning 2 digits per byte, and the first (leftmost) digit is the most significant 4 bits of the byte.

A Boolean null encoded:

 00

A Boolean true encoded:

 01

A Boolean false encoded:

 02

Integer Field Type

The Integer field types are used to encode positive and negative integers efficiently. There is also a field type to encode a null Integer field. The positive integer types use only the number of bytes necessary to encode the concrete integer value. The negative integer types encode the value as a positive number, and thus uses only the number of bytes necessary to encode the value that is needed to encode its positive value. After reading a negative value you should negate it (the Polymorph Data APIs do this for you automatically).

Here are the integer field types:

Field TypeType Code
INT_NULL3A single byte with the value 3 - representing a null value of type integer.
INT_POS_1_BYTES4
INT_POS_2_BYTES5
INT_POS_3_BYTES6
INT_POS_4_BYTES7
INT_POS_5_BYTES8
INT_POS_6_BYTES9
INT_POS_7_BYTES10
INT_POS_8_BYTES11
INT_NEG_1_BYTES12
INT_NEG_2_BYTES13
INT_NEG_3_BYTES14
INT_NEG_4_BYTES15
INT_NEG_5_BYTES16
INT_NEG_6_BYTES17
INT_NEG_7_BYTES18
INT_NEG_8_BYTES19

Integer Field Encoding Examples

The following encoding examples are shown using hexadecimal notation - meaning 2 digits per byte, and the first (leftmost) digit is the most significant 4 bits of the byte.

Integer null encoded:

    03

Integer value 1 encoded:

    04 01

Integer value 65535 encoded:

    05 FF FF

Integer value -1 encoded:

    0C 01

Integer value -65535 encoded:

    0D FF FF

Float Field Type

The Float field type is used to represent floating point numbers of either 4 or 8 bytes - corresponding to Java's float and double types. You can also encode a null of type Float if you need to.

Here are the Float field types:

Field TypeType Code
FLOAT_NULL20
FLOAT_4_BYTES21
FLOAT_8_BYTES22

Bytes Field Type

The Bytes field type is used to represent sequences of raw bytes - such as a byte array or the contents of a file.

The Bytes field types are:

Field TypeType Code
BYTES_NULL231 type byte representing a field of type byte sequence - with a null value.
BYTES_0_BYTES241 type byte + 0 value bytes - representing field of type byte sequence - with a zero length.
BYTES_1_BYTES251 type byte + 1 value bytes - representing field of type byte sequence - with a 1 byte length (a 1 byte byte array).
BYTES_2_BYTES261 type byte + 2 value bytes - representing field of type byte sequence - with a 2 byte length (a 2 byte byte array).
BYTES_3_BYTES271 type byte + 3 value bytes - representing field of type byte sequence - with a 3 byte length (a 3 byte byte array).
BYTES_4_BYTES281 type byte + 4 value bytes - representing field of type byte sequence - with a 4 byte length (a 4 byte byte array).
BYTES_5_BYTES291 type byte + 5 value bytes - representing field of type byte sequence - with a 5 byte length (a 5 byte byte array).
BYTES_6_BYTES301 type byte + 6 value bytes - representing field of type byte sequence - with a 6 byte length (a 6 byte byte array).
BYTES_7_BYTES311 type byte + 7 value bytes - representing field of type byte sequence - with a 7 byte length (a 7 byte byte array).
BYTES_8_BYTES321 type byte + 8 value bytes - representing field of type byte sequence - with a 8 byte length (a 8 byte byte array).
BYTES_9_BYTES331 type byte + 9 value bytes - representing field of type byte sequence - with a 9 byte length (a 9 byte byte array).
BYTES_10_BYTES341 type byte + 10 value bytes - representing field of type byte sequence - with a 10 byte length (a 10 byte byte array).
BYTES_11_BYTES351 type byte + 11 value bytes - representing field of type byte sequence - with a 11 byte length (a 11 byte byte array).
BYTES_12_BYTES361 type byte + 12 value bytes - representing field of type byte sequence - with a 12 byte length (a 12 byte byte array).
BYTES_13_BYTES371 type byte + 13 value bytes - representing field of type byte sequence - with a 13 byte length (a 13 byte byte array).
BYTES_14_BYTES381 type byte + 14 value bytes - representing field of type byte sequence - with a 14 byte length (a 14 byte byte array).
BYTES_15_BYTES391 type byte + 15 value bytes - representing field of type byte sequence - with a 15 byte length (a 15 byte byte array).
BYTES_1_LENGTH_BYTES401 type byte + 1 length byte + N length bytes - representing field of type byte sequence with a max length of 2^8-1 bytes.
BYTES_2_LENGTH_BYTES411 type byte + 2 length byte + N length bytes - representing field of type byte sequence with a max length of 2^16-1 bytes.
BYTES_3_LENGTH_BYTES421 type byte + 3 length byte + N length bytes - representing field of type byte sequence with a max length of 2^24-1 bytes.
BYTES_4_LENGTH_BYTES431 type byte + 4 length byte + N length bytes - representing field of type byte sequence with a max length of 2^32-1 bytes.
BYTES_5_LENGTH_BYTES441 type byte + 5 length byte + N length bytes - representing field of type byte sequence with a max length of 2^40-1 bytes.
BYTES_6_LENGTH_BYTES451 type byte + 5 length byte + N length bytes - representing field of type byte sequence with a max length of 2^48-1 bytes.
BYTES_7_LENGTH_BYTES461 type byte + 5 length byte + N length bytes - representing field of type byte sequence with a max length of 2^56-1 bytes.
BYTES_8_LENGTH_BYTES471 type byte + 5 length byte + N length bytes - representing field of type byte sequence with a max length of 2^64-1 bytes.

Bytes Field Encoding Examples

The following encoding examples are shown using hexadecimal notation - meaning 2 digits per byte, and the first (leftmost) digit is the most significant 4 bits of the byte.

A null Bytes field:

    17

A 3 byte long Bytes field:

    1B F3 34 A1

A 16 byte long Bytes field - (with 1 length byte):

    28 10 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

UTF-8 Field Type

The UTF-8 Field type is used to represent sequences of UTF-8 characters. The UTF-8 characters are just stored as bytes - just like in a Bytes field - but the UTF-8 field type tells you that these bytes are to be interpreted as UTF-8 characters.

Here are the UTF-8 field types:

Field TypeType Code
UTF_8_NULL48
UTF_8_0_BYTES49
UTF_8_1_BYTES50
UTF_8_2_BYTES51
UTF_8_3_BYTES52
UTF_8_4_BYTES53
UTF_8_5_BYTES54
UTF_8_6_BYTES55
UTF_8_7_BYTES56
UTF_8_8_BYTES57
UTF_8_9_BYTES58
UTF_8_10_BYTES59
UTF_8_11_BYTES60
UTF_8_12_BYTES61
UTF_8_13_BYTES62
UTF_8_14_BYTES63
UTF_8_15_BYTES64
UTF_8_1_LENGTH_BYTES65
UTF_8_2_LENGTH_BYTES66
UTF_8_3_LENGTH_BYTES67
UTF_8_4_LENGTH_BYTES68
UTF_8_5_LENGTH_BYTES69
UTF_8_6_LENGTH_BYTES70
UTF_8_7_LENGTH_BYTES71
UTF_8_8_LENGTH_BYTES72

UTF-8 Field Encoding Examples

A null UTF-8 field:

    30

A 3 byte long UTF-8 field:

    34 41 42 43

A 16 byte long UTF-8 field - (with 1 length byte):

    41 10 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50

UTC Field Type

Copy Field Type

Reference Field Type

Key Field Type

The Key field type is used to represent a "key" in a hashtable, a property name inside an Object field, or a column name inside a Table field.

Key Field Encoding Examples

Here are a few Key field encoding examples - in hexadecimal encoding.

A key field with 4 bytes inside (Ascii values of A, B, C and D):

    69 41 42 43 44

Object Field Type

The Object field type is used to represent objects with named properties + property values, or maps with keys and values. The Object field type is intended to contain other Polymorph Data fields inside it. These nested fields make up the property names and values.

A property name inside an Object field is represented by a Key field + some other field that makes up the value. For instance, an int property would consist of a Key field with the property name, and an Int field with the value.

You can nest Object fields (and Table fields) inside Object fields, to create bigger object graphs.

Object Field Encoding Examples

Here are some examples of encoding a Polymorph Data Object field. The example uses hexadecimal notation.

Here is a null Object field:

77

Here is an Object with 1 length byte, plus a single property (Key + Int field):

78 05    63 66 31    04 FF

Table Field Type

The Table field is used to represent tabular data - similar to what you can represent in a CSV file or HTML table.

The Table field consists of the Table type code, the length bytes, the number of rows in the table (as an Int field), the Key fields for the column headers, and then all the column value fields - for all rows - with no row separator field.

The number of columns per row is marked by the series of Key fields for the column headers. If there are 3 Key fields in that series, each row has 3 columns.

The length (in bytes) of the Table field should include all nested fields, including the row count Int field and the Key fields for the columns, and of course the row field values.

Table Field Encoding Examples

An example of a null Table field:

80

Here is a Table field with 1 length byte, 2 rows, and 2 columns (2 Key fields).

81 0F
   02
   63 66 31   63 66 32
   04 FF      04 FE
   04 FD      04 FC

Jakob Jenkov

Featured Videos

Java ConcurrentMap + ConcurrentHashMap

Java Generics

Java ForkJoinPool

P2P Networks Introduction

















Close TOC
All Tutorial Trails
All Trails
Table of contents (TOC) for this tutorial trail
Trail TOC
Table of contents (TOC) for this tutorial
Page TOC
Previous tutorial in this tutorial trail
Previous
Next tutorial in this tutorial trail
Next