@mega-yfue/eufy-sdk / encodeVarint
Function: encodeVarint()
ts
function encodeVarint(value): number[];Encode an unsigned integer as a base-128 varint, low group first with the continuation bit set on every group but the last.
Takes a number and rejects anything that is not a non-negative safe integer, rather than silently truncating: JavaScript's bitwise operators are 32-bit, so a naive shift-based loop wraps above 2³¹ and would emit a plausible-looking frame for the wrong value. Division keeps the full safe-integer range available and the guard makes the boundary explicit instead of surprising.
Parameters
value
number
Returns
number[]