诸暨麻将添加redis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

135 regels
4.2 KiB

  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #include <google/protobuf/stubs/status.h>
  31. #include <ostream>
  32. #include <stdio.h>
  33. #include <string>
  34. #include <utility>
  35. namespace google {
  36. namespace protobuf {
  37. namespace util {
  38. namespace error {
  39. inline string CodeEnumToString(error::Code code) {
  40. switch (code) {
  41. case OK:
  42. return "OK";
  43. case CANCELLED:
  44. return "CANCELLED";
  45. case UNKNOWN:
  46. return "UNKNOWN";
  47. case INVALID_ARGUMENT:
  48. return "INVALID_ARGUMENT";
  49. case DEADLINE_EXCEEDED:
  50. return "DEADLINE_EXCEEDED";
  51. case NOT_FOUND:
  52. return "NOT_FOUND";
  53. case ALREADY_EXISTS:
  54. return "ALREADY_EXISTS";
  55. case PERMISSION_DENIED:
  56. return "PERMISSION_DENIED";
  57. case UNAUTHENTICATED:
  58. return "UNAUTHENTICATED";
  59. case RESOURCE_EXHAUSTED:
  60. return "RESOURCE_EXHAUSTED";
  61. case FAILED_PRECONDITION:
  62. return "FAILED_PRECONDITION";
  63. case ABORTED:
  64. return "ABORTED";
  65. case OUT_OF_RANGE:
  66. return "OUT_OF_RANGE";
  67. case UNIMPLEMENTED:
  68. return "UNIMPLEMENTED";
  69. case INTERNAL:
  70. return "INTERNAL";
  71. case UNAVAILABLE:
  72. return "UNAVAILABLE";
  73. case DATA_LOSS:
  74. return "DATA_LOSS";
  75. }
  76. // No default clause, clang will abort if a code is missing from
  77. // above switch.
  78. return "UNKNOWN";
  79. }
  80. } // namespace error.
  81. const Status Status::OK = Status();
  82. const Status Status::CANCELLED = Status(error::CANCELLED, "");
  83. const Status Status::UNKNOWN = Status(error::UNKNOWN, "");
  84. Status::Status() : error_code_(error::OK) {
  85. }
  86. Status::Status(error::Code error_code, StringPiece error_message)
  87. : error_code_(error_code) {
  88. if (error_code != error::OK) {
  89. error_message_ = error_message.ToString();
  90. }
  91. }
  92. Status::Status(const Status& other)
  93. : error_code_(other.error_code_), error_message_(other.error_message_) {
  94. }
  95. Status& Status::operator=(const Status& other) {
  96. error_code_ = other.error_code_;
  97. error_message_ = other.error_message_;
  98. return *this;
  99. }
  100. bool Status::operator==(const Status& x) const {
  101. return error_code_ == x.error_code_ &&
  102. error_message_ == x.error_message_;
  103. }
  104. string Status::ToString() const {
  105. if (error_code_ == error::OK) {
  106. return "OK";
  107. } else {
  108. if (error_message_.empty()) {
  109. return error::CodeEnumToString(error_code_);
  110. } else {
  111. return error::CodeEnumToString(error_code_) + ":" +
  112. error_message_;
  113. }
  114. }
  115. }
  116. std::ostream& operator<<(std::ostream& os, const Status& x) {
  117. os << x.ToString();
  118. return os;
  119. }
  120. } // namespace util
  121. } // namespace protobuf
  122. } // namespace google