code: public IoBuffer encodePing(Ping ping) {
          int len;
          short type = ping.getEventType();
          switch (type) {
              case Ping.CLIENT_BUFFER:
                  len = 10;
                  break;
              case Ping.PONG_SWF_VERIFY:
                  len = 44;
                  break;
              default:
                  len = 6;
          }
          final IoBuffer out = IoBuffer.allocate(len);
          out.putShort(type);
          switch (type) {
              case Ping.STREAM_BEGIN:
              case Ping.STREAM_PLAYBUFFER_CLEAR:
              case Ping.STREAM_DRY:
              case Ping.RECORDED_STREAM:
              case Ping.PING_CLIENT:
              case Ping.PONG_SERVER:
              case Ping.BUFFER_EMPTY:
              case Ping.BUFFER_FULL:
                  out.putInt(ping.getValue2().intValue());
                  break;
              case Ping.CLIENT_BUFFER:
                  if (ping instanceof SetBuffer) {
                      SetBuffer setBuffer = (SetBuffer) ping;
                      out.putInt(setBuffer.getStreamId());
                      out.putInt(setBuffer.getBufferLength());
                  } else {
                      out.putInt(ping.getValue2().intValue());
                      out.putInt(ping.getValue3());
                  }
                  break;
              case Ping.PING_SWF_VERIFY:
                  break;
              case Ping.PONG_SWF_VERIFY:
                  out.put(((SWFResponse) ping).getBytes());
                  break;
          }
          // this may not be needed anymore
          if (ping.getValue4() != Ping.UNDEFINED) {
              out.putInt(ping.getValue4());
          }
          return out;
      }
docs: {@inheritDoc}