Google_Protobuf_Compiler_CodeGeneratorResponse+Extensions.swift 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. public init(error: String) {
  17. self.init()
  18. self.error = error
  19. }
  20. /// Helper to make a response with a set of files
  21. @available(*, deprecated, message: "Please move your plugin to the CodeGenerator interface")
  22. public init(files: [Google_Protobuf_Compiler_CodeGeneratorResponse.File]) {
  23. self.init(files: files, supportedFeatures: [])
  24. }
  25. /// Helper to make a response with a set of files and supported features.
  26. @available(*, deprecated, message: "Please move your plugin to the CodeGenerator interface")
  27. public init(
  28. files: [Google_Protobuf_Compiler_CodeGeneratorResponse.File],
  29. supportedFeatures: [Google_Protobuf_Compiler_CodeGeneratorResponse.Feature] = []
  30. ) {
  31. self.init()
  32. self.file = files
  33. self.supportedFeatures = supportedFeatures.reduce(0) { $0 | UInt64($1.rawValue) }
  34. }
  35. }
  36. extension Google_Protobuf_Compiler_CodeGeneratorResponse.File {
  37. /// Helper to make a Response.File with specific content.
  38. public init(name: String, content: String) {
  39. self.init()
  40. self.name = name
  41. self.content = content
  42. }
  43. }