encodeVarint function
Encodes a non-negative integer as a varint (unsigned LEB128).
Implementation
Uint8List encodeVarint(int value) {
if (value < 0) {
throw ArgumentError('Value must be non-negative');
}
final bytes = <int>[];
do {
var byte = value & 0x7F;
value >>= 7;
if (value > 0) {
byte |= 0x80; // Set continuation bit
}
bytes.add(byte);
} while (value > 0);
return Uint8List.fromList(bytes);
}