@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 A toWrite) {
   out.writeUtf8(toWrite.str_);
   if (toWrite.list_ != null) {
     int size = toWrite.list_.size();
     out.writeStopBit(size);
     for (int i = 0; i < size; i++) {
       toWrite.list_.get(i).writeMarshallable(out);
     }
   } else {
     out.writeStopBit(-1);
   }
 }