NanoPB+CustomStringConvertible.swift 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // Copyright 2022 Google LLC
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. import Foundation
  16. #if SWIFT_PACKAGE
  17. import FirebaseSessionsObjC
  18. #endif // SWIFT_PACKAGE
  19. ///
  20. /// These extensions allows us to console log properties of our Session Events
  21. /// proto for development and debugging purposes without having to call decode
  22. /// on each field manually. Instead you can read `<field>.description`.
  23. ///
  24. extension firebase_appquality_sessions_EventType: Swift.CustomStringConvertible {
  25. public var description: String {
  26. switch self {
  27. case firebase_appquality_sessions_EventType_SESSION_START:
  28. return "SESSION_START"
  29. case firebase_appquality_sessions_EventType_EVENT_TYPE_UNKNOWN:
  30. return "UNKNOWN"
  31. default:
  32. return "Unrecognized EventType. Please update the firebase_appquality_sessions_EventType CustomStringConvertible extension"
  33. }
  34. }
  35. }
  36. extension firebase_appquality_sessions_DataCollectionState: Swift.CustomStringConvertible {
  37. public var description: String {
  38. switch self {
  39. case firebase_appquality_sessions_DataCollectionState_COLLECTION_ENABLED:
  40. return "ENABLED"
  41. case firebase_appquality_sessions_DataCollectionState_COLLECTION_SAMPLED:
  42. return "SAMPLED"
  43. case firebase_appquality_sessions_DataCollectionState_COLLECTION_UNKNOWN:
  44. return "UNKNOWN"
  45. case firebase_appquality_sessions_DataCollectionState_COLLECTION_DISABLED:
  46. return "DISABLED"
  47. case firebase_appquality_sessions_DataCollectionState_COLLECTION_DISABLED_REMOTE:
  48. return "DISABLED_REMOTE"
  49. case firebase_appquality_sessions_DataCollectionState_COLLECTION_SDK_NOT_INSTALLED:
  50. return "SDK_NOT_INSTALLED"
  51. default:
  52. return "Unrecognized DataCollectionState. Please update the firebase_appquality_sessions_DataCollectionState CustomStringConvertible extension"
  53. }
  54. }
  55. }
  56. extension firebase_appquality_sessions_OsName: Swift.CustomStringConvertible {
  57. public var description: String {
  58. switch self {
  59. case firebase_appquality_sessions_OsName_IOS:
  60. return "IOS"
  61. case firebase_appquality_sessions_OsName_IPADOS:
  62. return "IPADOS"
  63. case firebase_appquality_sessions_OsName_TVOS:
  64. return "TVOS"
  65. case firebase_appquality_sessions_OsName_IOS_ON_MAC:
  66. return "IOS_ON_MAC"
  67. case firebase_appquality_sessions_OsName_MACOS:
  68. return "MACOS"
  69. case firebase_appquality_sessions_OsName_MACCATALYST:
  70. return "MACCATALYST"
  71. case firebase_appquality_sessions_OsName_WATCHOS:
  72. return "WATCHOS"
  73. case firebase_appquality_sessions_OsName_UNKNOWN_OSNAME:
  74. return "UNKNOWN_OSNAME"
  75. case firebase_appquality_sessions_OsName_UNSPECIFIED:
  76. return "UNSPECIFIED"
  77. default:
  78. return "Unrecognized OsName. Please update the firebase_appquality_sessions_OsName CustomStringConvertible extension"
  79. }
  80. }
  81. }
  82. extension firebase_appquality_sessions_LogEnvironment: Swift.CustomStringConvertible {
  83. public var description: String {
  84. switch self {
  85. case firebase_appquality_sessions_LogEnvironment_LOG_ENVIRONMENT_PROD:
  86. return "PROD"
  87. case firebase_appquality_sessions_LogEnvironment_LOG_ENVIRONMENT_STAGING:
  88. return "STAGING"
  89. case firebase_appquality_sessions_LogEnvironment_LOG_ENVIRONMENT_AUTOPUSH:
  90. return "AUTOPUSH"
  91. case firebase_appquality_sessions_LogEnvironment_LOG_ENVIRONMENT_UNKNOWN:
  92. return "UNKNOWN"
  93. default:
  94. return "Unrecognized LogEnvironment. Please update the firebase_appquality_sessions_LogEnvironment CustomStringConvertible extension"
  95. }
  96. }
  97. }
  98. // This is written like this for Swift backwards-compatibility.
  99. // Once we upgrade to Xcode 14, this can be written as
  100. // UnsafeMutablePointer<pb_bytes_array_t>
  101. extension UnsafeMutablePointer: Swift.CustomStringConvertible where Pointee == pb_bytes_array_t {
  102. public var description: String {
  103. let decoded = FIRSESDecodeString(self)
  104. if decoded.count == 0 {
  105. return "<EMPTY>"
  106. }
  107. return decoded
  108. }
  109. }
  110. // For an optional field
  111. // This is written like this for Swift backwards-compatibility.
  112. // Once we upgrade to Xcode 14, this can be written as
  113. // UnsafeMutablePointer<pb_bytes_array_t>?
  114. extension Optional: Swift.CustomStringConvertible
  115. where Wrapped == UnsafeMutablePointer<pb_bytes_array_t> {
  116. public var description: String {
  117. guard let this = self else {
  118. return "<NULL>"
  119. }
  120. return this.description
  121. }
  122. }