code: public ByteString toByteString() {
      try {
        final ByteString.CodedBuilder out =
          ByteString.newCodedBuilder(getSerializedSize());
        writeTo(out.getCodedOutput());
        return out.build();
      } catch (final IOException e) {
        throw new RuntimeException(
          "Serializing to a ByteString threw an IOException (should " +
          "never happen).", e);
      }
    }
docs: Serializes the message to a {@code ByteString} and returns it. This is
  just a trivial wrapper around {@link #writeTo(CodedOutputStream)}.