0

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.

Chiru
  • 141
  • 6

1 Answers1

1

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.
Pieter Wuille
  • 98,249
  • 9
  • 183
  • 287