user119698: I'm trying to understand the structure of the service and network bytes for compact sizes.
what's specification for compressing the bytes for example in addrv2 message encoding?
thanks.

user208: The compactsize encoding is a variable-length encoding for integers between 0 and 264 - 1 inclusive.

Numbers in [0,253) are stored a a single byte, encoding the value directly.
Numbers in [253,216) are stored as 3 bytes: 0xFD + the number in 16-bit little-endian format.
Numbers in [216,232) are stored as 5 bytes: 0xFE + the number in 32-bit little-endian format.
Numbers in [232,264) are stored as 9 bytes: 0xFF + the number in 64-bit little-endian format.


119698: <p>I'm trying to understand the structure of the service and network bytes for compact sizes.</p>
<p>what's specification for compressing the bytes for example in addrv2 message encoding?</p>
<p>thanks.</p>
 208: <p>The compactsize encoding is a variable-length encoding for integers between 0 and 2<sup>64</sup> - 1 inclusive.</p>
<ul>
<li>Numbers in [0,253) are stored a a single byte, encoding the value directly.</li>
<li>Numbers in [253,2<sup>16</sup>) are stored as 3 bytes: 0xFD + the number in 16-bit little-endian format.</li>
<li>Numbers in [2<sup>16</sup>,2<sup>32</sup>) are stored as 5 bytes: 0xFE + the number in 32-bit little-endian format.</li>
<li>Numbers in [2<sup>32</sup>,2<sup>64</sup>) are stored as 9 bytes: 0xFF + the number in 64-bit little-endian format.</li>
</ul>
