诸暨麻将添加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.
 
 
 
 
 
 

204 lines
8.4 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. #ifndef GOOGLE_PROTOBUF_UTIL_CONVERTER_UTILITY_H__
  31. #define GOOGLE_PROTOBUF_UTIL_CONVERTER_UTILITY_H__
  32. #include <memory>
  33. #include <string>
  34. #include <utility>
  35. #include <google/protobuf/stubs/common.h>
  36. #include <google/protobuf/stubs/logging.h>
  37. #include <google/protobuf/any.pb.h>
  38. #include <google/protobuf/type.pb.h>
  39. #include <google/protobuf/repeated_field.h>
  40. #include <google/protobuf/stubs/strutil.h>
  41. #include <google/protobuf/stubs/status.h>
  42. #include <google/protobuf/stubs/statusor.h>
  43. // Must be included last.
  44. #include <google/protobuf/port_def.inc>
  45. namespace google {
  46. namespace protobuf {
  47. namespace util {
  48. namespace converter {
  49. // Size of "type.googleapis.com"
  50. static const int64 kTypeUrlSize = 19;
  51. // Finds the tech option identified by option_name. Parses the boolean value and
  52. // returns it.
  53. // When the option with the given name is not found, default_value is returned.
  54. PROTOBUF_EXPORT bool GetBoolOptionOrDefault(
  55. const RepeatedPtrField<google::protobuf::Option>& options,
  56. StringPiece option_name, bool default_value);
  57. // Returns int64 option value. If the option isn't found, returns the
  58. // default_value.
  59. PROTOBUF_EXPORT int64 GetInt64OptionOrDefault(
  60. const RepeatedPtrField<google::protobuf::Option>& options,
  61. StringPiece option_name, int64 default_value);
  62. // Returns double option value. If the option isn't found, returns the
  63. // default_value.
  64. PROTOBUF_EXPORT double GetDoubleOptionOrDefault(
  65. const RepeatedPtrField<google::protobuf::Option>& options,
  66. StringPiece option_name, double default_value);
  67. // Returns string option value. If the option isn't found, returns the
  68. // default_value.
  69. PROTOBUF_EXPORT std::string GetStringOptionOrDefault(
  70. const RepeatedPtrField<google::protobuf::Option>& options,
  71. StringPiece option_name, StringPiece default_value);
  72. // Returns a boolean value contained in Any type.
  73. // TODO(skarvaje): Make these utilities dealing with Any types more generic,
  74. // add more error checking and move to a more public/sharable location so others
  75. // can use.
  76. PROTOBUF_EXPORT bool GetBoolFromAny(const google::protobuf::Any& any);
  77. // Returns int64 value contained in Any type.
  78. PROTOBUF_EXPORT int64 GetInt64FromAny(const google::protobuf::Any& any);
  79. // Returns double value contained in Any type.
  80. PROTOBUF_EXPORT double GetDoubleFromAny(const google::protobuf::Any& any);
  81. // Returns string value contained in Any type.
  82. PROTOBUF_EXPORT std::string GetStringFromAny(const google::protobuf::Any& any);
  83. // Returns the type string without the url prefix. e.g.: If the passed type is
  84. // 'type.googleapis.com/tech.type.Bool', the returned value is 'tech.type.Bool'.
  85. PROTOBUF_EXPORT const StringPiece GetTypeWithoutUrl(
  86. StringPiece type_url);
  87. // Returns the simple_type with the base type url (kTypeServiceBaseUrl)
  88. // prefixed.
  89. //
  90. // E.g:
  91. // GetFullTypeWithUrl("google.protobuf.Timestamp") returns the string
  92. // "type.googleapis.com/google.protobuf.Timestamp".
  93. PROTOBUF_EXPORT const std::string GetFullTypeWithUrl(
  94. StringPiece simple_type);
  95. // Finds and returns option identified by name and option_name within the
  96. // provided map. Returns nullptr if none found.
  97. const google::protobuf::Option* FindOptionOrNull(
  98. const RepeatedPtrField<google::protobuf::Option>& options,
  99. StringPiece option_name);
  100. // Finds and returns the field identified by field_name in the passed tech Type
  101. // object. Returns nullptr if none found.
  102. const google::protobuf::Field* FindFieldInTypeOrNull(
  103. const google::protobuf::Type* type, StringPiece field_name);
  104. // Similar to FindFieldInTypeOrNull, but this looks up fields with given
  105. // json_name.
  106. const google::protobuf::Field* FindJsonFieldInTypeOrNull(
  107. const google::protobuf::Type* type, StringPiece json_name);
  108. // Similar to FindFieldInTypeOrNull, but this looks up fields by number.
  109. const google::protobuf::Field* FindFieldInTypeByNumberOrNull(
  110. const google::protobuf::Type* type, int32 number);
  111. // Finds and returns the EnumValue identified by enum_name in the passed tech
  112. // Enum object. Returns nullptr if none found.
  113. const google::protobuf::EnumValue* FindEnumValueByNameOrNull(
  114. const google::protobuf::Enum* enum_type, StringPiece enum_name);
  115. // Finds and returns the EnumValue identified by value in the passed tech
  116. // Enum object. Returns nullptr if none found.
  117. const google::protobuf::EnumValue* FindEnumValueByNumberOrNull(
  118. const google::protobuf::Enum* enum_type, int32 value);
  119. // Finds and returns the EnumValue identified by enum_name without underscore in
  120. // the passed tech Enum object. Returns nullptr if none found.
  121. // For Ex. if enum_name is ACTIONANDADVENTURE it can get accepted if
  122. // EnumValue's name is action_and_adventure or ACTION_AND_ADVENTURE.
  123. const google::protobuf::EnumValue* FindEnumValueByNameWithoutUnderscoreOrNull(
  124. const google::protobuf::Enum* enum_type, StringPiece enum_name);
  125. // Converts input to camel-case and returns it.
  126. PROTOBUF_EXPORT std::string ToCamelCase(const StringPiece input);
  127. // Converts enum name string to camel-case and returns it.
  128. std::string EnumValueNameToLowerCamelCase(const StringPiece input);
  129. // Converts input to snake_case and returns it.
  130. PROTOBUF_EXPORT std::string ToSnakeCase(StringPiece input);
  131. // Returns true if type_name represents a well-known type.
  132. PROTOBUF_EXPORT bool IsWellKnownType(const std::string& type_name);
  133. // Returns true if 'bool_string' represents a valid boolean value. Only "true",
  134. // "false", "0" and "1" are allowed.
  135. PROTOBUF_EXPORT bool IsValidBoolString(StringPiece bool_string);
  136. // Returns true if "field" is a protobuf map field based on its type.
  137. PROTOBUF_EXPORT bool IsMap(const google::protobuf::Field& field,
  138. const google::protobuf::Type& type);
  139. // Returns true if the given type has special MessageSet wire format.
  140. bool IsMessageSetWireFormat(const google::protobuf::Type& type);
  141. // Infinity/NaN-aware conversion to string.
  142. PROTOBUF_EXPORT std::string DoubleAsString(double value);
  143. PROTOBUF_EXPORT std::string FloatAsString(float value);
  144. // Convert from int32, int64, uint32, uint64, double or float to string.
  145. template <typename T>
  146. std::string ValueAsString(T value) {
  147. return StrCat(value);
  148. }
  149. template <>
  150. inline std::string ValueAsString(float value) {
  151. return FloatAsString(value);
  152. }
  153. template <>
  154. inline std::string ValueAsString(double value) {
  155. return DoubleAsString(value);
  156. }
  157. // Converts a string to float. Unlike safe_strtof, conversion will fail if the
  158. // value fits into double but not float (e.g., DBL_MAX).
  159. PROTOBUF_EXPORT bool SafeStrToFloat(StringPiece str, float* value);
  160. } // namespace converter
  161. } // namespace util
  162. } // namespace protobuf
  163. } // namespace google
  164. #include <google/protobuf/port_undef.inc>
  165. #endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_UTILITY_H__