Skip to main content

Module varint

Module varint 

Source
Expand description

Variable-length integer encoding (Bitcoin protocol)

Bitcoin uses a variable-length integer encoding where:

  • Values < 0xfd: encoded as single byte
  • Values < 0xffff: encoded as 0xfd + 2 bytes (little-endian)
  • Values < 0xffffffff: encoded as 0xfe + 4 bytes (little-endian)
  • Values >= 0xffffffff: encoded as 0xff + 8 bytes (little-endian)

Constants§

MAX_VARINT
Maximum value for a varint (2^64 - 1)

Functions§

read_varint
Read a variable-length integer from bytes
varint_size
Get the encoded size of a varint without writing it
write_varint
Write a variable-length integer to bytes