Expand description
Bitcoin VarInt encoding/decoding
VarInt (Variable Integer) is a compact encoding for integers used throughout Bitcoin’s wire format. It uses 1-9 bytes depending on the value.
Encoding rules:
- If value < 0xfd: single byte
- If value <= 0xffff: 0xfd prefix + 2 bytes (little-endian)
- If value <= 0xffffffff: 0xfe prefix + 4 bytes (little-endian)
- Otherwise: 0xff prefix + 8 bytes (little-endian)
This must match consensus’s CVarInt implementation exactly.
Enums§
- VarInt
Error - Error type for VarInt encoding/decoding failures
Functions§
- decode_
varint - Decode a Bitcoin VarInt from bytes
- encode_
varint - Encode a u64 value as a Bitcoin VarInt