> For the complete documentation index, see [llms.txt](https://openvector.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://openvector.gitbook.io/docs/api-references/computeresponse-class.md).

# ComputeResponse Class

The `ComputeResponse` class represents the response received from the OpenVector network after a computation has been performed. It contains the status of the computation and any resulting data.

### Public Enums

#### `enum class Status`

Indicates the status of the computation.

* **Values:**
  * `OK`: The computation was successful.
  * `ERROR`: An error occurred during the computation.

### Constructors

#### `ComputeResponse(Status status, std::string data);`

Creates a compute response with the specified status and data.

```cpp
ComputeResponse response(ComputeResponse::Status::OK, resultData);
```

* **Parameters:**
  * `status`: The status of the computation (`OK` or `ERROR`).
  * `data`: The result data as a string. The format and content depend on the computation performed.

### Member Functions

* **`Status& status();`**

  Returns a reference to the status of the computation.
* **`const Status& status() const;`**

  Returns a constant reference to the status of the computation.
* **`std::string& data();`**

  Returns a reference to the result data string.
* **`const std::string& data() const;`**

  Returns a constant reference to the result data string.
* **`std::string to_string() const;`**

  Serializes the compute response to a string.
* **`static ComputeResponse from_string(const std::string& str);`**

  Deserializes a compute response from a string.

### Usage Example

```cpp
// After performing a compute operation using ClientNode
ComputeResponse* response = nullptr;
clientNode.compute(request, &response);

if (response) {
    if (response->status() == ComputeResponse::Status::OK) {
        // Deserialize the result
        PlainTextImpl resultPt = cs.deserialize_plaintext(response->data());
        float resultValue = cs.get_float_from_plaintext(resultPt);
        // Use the resultValue
    } else {
        // Handle error
        std::cerr << "Computation failed." << std::endl;
    }
} else {
    // Handle null response
    std::cerr << "No response received from the server." << std::endl;
}
```

### Notes

* The `data` field contains the serialized result of the computation. You need to deserialize it using the appropriate method from the `CryptoSystem`.
* Always check the `status` before attempting to use the `data`.
* In case of an error, the `data` field may contain an error message or be empty.

### See Also

* [ClientNode Class](/docs/api-references/markdown.md)
* [ComputeRequest Class](/docs/api-references/openapi.md)
* [CryptoSystem Interface](/docs/api-references/editor.md)
