encodeStateVectorFromUpdateV2 = (update, YEncoder = DSEncoderV2, YDecoder = UpdateDecoderV2) => {
  const encoder = new YEncoder();
  const updateDecoder = new LazyStructReader(new YDecoder(decoding.createDecoder(update)), false);
  let curr = updateDecoder.curr;

  if (curr !== null) {
    let size = 0;
    let currClient = curr.id.client;
    let stopCounting = curr.id.clock !== 0; // must start at 0

    let currClock = stopCounting ? 0 : curr.id.clock + curr.length;

    for (; curr !== null; curr = updateDecoder.next()) {
      if (currClient !== curr.id.client) {
        if (currClock !== 0) {
          size++; // We found a new client
          // write what we have to the encoder

          encoding.writeVarUint(encoder.restEncoder, currClient);
          encoding.writeVarUint(encoder.restEncoder, currClock);
        }

        currClient = curr.id.client;
        currClock = 0;
        stopCounting = curr.id.clock !== 0;
      } // we ignore skips


      if (curr.constructor === Skip) {
        stopCounting = true;
      }

      if (!stopCounting) {
        currClock = curr.id.clock + curr.length;
      }
    } // write what we have


    if (currClock !== 0) {
      size++;
      encoding.writeVarUint(encoder.restEncoder, currClient);
      encoding.writeVarUint(encoder.restEncoder, currClock);
    } // prepend the size of the state vector


    const enc = encoding.createEncoder();
    encoding.writeVarUint(enc, size);
    encoding.writeBinaryEncoder(enc, encoder.restEncoder);
    encoder.restEncoder = enc;
    return encoder.toUint8Array();
  } else {
    encoding.writeVarUint(encoder.restEncoder, 0);
    return encoder.toUint8Array();
  }
}
@param {Uint8Array} update
@param {typeof DSEncoderV1 | typeof DSEncoderV2} YEncoder
@param {typeof UpdateDecoderV1 | typeof UpdateDecoderV2} YDecoder
@return {Uint8Array}