grpc_status_code.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <contrib/libs/grpc/include/grpcpp/impl/codegen/status_code_enum.h>
  2. #include <util/stream/output.h>
  3. namespace {
  4. const char* GrpcStatusCodeToString(grpc::StatusCode statusCode) {
  5. switch (statusCode) {
  6. case grpc::OK:
  7. return "OK";
  8. case grpc::CANCELLED:
  9. return "CANCELLED";
  10. case grpc::UNKNOWN:
  11. return "UNKNOWN";
  12. case grpc::INVALID_ARGUMENT:
  13. return "INVALID_ARGUMENT";
  14. case grpc::DEADLINE_EXCEEDED:
  15. return "DEADLINE_EXCEEDED";
  16. case grpc::NOT_FOUND:
  17. return "NOT_FOUND";
  18. case grpc::ALREADY_EXISTS:
  19. return "ALREADY_EXISTS";
  20. case grpc::PERMISSION_DENIED:
  21. return "PERMISSION_DENIED";
  22. case grpc::UNAUTHENTICATED:
  23. return "UNAUTHENTICATED";
  24. case grpc::RESOURCE_EXHAUSTED:
  25. return "RESOURCE_EXHAUSTED";
  26. case grpc::FAILED_PRECONDITION:
  27. return "FAILED_PRECONDITION";
  28. case grpc::ABORTED:
  29. return "ABORTED";
  30. case grpc::OUT_OF_RANGE:
  31. return "OUT_OF_RANGE";
  32. case grpc::UNIMPLEMENTED:
  33. return "UNIMPLEMENTED";
  34. case grpc::INTERNAL:
  35. return "INTERNAL";
  36. case grpc::UNAVAILABLE:
  37. return "UNAVAILABLE";
  38. case grpc::DATA_LOSS:
  39. return "DATA_LOSS";
  40. default:
  41. return nullptr;
  42. }
  43. }
  44. }
  45. template <>
  46. void Out<grpc::StatusCode>(IOutputStream& o, grpc::StatusCode statusCode) {
  47. const auto* s = GrpcStatusCodeToString(statusCode);
  48. if (s == nullptr) {
  49. o << "grpc::StatusCode [" << static_cast<int>(statusCode) << "]";
  50. } else {
  51. o << s;
  52. }
  53. }