Descriptor+TestHelpers.swift 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Sources/protoc-gen-swift/Descriptor+TestHelpers.swift - Additions to Descriptors
  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. import SwiftProtobuf
  11. extension Google_Protobuf_FileDescriptorProto {
  12. package init(name: String, dependencies: [String] = [], publicDependencies: [Int32] = [], package: String = "") {
  13. for idx in publicDependencies { precondition(Int(idx) <= dependencies.count) }
  14. self.init()
  15. self.name = name
  16. self.dependency = dependencies
  17. self.publicDependency = publicDependencies
  18. self.package = package
  19. }
  20. package init(textFormatStrings: [String]) throws {
  21. let s = textFormatStrings.joined(separator: "\n") + "\n"
  22. try self.init(textFormatString: s)
  23. }
  24. }
  25. extension Google_Protobuf_FileDescriptorSet {
  26. package init(files: [Google_Protobuf_FileDescriptorProto]) {
  27. self.init()
  28. self.file = files
  29. }
  30. package init(file: Google_Protobuf_FileDescriptorProto) {
  31. self.init()
  32. self.file = [file]
  33. }
  34. }
  35. extension Google_Protobuf_EnumValueDescriptorProto {
  36. package init(name: String, number: Int32) {
  37. self.init()
  38. self.name = name
  39. self.number = number
  40. }
  41. }