public static int encode(
      final MutableDirectBuffer mutableDirectBuffer,
      final int offset,
      int flags,
      final int keepaliveInterval,
      final int maxLifetime,
      final String metadataMimeType,
      final String dataMimeType,
      final ByteBuffer metadata,
      final ByteBuffer data) {
    final int frameLength =
        computeFrameLength(metadataMimeType, dataMimeType, metadata.remaining(), data.remaining());

    int length =
        FrameHeaderFlyweight.encodeFrameHeader(
            mutableDirectBuffer, offset, frameLength, flags, FrameType.SETUP, 0);

    mutableDirectBuffer.putInt(
        offset + VERSION_FIELD_OFFSET, CURRENT_VERSION, ByteOrder.BIG_ENDIAN);
    mutableDirectBuffer.putInt(
        offset + KEEPALIVE_INTERVAL_FIELD_OFFSET, keepaliveInterval, ByteOrder.BIG_ENDIAN);
    mutableDirectBuffer.putInt(
        offset + MAX_LIFETIME_FIELD_OFFSET, maxLifetime, ByteOrder.BIG_ENDIAN);

    length += BitUtil.SIZE_OF_INT * 3;

    length += putMimeType(mutableDirectBuffer, offset + length, metadataMimeType);
    length += putMimeType(mutableDirectBuffer, offset + length, dataMimeType);

    length +=
        FrameHeaderFlyweight.encodeMetadata(mutableDirectBuffer, offset, offset + length, metadata);
    length += FrameHeaderFlyweight.encodeData(mutableDirectBuffer, offset + length, data);

    return length;
  }
  public static int encode(
      final MutableDirectBuffer mutableDirectBuffer,
      final int offset,
      final int ttl,
      final int numRequests,
      final ByteBuffer metadata) {
    final int frameLength = computeFrameLength(metadata.remaining());

    int length =
        FrameHeaderFlyweight.encodeFrameHeader(
            mutableDirectBuffer, offset, frameLength, 0, FrameType.LEASE, 0);

    mutableDirectBuffer.putInt(offset + TTL_FIELD_OFFSET, ttl, ByteOrder.BIG_ENDIAN);
    mutableDirectBuffer.putInt(
        offset + NUM_REQUESTS_FIELD_OFFSET, numRequests, ByteOrder.BIG_ENDIAN);

    length += BitUtil.SIZE_OF_INT * 2;
    length +=
        FrameHeaderFlyweight.encodeMetadata(mutableDirectBuffer, offset, offset + length, metadata);

    return length;
  }