encodeVarint static method
Implementation
static BuBytes encodeVarint(int value) {
if (value < 253) {
return BuBytes([value]);
} else if (value < 0x10000) {
final bytes = BuBytes.zero(3);
bytes[0] = 0xfd;
BinaryOps.writeUint16LE(value, bytes, 1);
return bytes;
} else if (value < 0x100000000) {
final bytes = BuBytes.zero(5);
bytes[0] = 0xfe;
BinaryOps.writeUint32LE(value, bytes, 1);
return bytes;
} else {
throw CoreErrors.invalidOperationArguments(
"encodeVarint",
name: "byteint",
reason: "Value is too large.",
);
}
}