What is wrong in convert code from js to swift?

I have a js code. I’m trying to convert it to swift

const writeUInt64 = value => {
  const result = [];
  let index = 0;
  while (value > BigInt(rest)) {
    result[index] = BigInt(msg).or(value.and(BigInt(rest))).toJSNumber();
    value = value.shiftRight(7);
    index += 1;
  }

  result[Number(index)] = value.toJSNumber();

  return Buffer.from(result);
};

Need to convert this code to swift. My try:

internal func writeUInt64(_ value: UInt64) -> [UInt8] {
    var result = [UInt8]()
    var value = value
    while (value > UInt64(rest)) {
        result.append(msg | UInt8((Int64((value & UInt64(rest))) >>> 0)))
        value = UInt64(Int64(value) >>> 7)
    }

    result.append(UInt8(value))
    
    return result
};

It is correct ? can you help please