Jelajahi Sumber

Specify when integers and floats are 32 and when 64 bits (#4893)

Co-authored-by: Hugo Locurcio <[email protected]>
Simone Gianni 4 tahun lalu
induk
melakukan
3f60675227
1 mengubah file dengan 29 tambahan dan 1 penghapusan
  1. 29 1
      tutorials/io/binary_serialization_api.rst

+ 29 - 1
tutorials/io/binary_serialization_api.rst

@@ -17,7 +17,13 @@ Packet specification
 
 
 The packet is designed to be always padded to 4 bytes. All values are
 The packet is designed to be always padded to 4 bytes. All values are
 little-endian-encoded. All packets have a 4-byte header representing an
 little-endian-encoded. All packets have a 4-byte header representing an
-integer, specifying the type of data:
+integer, specifying the type of data.
+
+The lowest value two bytes are used to determine the type, while the highest value
+two bytes contain flags::
+
+    base_type = val & 0xFFFF;
+    flags = val >> 16;
 
 
 +--------+--------------------------+
 +--------+--------------------------+
 | Type   | Value                    |
 | Type   | Value                    |
@@ -105,6 +111,17 @@ precision.
 2: :ref:`int<class_int>`
 2: :ref:`int<class_int>`
 ~~~~~~~~~~~~~~~~~~~~~~~~
 ~~~~~~~~~~~~~~~~~~~~~~~~
 
 
+If no flags are set (flags == 0), the integer is sent as a 32 bit integer:
+
++----------+-------+-----------+--------------------------+
+| Offset   | Len   | Type      | Description              |
++==========+=======+===========+==========================+
+| 4        | 4     | Integer   | 32-bit signed integer    |
++----------+-------+-----------+--------------------------+
+
+If flag ``ENCODE_FLAG_64`` is set (``flags & 1 == 1``), the integer is sent as 
+a 64-bit integer:
+
 +----------+-------+-----------+--------------------------+
 +----------+-------+-----------+--------------------------+
 | Offset   | Len   | Type      | Description              |
 | Offset   | Len   | Type      | Description              |
 +==========+=======+===========+==========================+
 +==========+=======+===========+==========================+
@@ -114,6 +131,17 @@ precision.
 3: :ref:`float<class_float>`
 3: :ref:`float<class_float>`
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 
+If no flags are set (flags == 0), the float is sent as a 32 bit single precision:
+
++----------+-------+---------+-----------------------------------+
+| Offset   | Len   | Type    | Description                       |
++==========+=======+=========+===================================+
+| 4        | 4     | Float   | IEEE 754 single-precision float   |
++----------+-------+---------+-----------------------------------+
+
+If flag ``ENCODE_FLAG_64`` is set (``flags & 1 == 1``), the float is sent as 
+a 64-bit double precision number:
+
 +----------+-------+---------+-----------------------------------+
 +----------+-------+---------+-----------------------------------+
 | Offset   | Len   | Type    | Description                       |
 | Offset   | Len   | Type    | Description                       |
 +==========+=======+=========+===================================+
 +==========+=======+=========+===================================+