docs: @SuppressWarnings("null")
    @Override
    public byte[] toByteArray() {
      int summariesBytesLength = 0;
      byte[][] summariesBytes = null;
      final int count = getRetainedEntries();
      if (count > 0) {
        summariesBytes = new byte[count][];
        for (int i = 0; i < count; i++) {
          summariesBytes[i] = summaries_[i].toByteArray();
          summariesBytesLength += summariesBytes[i].length;
        }
      }
  
      int sizeBytes =
          Byte.BYTES // preamble longs
        + Byte.BYTES // serial version
        + Byte.BYTES // family id
        + Byte.BYTES // sketch type
        + Byte.BYTES; // flags
      final boolean isThetaIncluded = theta_ < Long.MAX_VALUE;
      if (isThetaIncluded) {
        sizeBytes += Long.BYTES; // theta
      }
      if (count > 0) {
        sizeBytes +=
          + Integer.BYTES // count
          + (Long.BYTES * count) + summariesBytesLength;
      }
      final byte[] bytes = new byte[sizeBytes];
      int offset = 0;
      bytes[offset++] = PREAMBLE_LONGS;
      bytes[offset++] = serialVersionUID;
      bytes[offset++] = (byte) Family.TUPLE.getID();
      bytes[offset++] = (byte) SerializerDeserializer.SketchType.CompactSketch.ordinal();
      final boolean isBigEndian = ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN);
      bytes[offset++] = (byte) (
        (isBigEndian ? 1 << Flags.IS_BIG_ENDIAN.ordinal() : 0)
        | (isEmpty_ ? 1 << Flags.IS_EMPTY.ordinal() : 0)
        | (count > 0 ? 1 << Flags.HAS_ENTRIES.ordinal() : 0)
        | (isThetaIncluded ? 1 << Flags.IS_THETA_INCLUDED.ordinal() : 0)
      );
      if (isThetaIncluded) {
        ByteArrayUtil.putLongLE(bytes, offset, theta_);
        offset += Long.BYTES;
      }
      if (count > 0) {
        ByteArrayUtil.putIntLE(bytes, offset, getRetainedEntries());
        offset += Integer.BYTES;
        for (int i = 0; i < count; i++) {
          ByteArrayUtil.putLongLE(bytes, offset, keys_[i]);
          offset += Long.BYTES;
        }
        for (int i = 0; i < count; i++) {
          System.arraycopy(summariesBytes[i], 0, bytes, offset, summariesBytes[i].length);
          offset += summariesBytes[i].length;
        }
      }
      return bytes;
    }