NanoPB+CustomStringConvertible.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. ///
  17. /// These extensions allows us to console log properties of our Session Events
  18. /// proto for development and debugging purposes without having to call decode
  19. /// on each field manually. Instead you can read `<field>.description`.
  20. ///
  21. extension firebase_appquality_sessions_EventType: CustomStringConvertible {
  22. public var description: String {
  23. switch self {
  24. case firebase_appquality_sessions_EventType_SESSION_START:
  25. return "SESSION_START"
  26. case firebase_appquality_sessions_EventType_EVENT_TYPE_UNKNOWN:
  27. return "UNKNOWN"
  28. default:
  29. return "Unrecognized EventType. Please update the firebase_appquality_sessions_EventType CustomStringConvertible extension"
  30. }
  31. }
  32. }
  33. extension firebase_appquality_sessions_DataCollectionState: CustomStringConvertible {
  34. public var description: String {
  35. switch self {
  36. case firebase_appquality_sessions_DataCollectionState_COLLECTION_ENABLED:
  37. return "ENABLED"
  38. case firebase_appquality_sessions_DataCollectionState_COLLECTION_SAMPLED:
  39. return "SAMPLED"
  40. case firebase_appquality_sessions_DataCollectionState_COLLECTION_UNKNOWN:
  41. return "UNKNOWN"
  42. case firebase_appquality_sessions_DataCollectionState_COLLECTION_DISABLED:
  43. return "DISABLED"
  44. case firebase_appquality_sessions_DataCollectionState_COLLECTION_DISABLED_REMOTE:
  45. return "DISABLED_REMOTE"
  46. case firebase_appquality_sessions_DataCollectionState_COLLECTION_SDK_NOT_INSTALLED:
  47. return "SDK_NOT_INSTALLED"
  48. default:
  49. return "Unrecognized DataCollectionState. Please update the firebase_appquality_sessions_DataCollectionState CustomStringConvertible extension"
  50. }
  51. }
  52. }
  53. extension firebase_appquality_sessions_OsName: CustomStringConvertible {
  54. public var description: String {
  55. switch self {
  56. case firebase_appquality_sessions_OsName_IOS:
  57. return "IOS"
  58. case firebase_appquality_sessions_OsName_IPADOS:
  59. return "IPADOS"
  60. case firebase_appquality_sessions_OsName_TVOS:
  61. return "TVOS"
  62. case firebase_appquality_sessions_OsName_IOS_ON_MAC:
  63. return "IOS_ON_MAC"
  64. case firebase_appquality_sessions_OsName_MACOS:
  65. return "MACOS"
  66. case firebase_appquality_sessions_OsName_MACCATALYST:
  67. return "MACCATALYST"
  68. case firebase_appquality_sessions_OsName_WATCHOS:
  69. return "WATCHOS"
  70. case firebase_appquality_sessions_OsName_UNKNOWN_OSNAME:
  71. return "UNKNOWN_OSNAME"
  72. case firebase_appquality_sessions_OsName_UNSPECIFIED:
  73. return "UNSPECIFIED"
  74. default:
  75. return "Unrecognized OsName. Please update the firebase_appquality_sessions_OsName CustomStringConvertible extension"
  76. }
  77. }
  78. }
  79. extension UnsafeMutablePointer<pb_bytes_array_t>: CustomStringConvertible {
  80. public var description: String {
  81. let decoded = FIRSESDecodeString(self)
  82. if decoded.count == 0 {
  83. return "<EMPTY>"
  84. }
  85. return decoded
  86. }
  87. }
  88. // For an optional field
  89. extension UnsafeMutablePointer<pb_bytes_array_t>?: CustomStringConvertible {
  90. public var description: String {
  91. guard let this = self else {
  92. return "<NULL>"
  93. }
  94. return this.description
  95. }
  96. }