#include <iostream>
using namespace std;
int varintEncode(int n, unsigned char *bytes) {
int idx = 0;
while (true) {
if ((n & ~0x7f) == 0) {
bytes[idx++] = (char) n;
break;
} else {
bytes[idx++] = ((unsigned char) ((n & 0x7f) | 0x80));
n = n >> 7;
}
}
return idx;
}
int varintDecode(unsigned char *bytes) {
int idx = 0;
int shift = 0;
int result = 0;
while (true) {
unsigned char b = bytes[idx++];
result |= ((b & 0x7f) << shift);
if ((b >> 7) == 0) {
break;
}
shift += 7;
}
return result;
}
int main() {
for (int i = 1; i < 1000000; i++) {
unsigned char bytes[5]{0};
if (i != varintDecode(bytes)) {
cout << "decode error" << endl;
}
}
}