param val export function encodeVarInt ( i ) { if ( i < BigInt ( "0xfd" ) ) { return Buffer . from ( [ Number ( i ) ] ) ; } else if ( i < BigInt ( "0x10000" ) ) { const buf = Buffer . alloc ( 3 ) ; buf [ 0 ] = 0xfd ; buf . writeUInt16LE ( Number ( i ) , 1 ) ; return buf ; } else if ( i < BigInt ( "0x100000000" ) ) { const buf = Buffer . alloc ( 5 ) ; buf [ 0 ] = 0xfe ; buf . writeUInt32LE ( Number ( i ) , 1 ) ; return buf ; } else if ( i < BigInt ( "0x10000000000000000" ) ) { const buf = Buffer . alloc ( 9 ) ; buf [ 0 ] = 0xff ; buf . writeBigUInt64LE ( BigInt ( i ) , 1 ) ; return buf ; } else { throw new Error ( `Integer too large ${ i }` ) ; } }