CCF
Loading...
Searching...
No Matches
status.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
6#include "status.pb.h"
7
8#include <optional>
9#include <string>
10
11namespace ccf::grpc
12{
13 static int32_t status_to_code(const grpc_status& status)
14 {
15 return static_cast<int32_t>(status);
16 }
17
18 static protobuf::Status make_grpc_status(
19 enum grpc_status status,
20 const std::optional<std::string>& msg = std::nullopt)
21 {
22 protobuf::Status s;
23 s.set_code(status_to_code(status));
24 if (msg.has_value())
25 {
26 s.set_message(msg.value());
27 }
28 else
29 {
30 s.set_message(grpc_status_str(status));
31 }
32 // Note: details are not currently supported. The fields in this Status are
33 // put used for the `grpc-status` and `grpc-message` response trailers, but
34 // the details field is not serialised/included in the response
35 // if (details.has_value())
36 // {
37 // auto* d = s.add_details();
38 // d->set_value(details.value());
39 // }
40 return s;
41 }
42
43 static protobuf::Status make_grpc_status_ok()
44 {
45 return make_grpc_status(GRPC_STATUS_OK);
46 }
47}
grpc_status
Definition grpc_status.h:30
Definition grpc_status.h:98