class ClusterStateResponse extends TransportResponse {

    private final ClusterName clusterName;
    private final ClusterState clusterState;
    private boolean waitForTimedOut = false;

    public ClusterStateResponse(ClusterName clusterName, ClusterState clusterState, boolean waitForTimedOut) {
        this.clusterName = clusterName;
        this.clusterState = clusterState;
        this.waitForTimedOut = waitForTimedOut;
    }

    /**
     * The requested cluster state.  Only the parts of the cluster state that were
     * requested are included in the returned {@link ClusterState} instance.
     */
    public ClusterState getState() {
        return this.clusterState;
    }

    /**
     * The name of the cluster.
     */
    public ClusterName getClusterName() {
        return this.clusterName;
    }

    /**
     * Returns whether the request timed out waiting for a cluster state with a metadata version equal or
     * higher than the specified metadata.
     */
    public boolean isWaitForTimedOut() {
        return waitForTimedOut;
    }

    public ClusterStateResponse(StreamInput in) throws IOException {
        clusterName = new ClusterName(in);
        if (in.getVersion().onOrAfter(Version.V_4_4_0)) {
            clusterState = in.readOptionalWriteable(innerIn -> ClusterState.readFrom(innerIn, null));
            waitForTimedOut = in.readBoolean();
        } else {
            clusterState = ClusterState.readFrom(in, null);
        }
    }

    @Override
    public void writeTo(StreamOutput out) throws IOException {<FILL_FUNCTION_BODY>}

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ClusterStateResponse response = (ClusterStateResponse) o;
        return waitForTimedOut == response.waitForTimedOut &&
            Objects.equals(clusterName, response.clusterName) &&
            // Best effort. Only compare cluster state version and master node id,
            // because cluster state doesn't implement equals()
            Objects.equals(getVersion(clusterState), getVersion(response.clusterState)) &&
            Objects.equals(getMasterNodeId(clusterState), getMasterNodeId(response.clusterState));
    }

    @Override
    public int hashCode() {
        // Best effort. Only use cluster state version and master node id,
        // because cluster state doesn't implement  hashcode()
        return Objects.hash(
            clusterName,
            getVersion(clusterState),
            getMasterNodeId(clusterState),
            waitForTimedOut
        );
    }

    private static String getMasterNodeId(ClusterState clusterState) {
        if (clusterState == null) {
            return null;
        }
        DiscoveryNodes nodes = clusterState.nodes();
        if (nodes != null) {
            return nodes.getMasterNodeId();
        } else {
            return null;
        }
    }

    private static Long getVersion(ClusterState clusterState) {
        if (clusterState != null) {
            return clusterState.version();
        } else {
            return null;
        }
    }

}

        clusterName.writeTo(out);
        if (out.getVersion().onOrAfter(Version.V_4_4_0)) {
            out.writeOptionalWriteable(clusterState);
            out.writeBoolean(waitForTimedOut);
        } else {
            clusterState.writeTo(out);
        }
    
<methods>public non-sealed void <init>() <variables>