@Override
  public void write(Bytes out, @NotNull CharSequence s) {
    if (s == null) {
      out.writeStopBit(NULL_LENGTH);
      return;
    } else if (s.length() == 0) {
      out.writeStopBit(0);
      return;
    }
    // write the total length.
    int length = s.length();
    out.writeStopBit(length);

    long position = out.writePosition();
    out.writeInt(0);
    DataOutputStream dos =
        new DataOutputStream(
            new BufferedOutputStream(new DeflaterOutputStream(out.outputStream())));
    try {
      for (int i = 0; i < s.length(); i++) {
        dos.write(s.charAt(i));
      }
      dos.close();
    } catch (IOException e) {
      throw new IORuntimeException(e);
    }
    out.writeInt(position, (int) (out.writePosition() - position - 4));
  }
 @Override
 public void write(Bytes out, @NotNull Integer toWrite) {
   out.writeInt(toWrite);
 }
 @Override
 public void write(@NotNull Bytes out, long size, @NotNull Integer toWrite) {
   out.writeInt(toWrite);
 }