Google_Protobuf_Compiler_CodeGeneratorResponse+Extensions.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Sources/SwiftProtobufPluginLibrary/Google_Protobuf_Compiler_CodeGeneratorResponse+Extensions.swift - CodeGeneratorResponse extensions
  2. //
  3. // Copyright (c) 2014 - 2017 Apple Inc. and the project authors
  4. // Licensed under Apache License v2.0 with Runtime Library Exception
  5. //
  6. // See LICENSE.txt for license information:
  7. // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt
  8. //
  9. // -----------------------------------------------------------------------------
  10. ///
  11. /// Extensions to `CodeGeneratorResponse` provide some simple helpers.
  12. ///
  13. // -----------------------------------------------------------------------------
  14. extension Google_Protobuf_Compiler_CodeGeneratorResponse {
  15. /// Helper to make a response with an error.
  16. @available(*, deprecated, message: "Please move your plugin to the CodeGenerator interface")
  17. public init(error: String) {
  18. self.init()
  19. self.error = error
  20. }
  21. /// Helper to make a response with a set of files
  22. @available(*, deprecated, message: "Please move your plugin to the CodeGenerator interface")
  23. public init(files: [Google_Protobuf_Compiler_CodeGeneratorResponse.File]) {
  24. self.init(files: files, supportedFeatures: [])
  25. }
  26. /// Helper to make a response with a set of files and supported features.
  27. @available(*, deprecated, message: "Please move your plugin to the CodeGenerator interface")
  28. public init(
  29. files: [Google_Protobuf_Compiler_CodeGeneratorResponse.File],
  30. supportedFeatures: [Google_Protobuf_Compiler_CodeGeneratorResponse.Feature] = []
  31. ) {
  32. self.init()
  33. self.file = files
  34. self.supportedFeatures = supportedFeatures.reduce(0) { $0 | UInt64($1.rawValue) }
  35. }
  36. }
  37. extension Google_Protobuf_Compiler_CodeGeneratorResponse.File {
  38. /// Helper to make a Response.File with specific content.
  39. public init(name: String, content: String) {
  40. self.init()
  41. self.name = name
  42. self.content = content
  43. }
  44. }