NanoPB+CustomStringConvertible.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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: 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: 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: 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 UnsafeMutablePointer<pb_bytes_array_t>: CustomStringConvertible {
  83. public var description: String {
  84. let decoded = FIRSESDecodeString(self)
  85. if decoded.count == 0 {
  86. return "<EMPTY>"
  87. }
  88. return decoded
  89. }
  90. }
  91. // For an optional field
  92. extension UnsafeMutablePointer<pb_bytes_array_t>?: CustomStringConvertible {
  93. public var description: String {
  94. guard let this = self else {
  95. return "<NULL>"
  96. }
  97. return this.description
  98. }
  99. }