code: public byte[] toByteArray() {
      final int preLongs, outBytes;
      final boolean empty = itemsSeen_ == 0;
      final int numItems = (int) Math.min(reservoirSize_, itemsSeen_);
  
      if (empty) {
        preLongs = 1;
        outBytes = 8;
      } else {
        preLongs = Family.RESERVOIR.getMaxPreLongs();
        outBytes = (preLongs + numItems) << 3; // for longs, we know the size
      }
      final byte[] outArr = new byte[outBytes];
      final WritableMemory mem = WritableMemory.wrap(outArr);
  
      // build first preLong
      PreambleUtil.insertPreLongs(mem, preLongs);                 // Byte 0
      PreambleUtil.insertLgResizeFactor(mem, rf_.lg());
      PreambleUtil.insertSerVer(mem, SER_VER);                    // Byte 1
      PreambleUtil.insertFamilyID(mem, Family.RESERVOIR.getID()); // Byte 2
      if (empty) {
        PreambleUtil.insertFlags(mem, EMPTY_FLAG_MASK);           // Byte 3
      } else {
        PreambleUtil.insertFlags(mem, 0);
      }
      PreambleUtil.insertK(mem, reservoirSize_);                  // Bytes 4-7
  
      if (!empty) {
        // second preLong, only if non-empty
        PreambleUtil.insertN(mem, itemsSeen_);
  
        // insert the serialized samples, offset by the preamble size
        final int preBytes = preLongs << 3;
        mem.putLongArray(preBytes, data_, 0, numItems);
      }
  
      return outArr;
    }
docs: Returns a byte array representation of this sketch
  
  @return a byte array representation of this sketch