encodeStateVectorV2 = (doc, encoder = new DSEncoderV2()) => {
  if (doc instanceof Map) {
    writeStateVector(encoder, doc);
  } else {
    writeDocumentStateVector(encoder, doc);
  }

  return encoder.toUint8Array();
}
Encode State as Uint8Array.

@param {Doc|Map<number,number>} doc
@param {DSEncoderV1 | DSEncoderV2} [encoder]
@return {Uint8Array}

@function