├── .gitignore ├── .swift-version ├── .travis.yml ├── CREDITS ├── ISSUE_TEMPLATE ├── Info.plist ├── LICENSE ├── Makefile.am ├── Package.swift ├── ProtocolBuffers-Swift.podspec ├── ProtocolBuffers.xcodeproj ├── ProtocolBufferTests_Info.plist ├── ProtocolBuffers_Info.plist ├── project.pbxproj └── xcshareddata │ └── xcschemes │ ├── ProtocolBuffers-Package.xcscheme │ ├── ProtocolBuffers.xcscheme │ └── xcschememanagement.plist ├── README.md ├── Source ├── AbstractMessage.swift ├── CodedInputStream.swift ├── CodedOutputStream.swift ├── ConcreateExtensionField.swift ├── ExtendableMessage.swift ├── ExtensionRegistry.swift ├── Field.swift ├── GeneratedMessage.swift ├── Google.Protobuf.Any.proto.swift ├── Google.Protobuf.Api.proto.swift ├── Google.Protobuf.Descriptor.proto.swift ├── Google.Protobuf.Duration.proto.swift ├── Google.Protobuf.Empty.proto.swift ├── Google.Protobuf.FieldMask.proto.swift ├── Google.Protobuf.SourceContext.proto.swift ├── Google.Protobuf.Struct.proto.swift ├── Google.Protobuf.SwiftDescriptor.proto.swift ├── Google.Protobuf.Timestamp.proto.swift ├── Google.Protobuf.Type.proto.swift ├── Google.Protobuf.Wrappers.proto.swift ├── ProtocolBuffers.h ├── RingBuffer.swift ├── UnknownFieldSet.swift └── WireFormat.swift ├── autogen.sh ├── configure.ac ├── plugin ├── PBCompiler │ └── PBCompiler.xcodeproj │ │ └── project.pbxproj ├── Tests │ ├── CodedInputStreamTests.swift │ ├── CodedOuputStreamTests.swift │ ├── ErrorHandlingTest.swift │ ├── GeneratedMessageTests.swift │ ├── Info.plist │ ├── MapFieldsTests.swift │ ├── MessageTests.swift │ ├── Performance.proto.swift │ ├── PluginTest.swift │ ├── ProtocolBuffersTests.swift │ ├── SizeTest.swift │ ├── SmallBlockInputStream.swift │ ├── TestUtilities.swift │ ├── UnknowFieldsTests.swift │ ├── WireFormatTests.swift │ ├── pbTests │ │ ├── Bar.Foo.proto.swift │ │ ├── Baz.Foo.proto.swift │ │ ├── Google.Protobuf.NoGenericServicesTest.UnittestNoGenericServices.proto.swift │ │ ├── Google.Protobuf.UnittestEnormousDescriptor.proto.swift │ │ ├── Proto2ArenaUnittest.UnittestArena.proto.swift │ │ ├── Proto2ArenaUnittest.UnittestNoArenaImport.proto.swift │ │ ├── Proto2NofieldpresenceUnittest.UnittestNoFieldPresence.proto.swift │ │ ├── Proto3ArenaUnittest.UnittestProto3Arena.proto.swift │ │ ├── Proto3PreserveUnknownEnumUnittest.UnittestPreserveUnknownEnum.proto.swift │ │ ├── ProtobufUnittest.Unittest.proto.swift │ │ ├── ProtobufUnittest.UnittestCustomOptions.proto.swift │ │ ├── ProtobufUnittest.UnittestEmbedOptimizeFor.proto.swift │ │ ├── ProtobufUnittest.UnittestLite.proto.swift │ │ ├── ProtobufUnittest.UnittestLiteImportsNonlite.proto.swift │ │ ├── ProtobufUnittest.UnittestMset.proto.swift │ │ ├── ProtobufUnittest.UnittestOptimizeFor.proto.swift │ │ ├── ProtobufUnittest.UnittestWellKnownTypes.proto.swift │ │ ├── ProtobufUnittestImport.UnittestImport.proto.swift │ │ ├── ProtobufUnittestImport.UnittestImportLite.proto.swift │ │ ├── ProtobufUnittestImport.UnittestImportPublic.proto.swift │ │ ├── ProtobufUnittestImport.UnittestImportPublicLite.proto.swift │ │ ├── ProtobufUnittestNoArena.UnittestNoArena.proto.swift │ │ ├── SwiftProtobufUnittest.UnittestMaps.proto.swift │ │ ├── ThreadingTest.swift │ │ ├── UnittestDropUnknownFields.UnittestDropUnknownFields.proto.swift │ │ ├── UnittestEmpty.proto.swift │ │ ├── UnittestErrorType.proto.swift │ │ ├── UnittestStruct.proto.swift │ │ ├── UnittestThreading.proto.swift │ │ └── testdata │ │ │ ├── bad_utf8_string │ │ │ ├── delimitedFile.dat │ │ │ ├── golden_message │ │ │ ├── golden_message_oneof_implemented │ │ │ ├── golden_packed_fields_message │ │ │ ├── text_format_unittest_data.txt │ │ │ ├── text_format_unittest_data_oneof_implemented.txt │ │ │ ├── text_format_unittest_data_pointy.txt │ │ │ ├── text_format_unittest_data_pointy_oneof.txt │ │ │ ├── text_format_unittest_extensions_data.txt │ │ │ └── text_format_unittest_extensions_data_pointy.txt │ └── testdata │ │ └── delimitedFile.dat └── compiler │ ├── Makefile.am │ ├── RESERVEDWORDS │ ├── google │ └── protobuf │ │ ├── .dirstamp │ │ ├── any.proto │ │ ├── any_test.proto │ │ ├── api.proto │ │ ├── descriptor.pb.cc │ │ ├── descriptor.pb.h │ │ ├── descriptor.proto │ │ ├── duration.proto │ │ ├── empty.proto │ │ ├── field_mask.proto │ │ ├── map_lite_unittest.proto │ │ ├── map_proto2_unittest.proto │ │ ├── map_unittest.proto │ │ ├── performance.proto │ │ ├── plugin.proto │ │ ├── source_context.proto │ │ ├── struct.proto │ │ ├── stubs │ │ ├── hash.h │ │ ├── strutil.h │ │ └── substitute.h │ │ ├── swift-descriptor.pb.cc │ │ ├── swift-descriptor.pb.h │ │ ├── swift-descriptor.proto │ │ ├── timestamp.proto │ │ ├── type.proto │ │ ├── unittest.proto │ │ ├── unittest_arena.proto │ │ ├── unittest_custom_options.proto │ │ ├── unittest_drop_unknown_fields.proto │ │ ├── unittest_embed_optimize_for.proto │ │ ├── unittest_empty.proto │ │ ├── unittest_enormous_descriptor.proto │ │ ├── unittest_error_type.proto │ │ ├── unittest_import.proto │ │ ├── unittest_import_lite.proto │ │ ├── unittest_import_public.proto │ │ ├── unittest_import_public_lite.proto │ │ ├── unittest_lite.proto │ │ ├── unittest_lite_imports_nonlite.proto │ │ ├── unittest_maps.proto │ │ ├── unittest_mset.proto │ │ ├── unittest_no_arena.proto │ │ ├── unittest_no_arena_import.proto │ │ ├── unittest_no_field_presence.proto │ │ ├── unittest_no_generic_services.proto │ │ ├── unittest_optimize_for.proto │ │ ├── unittest_preserve_unknown_enum.proto │ │ ├── unittest_proto3_arena.proto │ │ ├── unittest_struct.proto │ │ ├── unittest_threading.proto │ │ ├── unittest_well_known_types.proto │ │ ├── unknown_enum_test.proto │ │ └── wrappers.proto │ ├── main.cc │ ├── react_native │ ├── .dirstamp │ ├── main.cc │ ├── swift_file.cc │ ├── swift_file.h │ ├── swift_generator.cc │ ├── swift_generator.h │ ├── swift_helpers_react.cc │ ├── swift_helpers_react.h │ ├── swift_react.cc │ ├── swift_react.h │ ├── swift_react_enums.cc │ └── swift_react_enums.h │ ├── swift_enum.cc │ ├── swift_enum.h │ ├── swift_enum_field.cc │ ├── swift_enum_field.h │ ├── swift_extension.cc │ ├── swift_extension.h │ ├── swift_field.cc │ ├── swift_field.h │ ├── swift_file.cc │ ├── swift_file.h │ ├── swift_generator.cc │ ├── swift_generator.h │ ├── swift_helpers.cc │ ├── swift_helpers.h │ ├── swift_map_field.cc │ ├── swift_map_field.h │ ├── swift_message.cc │ ├── swift_message.h │ ├── swift_message_field.cc │ ├── swift_message_field.h │ ├── swift_oneof.cc │ ├── swift_oneof.h │ ├── swift_primitive_field.cc │ ├── swift_primitive_field.h │ └── tests │ ├── bar │ └── foo.proto │ └── baz │ └── foo.proto ├── protobuf-swift.rb └── scripts ├── build.sh ├── makeDescriptor.sh └── makeTests.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Build stuff 2 | *.o 3 | .deps 4 | Makefile 5 | Makefile.in 6 | aclocal.m4 7 | autom4te.cache 8 | config.h 9 | config.h.in 10 | config.guess 11 | config.log 12 | config.status 13 | config.sub 14 | configure 15 | depcomp 16 | install-sh 17 | libtool 18 | ltmain.sh 19 | missing 20 | m4 21 | stamp-h1 22 | 23 | 24 | # Targets 25 | *protoc-gen-swift 26 | 27 | # Mac stuff 28 | .DS_Store 29 | 30 | # Xcode 31 | .DS_Store 32 | build/ 33 | *.pbxuser 34 | !default.pbxuser 35 | *.mode1v3 36 | !default.mode1v3 37 | *.mode2v3 38 | !default.mode2v3 39 | *.perspectivev3 40 | !default.perspectivev3 41 | *.xcworkspace 42 | !default.xcworkspace 43 | xcuserdata 44 | profile 45 | *.moved-aside 46 | DerivedData 47 | .idea/ 48 | 49 | compile 50 | /plugin/compiler/protoc-gen-swift_realm 51 | /plugin/compiler/protoc-gen-swift_react 52 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 4.0 -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | osx_image: xcode10 3 | before_install: 4 | - brew update 5 | - brew unlink python 6 | - brew install protobuf 7 | # - brew uninstall xctool 8 | # - brew install xctool --HEAD 9 | 10 | install: 11 | - scripts/build.sh 12 | - scripts/makeTests.sh 13 | script: 14 | - xcodebuild test -project ./ProtocolBuffers.xcodeproj -scheme "ProtocolBuffers" -destination 'platform=macos' 15 | # - xctool -project ./plugin/ProtocolBuffers/ProtocolBuffers.xcodeproj -sdk iphonesimulator -scheme ProtocolBuffers build test 16 | # - xctool -project ./plugin/ProtocolBuffers/ProtocolBuffers.xcodeproj -scheme "ProtocolBuffers(OSX)" build test 17 | # - xctool -project ./plugin/ProtocolBuffers/ProtocolBuffers.xcodeproj -sdk appletvsimulator -scheme "ProtocolBuffers(tvOS)" build test 18 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | Alexey Khokhlov(alexeyxo) 2 | ------------------------------------------------------------------------------- 3 | Alexey Khokhlov 4 | 5 | Google Protocol Buffers 6 | ------------------------------------------------------------------------------- 7 | Cyrus Najmabadi,Sergey Martynov, Kenton Varda, Sanjay Ghemawat, Jeff Dean, and others 8 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE: -------------------------------------------------------------------------------- 1 | #### Version of protoc (```protoc --version```) 2 | ###### 3.0 3 | 4 | #### Version of ProtocolBuffers.framework 5 | ###### 3.0.0 6 | 7 | #### ```.proto``` file to reproduce 8 | ```protobuf 9 | 10 | ``` 11 | 12 | #### Description 13 | 14 | -------------------------------------------------------------------------------- /Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # Process this file with automake to produce Makefile.am 2 | 3 | ACLOCAL_AMFLAGS = -I m4 4 | AUTOMAKE_OPTIONS = foreign 5 | SUBDIRS = plugin/compiler 6 | 7 | EXTRA_DIST = \ 8 | autogen.sh 9 | 10 | # Clean up all of the files generated by autogen.sh 11 | MAINTAINERCLEANFILES = \ 12 | aclocal.m4 \ 13 | config.guess \ 14 | config.sub \ 15 | configure \ 16 | depcomp \ 17 | install-sh \ 18 | ltmain.sh \ 19 | Makefile.in \ 20 | missing \ 21 | mkinstalldirs \ 22 | config.h.in \ 23 | stamp.h.in 24 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:4.0 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "ProtocolBuffers", 8 | products: [ 9 | // Products define the executables and libraries produced by a package, and make them visible to other packages. 10 | .library( 11 | name: "ProtocolBuffers", 12 | targets: ["ProtocolBuffers"]), 13 | ], 14 | targets: [ 15 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 16 | // Targets can depend on other targets in this package, and on products in packages which this package depends on. 17 | .target( 18 | name: "ProtocolBuffers", 19 | path: ".", 20 | sources: ["Source"]), 21 | 22 | .testTarget( 23 | name: "ProtocolBufferTests", 24 | dependencies: ["ProtocolBuffers"], 25 | path: "./plugin/", 26 | sources: ["Tests"]) 27 | ] 28 | ) 29 | -------------------------------------------------------------------------------- /ProtocolBuffers-Swift.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "ProtocolBuffers-Swift" 3 | s.version = "4.0.5" 4 | s.summary = "Protocol Buffers for Swift" 5 | s.homepage = "http://protobuf.io#swift" 6 | s.license = "Apache 2.0" 7 | s.documentation_url = "https://github.com/alexeyxo/protobuf-swift" 8 | s.license = { :type => 'Apache License, Version 2.0', :text => 9 | <<-LICENSE 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | Unless required by applicable law or agreed to in writing, software 15 | distributed under the License is distributed on an "AS IS" BASIS, 16 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | See the License for the specific language governing permissions and 18 | limitations under the License. 19 | Copyright 2008 Google Inc. 20 | LICENSE 21 | } 22 | 23 | s.author = { "Alexey Khokhlov" => "alexeyxo@gmail.com" } 24 | s.authors = { "Alexey Khokhlov" => "alexeyxo@gmail.com" } 25 | 26 | s.ios.deployment_target = '8.0' 27 | s.osx.deployment_target = '10.10' 28 | s.watchos.deployment_target = '2.0' 29 | s.tvos.deployment_target = '9.0' 30 | 31 | s.module_name = "ProtocolBuffers" 32 | s.source = { :git => "https://github.com/alexeyxo/protobuf-swift.git", :tag => s.version } 33 | s.source_files = 'Source/*.{swift}' 34 | s.requires_arc = true 35 | s.frameworks = 'Foundation' 36 | end 37 | -------------------------------------------------------------------------------- /ProtocolBuffers.xcodeproj/ProtocolBufferTests_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | BNDL 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /ProtocolBuffers.xcodeproj/ProtocolBuffers_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 4.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /ProtocolBuffers.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers-Package.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 34 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 57 | 58 | 64 | 65 | 66 | 67 | 68 | 69 | 75 | 76 | 78 | 79 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /ProtocolBuffers.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 34 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 57 | 58 | 64 | 65 | 66 | 67 | 68 | 69 | 75 | 76 | 78 | 79 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /ProtocolBuffers.xcodeproj/xcshareddata/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SchemeUserState 5 | 6 | ProtocolBuffers-Package.xcscheme 7 | 8 | 9 | SuppressBuildableAutocreation 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Source/ExtensionRegistry.swift: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License") 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | import Foundation 19 | 20 | public typealias AnyClassType = GeneratedMessage.Type 21 | 22 | public protocol ExtensionField 23 | { 24 | var fieldNumber:Int32 {get set} 25 | var extendedClass:AnyClassType {get} 26 | var wireType:WireFormat {get} 27 | func writeValueIncludingTagToCodedOutputStream(value:Any, output:CodedOutputStream) throws 28 | func computeSerializedSizeIncludingTag(value:Any) throws -> Int32 29 | func getDescription(value:Any, indent:String) throws -> String 30 | func mergeFrom(codedInputStream:CodedInputStream, unknownFields:UnknownFieldSet.Builder, extensionRegistry:ExtensionRegistry, builder:ExtendableMessageBuilder, tag:Int32) throws 31 | 32 | } 33 | 34 | public class ExtensionRegistry 35 | { 36 | private var classMap:[String : [Int32 : ConcreateExtensionField]] 37 | 38 | public init() 39 | { 40 | self.classMap = [:] 41 | } 42 | public init(classMap:[String : [Int32 : ConcreateExtensionField]]) 43 | { 44 | self.classMap = classMap 45 | } 46 | 47 | public func getExtension(clName:AnyClassType, fieldNumber:Int32) -> ConcreateExtensionField? { 48 | 49 | let extensionMap = classMap[clName.className()] 50 | if extensionMap == nil 51 | { 52 | return nil 53 | } 54 | return extensionMap![fieldNumber] 55 | } 56 | 57 | public func addExtension(extensions:ConcreateExtensionField) 58 | { 59 | let extendedClass = extensions.extendedClass.className() 60 | var extensionMap = classMap[extendedClass] 61 | if extensionMap == nil 62 | { 63 | extensionMap = [Int32 : ConcreateExtensionField]() 64 | 65 | } 66 | extensionMap![extensions.fieldNumber] = extensions 67 | classMap[extendedClass] = extensionMap 68 | 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /Source/GeneratedMessage.swift: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License") 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | import Foundation 19 | 20 | public protocol GeneratedMessageProtocol: ProtocolBuffersMessage { 21 | associatedtype BuilderType:GeneratedMessageBuilderProtocol 22 | static func parseFrom(data: Data) throws -> Self 23 | static func parseFrom(data: Data, extensionRegistry:ExtensionRegistry) throws -> Self 24 | static func parseFrom(inputStream:InputStream) throws -> Self 25 | static func parseFrom(inputStream:InputStream, extensionRegistry:ExtensionRegistry) throws -> Self 26 | static func parseFrom(codedInputStream:CodedInputStream) throws -> Self 27 | static func parseFrom(codedInputStream:CodedInputStream, extensionRegistry:ExtensionRegistry) throws -> Self 28 | subscript(key: String) -> Any? { get } 29 | } 30 | 31 | 32 | public protocol GeneratedEnum:RawRepresentable, CustomDebugStringConvertible, CustomStringConvertible, Hashable, CaseIterable { 33 | func toString() -> String 34 | static func fromString(_ str:String) throws -> Self 35 | } 36 | 37 | public protocol GeneratedMessageBuilderProtocol: ProtocolBuffersMessageBuilder { 38 | subscript(key: String) -> Any? { get set } 39 | } 40 | 41 | open class GeneratedMessage:AbstractProtocolBuffersMessage 42 | { 43 | public var memoizedSerializedSize:Int32 = -1 44 | required public init() 45 | { 46 | super.init() 47 | self.unknownFields = UnknownFieldSet(fields: [:]) 48 | } 49 | 50 | //Override 51 | open class func className() -> String 52 | { 53 | return "GeneratedMessage" 54 | } 55 | open func className() -> String 56 | { 57 | return "GeneratedMessage" 58 | } 59 | open override class func classBuilder() -> ProtocolBuffersMessageBuilder 60 | { 61 | return GeneratedMessageBuilder() 62 | } 63 | open override func classBuilder() -> ProtocolBuffersMessageBuilder 64 | { 65 | return GeneratedMessageBuilder() 66 | } 67 | // 68 | } 69 | 70 | open class GeneratedMessageBuilder:AbstractProtocolBuffersMessageBuilder 71 | { 72 | open var internalGetResult:GeneratedMessage 73 | { 74 | get 75 | { 76 | return GeneratedMessage() 77 | } 78 | 79 | } 80 | 81 | override open var unknownFields:UnknownFieldSet 82 | { 83 | get 84 | { 85 | return internalGetResult.unknownFields 86 | } 87 | 88 | set (fields) 89 | { 90 | internalGetResult.unknownFields = fields 91 | } 92 | 93 | } 94 | public func checkInitialized() throws { 95 | let result = internalGetResult 96 | try result.isInitialized() 97 | } 98 | 99 | public func checkInitializedParsed() throws { 100 | let result = internalGetResult 101 | try result.isInitialized() 102 | } 103 | 104 | override open func isInitialized() throws { 105 | try internalGetResult.isInitialized() 106 | } 107 | @discardableResult 108 | override open func merge(unknownField: UnknownFieldSet) throws -> Self 109 | { 110 | let result:GeneratedMessage = internalGetResult 111 | result.unknownFields = try UnknownFieldSet.builderWithUnknownFields(copyFrom: result.unknownFields).merge(unknownFields: unknownField).build() 112 | return self 113 | } 114 | public func parse(codedInputStream:CodedInputStream ,unknownFields:UnknownFieldSet.Builder, extensionRegistry:ExtensionRegistry, tag:Int32) throws -> Bool { 115 | return try unknownFields.mergeFieldFrom(tag: tag, input:codedInputStream) 116 | } 117 | } 118 | 119 | extension GeneratedMessage:CustomDebugStringConvertible { 120 | public var debugDescription:String { 121 | return description 122 | } 123 | } 124 | 125 | extension GeneratedMessage:CustomStringConvertible { 126 | public var description:String { 127 | get { 128 | var output:String = "" 129 | output += try! getDescription(indent: "") 130 | return output 131 | } 132 | } 133 | } 134 | 135 | extension GeneratedMessageBuilder:CustomDebugStringConvertible { 136 | public var debugDescription:String { 137 | return internalGetResult.description 138 | } 139 | } 140 | extension GeneratedMessageBuilder:CustomStringConvertible { 141 | public var description:String { 142 | get { 143 | return internalGetResult.description 144 | } 145 | } 146 | } 147 | 148 | -------------------------------------------------------------------------------- /Source/ProtocolBuffers.h: -------------------------------------------------------------------------------- 1 | // 2 | // ProtocolBuffers.h 3 | // ProtocolBuffers 4 | // 5 | // Created by Alexey Khokhlov on 15.09.14. 6 | // Copyright (c) 2014 alexeyxo. All rights reserved. 7 | // 8 | 9 | #import 10 | //! Project version number for ProtocolBuffers. 11 | FOUNDATION_EXPORT double ProtocolBuffersVersionNumber; 12 | 13 | //! Project version string for ProtocolBuffers. 14 | FOUNDATION_EXPORT const unsigned char ProtocolBuffersVersionString[]; 15 | // In this header, you should import all the public headers of your framework using statements like #import 16 | 17 | 18 | -------------------------------------------------------------------------------- /Source/RingBuffer.swift: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License") 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | import Foundation 19 | 20 | internal struct Buffer { 21 | internal var buffer:[UInt8] 22 | var position:Int = 0 23 | var tail:Int = 0 24 | 25 | init(data:Data) { 26 | buffer = [UInt8](data) 27 | } 28 | func freeSpace() -> Int { 29 | var res:Int = 0 30 | 31 | if position < tail { 32 | res = tail - position 33 | } 34 | else { 35 | let dataLength = buffer.count 36 | res = (dataLength - position) + tail 37 | } 38 | 39 | if tail != 0 { 40 | res -= 1 41 | } 42 | return res 43 | } 44 | 45 | mutating func appendByte(byte:UInt8) -> Bool { 46 | if freeSpace() < 1 { 47 | return false 48 | } 49 | buffer[position] = byte 50 | position+=1 51 | return true 52 | } 53 | 54 | mutating func appendData(input:Data, offset:Int, length:Int) -> Int { 55 | var totalWritten:Int = 0 56 | var aLength = length 57 | var aOffset = offset 58 | var inputs = [UInt8](input) 59 | // let pointer = UnsafeMutablePointerUInt8From(data: buffer) 60 | if position >= tail { 61 | totalWritten = min(buffer.count - position, aLength) 62 | memcpy(&buffer + Int(position), &inputs + Int(aOffset), Int(totalWritten)) 63 | // buffer[position..<(position+totalWritten)] = input[aOffset.. Int { 98 | var totalWritten:Int = 0 99 | 100 | 101 | if tail > position { 102 | 103 | let written:Int = stream.write(&buffer + tail, maxLength:buffer.count - tail) 104 | if written <= 0 { 105 | return totalWritten 106 | } 107 | totalWritten += written 108 | tail += written 109 | if tail == buffer.count { 110 | tail = 0 111 | } 112 | } 113 | 114 | if tail < position { 115 | let written = stream.write(&buffer + tail, maxLength:position - tail) 116 | if written <= 0 { 117 | return totalWritten 118 | } 119 | totalWritten += written 120 | tail += written 121 | } 122 | if tail == position { 123 | tail = 0 124 | position = 0 125 | } 126 | if position == buffer.count && tail > 0 { 127 | position = 0 128 | } 129 | if tail == buffer.count { 130 | tail = 0 131 | } 132 | 133 | return totalWritten 134 | } 135 | 136 | 137 | } 138 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # 3 | # This script regenerates the autoconf-based configure script. The resulting 4 | # files aren't managed by source control but are included in the distribution. 5 | 6 | set -ex 7 | 8 | mkdir -p m4 9 | autoreconf -f -i -Wall 10 | rm -rf autom4te.cache configure.ac~ config.h.in~ 11 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_PREREQ(2.61) 2 | 3 | AC_INIT([protobuf-plugin-swift],[1.0],[alexeyxo.gmail.com],[protobuf-plugin-swift]) 4 | 5 | AC_CONFIG_SRCDIR(plugin/compiler/main.cc) 6 | AC_CONFIG_HEADERS([config.h]) 7 | AC_CONFIG_MACRO_DIR([m4]) 8 | 9 | AC_CANONICAL_TARGET 10 | AM_INIT_AUTOMAKE([subdir-objects]) 11 | 12 | # Check for programs 13 | AC_PROG_CC 14 | AC_PROG_CXX 15 | AC_LANG([C++]) 16 | 17 | AC_MSG_CHECKING([C++ compiler flags...]) 18 | AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],[ 19 | # Disable debugging checks by default. 20 | CXXFLAGS="$CXXFLAGS -DNDEBUG" 21 | AC_MSG_RESULT([use default: $CXXFLAGS]) 22 | ],[ 23 | AC_MSG_RESULT([use user-supplied: $CXXFLAGS]) 24 | ]) 25 | 26 | LT_INIT 27 | 28 | # Check for header files 29 | AC_HEADER_STDC 30 | AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h stdlib.h unistd.h]) 31 | 32 | # Check for libaries 33 | AC_FUNC_MEMCMP 34 | AC_FUNC_STRTOD 35 | AC_CHECK_FUNCS([ftruncate memset mkdir strchr strerror strtol]) 36 | 37 | # Locate the protobuf library. 38 | 39 | pbc_savelibs="$LIBS" 40 | LIBS="$LIBS -lprotoc -lprotobuf -lpthread" 41 | CFLAGS="$CFLAGS -DOBJC_ARC" 42 | AC_LINK_IFELSE( 43 | [AC_LANG_PROGRAM([[#include ]], 44 | [[google::protobuf::compiler::CommandLineInterface cli;]])], 45 | [], 46 | [AC_MSG_ERROR([ 47 | ERROR: 48 | protobuf test program failed to link: 49 | perhaps you need to add -Llibdir to your LDFLAGS.])]) 50 | LIBS="$pbc_savelibs" 51 | CXXFLAGS="$CXXFLAGS -std=c++11 -g" 52 | 53 | AC_CONFIG_FILES([Makefile plugin/compiler/Makefile]) 54 | AC_OUTPUT 55 | -------------------------------------------------------------------------------- /plugin/Tests/ErrorHandlingTest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ErrorHandlingTest.swift 3 | // ProtocolBuffers 4 | // 5 | // Created by Alexey Khokhlov on 03.09.16. 6 | // Copyright © 2016 alexeyxo. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | import ProtocolBuffers 11 | class ErrorHandlingTest: XCTestCase { 12 | 13 | override func setUp() { 14 | super.setUp() 15 | 16 | } 17 | 18 | override func tearDown() { 19 | 20 | super.tearDown() 21 | } 22 | 23 | func testEnumError() { 24 | do { 25 | try throwException() 26 | } catch let err as ServiceError where err == .internalServerError { 27 | XCTAssertTrue(true) 28 | } catch { 29 | XCTAssertTrue(false) 30 | } 31 | 32 | } 33 | 34 | func testMessageError() { 35 | do { 36 | try throwExceptionMessage() 37 | } catch let err as UserProfile.Exception { 38 | print(err) 39 | XCTAssertTrue(true) 40 | } catch { 41 | XCTAssertTrue(false) 42 | } 43 | 44 | } 45 | 46 | func throwException() throws { 47 | let user = UserProfile.Response.Builder() 48 | user.error = .internalServerError 49 | let data = try user.build().data() 50 | let userError = try UserProfile.Response.parseFrom(data:data) 51 | if userError.hasError { 52 | throw userError.error 53 | } 54 | 55 | } 56 | 57 | func throwExceptionMessage() throws { 58 | let exception = UserProfile.Exception.Builder() 59 | exception.errorCode = 403 60 | exception.errorDescription = "Bad Request" 61 | let exc = try exception.build() 62 | let data = try UserProfile.Response.Builder().setException(exc).build().data() 63 | let userError = try UserProfile.Response.parseFrom(data:data) 64 | if userError.hasException { 65 | throw userError.exception 66 | } 67 | 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /plugin/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /plugin/Tests/MapFieldsTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MapFieldsTests.swift 3 | // ProtocolBuffers 4 | // 5 | // Created by Alexey Khokhlov on 20.05.15. 6 | // Copyright (c) 2015 alexeyxo. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | import Foundation 11 | import ProtocolBuffers 12 | class MapFieldsTests: XCTestCase { 13 | 14 | func testMapsFields() 15 | { 16 | do { 17 | let mes1Builder = SwiftProtobufUnittest.MessageContainsMap.Builder() 18 | mes1Builder.mapInt32Int32 = [1:2] 19 | mes1Builder.mapInt64Int64 = [3:4] 20 | mes1Builder.mapStringString = ["a":"b"] 21 | mes1Builder.mapStringBytes = ["d":CodedInputStreamTests().bytesArray(from: [1,2,3,4])] 22 | let containingMessage = try SwiftProtobufUnittest.MapMessageValue.Builder().setValueInMapMessage(32).build() 23 | mes1Builder.mapStringMessage = ["c":containingMessage] 24 | let mes1 = try mes1Builder.build() 25 | let mes2 = try SwiftProtobufUnittest.MessageContainsMap.Builder().mergeFrom(other:mes1).build() 26 | XCTAssert(mes1 == mes2, "") 27 | XCTAssert(mes2.mapInt32Int32 == [1:2], "") 28 | XCTAssert(mes2.mapInt64Int64 == [3:4], "") 29 | XCTAssert(mes2.mapStringString == ["a":"b"], "") 30 | XCTAssert(mes2.mapStringMessage == ["c":containingMessage], "") 31 | XCTAssert(mes2.mapStringMessage["c"]?.valueInMapMessage == 32, "") 32 | } 33 | catch { 34 | XCTFail("testMapsFields") 35 | } 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /plugin/Tests/PluginTest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PluginTest.swift 3 | // Tests 4 | // 5 | // Created by Alexey Khokhlov on 18.10.2017. 6 | // 7 | 8 | import XCTest 9 | import ProtocolBuffers 10 | 11 | class PluginTest: XCTestCase { 12 | 13 | // func testParse() { 14 | // let data = Data(base64Encoded: testData) 15 | // let request = try! Google.Protobuf.Compiler.CodeGeneratorRequest.parseFrom(data: data!) 16 | // let generate = request.protoFile.filter({ 17 | // return request.fileToGenerate.contains($0.name) 18 | // }) 19 | // 20 | // generate.forEach({ file in 21 | // file.messageType.forEach({ message in 22 | // if message.options != nil { 23 | // if message.options.hasExtension(extensions: Google.Protobuf.SwiftDescriptorRoot.swiftMessageOptions()) { 24 | // if let option = message.options.getExtension(extensions: Google.Protobuf.SwiftDescriptorRoot.swiftMessageOptions()) as? Google.Protobuf.SwiftMessageOptions { 25 | // print(option.generateRealmObject) 26 | // } 27 | // } 28 | // } 29 | // }) 30 | // }) 31 | // XCTAssertNotNil(request) 32 | // 33 | // } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /plugin/Tests/ProtocolBuffersTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ProtocolBuffersTests.swift 3 | // ProtocolBuffersTests 4 | // 5 | // Created by Alexey Khokhlov on 15.09.14. 6 | // Copyright (c) 2014 alexeyxo. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import XCTest 11 | import ProtocolBuffers 12 | class ProtocolBuffersTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | } 17 | 18 | override func tearDown() { 19 | super.tearDown() 20 | } 21 | 22 | func testPerformance() { 23 | // let builder = AppSharedDialog.Builder() 24 | // builder.setId(123456789) 25 | // let build = try! builder.build() 26 | // let js = try! build.encode() 27 | // let js2 = try! AppSharedDialog.decode(jsonMap: js) 28 | // print(js2) 29 | 30 | 31 | // var originalBuilder = PBPerfomance.Builder() 32 | // originalBuilder.setInts(Int32(-32)) 33 | // .setInts64(Int64(-64)) 34 | // .setDoubles(Double(12.12)) 35 | // .setFloats(Float(123.123)) 36 | // .setStr("string") 37 | // let original = originalBuilder.build() 38 | // 39 | // let original2 = PBPerfomance.parseFrom(original.data()) 40 | // var builder = PBPerfomanceBatch.Builder() 41 | // 42 | // for in 0...2 { 43 | // builder.batch += [original] 44 | // } 45 | // 46 | // var user:PBUser! = nil 47 | // var group = PBGroup.Builder() 48 | // 49 | // group.getOwnerBuilder().setGroupName("asdfasdf") 50 | // 51 | // var bazBuilder = PBBaz.Builder() 52 | // bazBuilder.getBarBuilder().getFooBuilder().setVal(10) 53 | 54 | 55 | 56 | // let build = builder.build() 57 | // 58 | self.measure() { 59 | // var baz = bazBuilder.build() 60 | // var gg = group.build() 61 | // println(baz) 62 | // println(gg) 63 | 64 | } 65 | } 66 | // 67 | // func testPerformanceJson() 68 | // { 69 | // 70 | // var dict:NSMutableDictionary = NSMutableDictionary() 71 | // 72 | // dict.setObject(NSNumber(int: 32), forKey: "ints") 73 | // 74 | // dict.setObject(NSNumber(integer: 64), forKey: "ints64") 75 | // 76 | // dict.setObject(NSNumber(float: 123.123), forKey: "floats") 77 | // 78 | // dict.setObject(NSNumber(double: 12.12), forKey: "double") 79 | // 80 | // dict.setObject("string", forKey: "string") 81 | // 82 | // var arr:Array = [] 83 | // for in 0...10000 84 | // { 85 | // arr += [dict] 86 | // } 87 | // 88 | // var res:NSMutableDictionary = NSMutableDictionary() 89 | // 90 | // res.setObject(arr, forKey: "object") 91 | // 92 | // var error:NSError? 93 | // 94 | // var jsonobject = NSJSONSerialization.dataWithJSONObject(res, options: NSJSONWritingOptions.PrettyPrinted, error:&error) 95 | // 96 | // self.measureBlock() { 97 | // 98 | // for in 0...1 { 99 | // 100 | // var jsonErrorOptional:NSError? 101 | // let clone2: AnyObject! = NSJSONSerialization.JSONObjectWithData(jsonobject!, options: NSJSONReadingOptions(0), error: &jsonErrorOptional) 102 | // } 103 | // 104 | // } 105 | // 106 | // } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /plugin/Tests/SizeTest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SizeTest.swift 3 | // ProtocolBuffers 4 | // 5 | // Created by Alexey Khokhlov on 10.11.14. 6 | // Copyright (c) 2014 alexeyxo. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import XCTest 11 | 12 | class SizeTest: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | } 17 | 18 | override func tearDown() { 19 | super.tearDown() 20 | } 21 | 22 | func testTypeSizes() { 23 | XCTAssertTrue(4 == MemoryLayout.size) 24 | XCTAssertTrue(8 == MemoryLayout.size) 25 | XCTAssertTrue(8 == MemoryLayout.size) 26 | XCTAssertTrue(4 == MemoryLayout.size) 27 | XCTAssertTrue(4 == MemoryLayout.size) 28 | XCTAssertTrue(8 == MemoryLayout.size) 29 | XCTAssertTrue(1 == MemoryLayout.size) 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /plugin/Tests/SmallBlockInputStream.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SmallBlockInputStream.swift 3 | // ProtocolBuffers 4 | // 5 | // Created by Alexey Khokhlov on 03.08.14. 6 | // Copyright (c) 2014 Alexey Khokhlov. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | class SmallBlockInputStream:InputStream { 12 | var underlyingStream:InputStream? 13 | var blockSize:Int32 = 0 14 | 15 | func setup(data aData:Data, blocksSize:Int32) { 16 | underlyingStream = InputStream(data: aData) 17 | blockSize = blocksSize 18 | } 19 | 20 | override func open() { 21 | underlyingStream!.open() 22 | } 23 | override func close() { 24 | underlyingStream!.close() 25 | } 26 | override func read(_ buffer: UnsafeMutablePointer, maxLength len: Int) -> Int { 27 | return underlyingStream!.read(buffer, maxLength:min(len, Int(blockSize))) 28 | } 29 | 30 | override internal func getBuffer(_ buffer: UnsafeMutablePointer?>, length len: UnsafeMutablePointer) -> Bool { 31 | return underlyingStream!.getBuffer(buffer, length: len) 32 | } 33 | 34 | override var hasBytesAvailable:Bool { 35 | get { 36 | return underlyingStream!.hasBytesAvailable 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /plugin/Tests/WireFormatTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // WireFormatTests.swift 3 | // ProtocolBuffers 4 | // 5 | // Created by Alexey Khokhlov on 12.11.14. 6 | // Copyright (c) 2014 alexeyxo. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import XCTest 11 | import ProtocolBuffers 12 | 13 | class WireFormatTests: XCTestCase { 14 | 15 | override func setUp() { 16 | super.setUp() 17 | } 18 | 19 | override func tearDown() { 20 | super.tearDown() 21 | } 22 | func testSerialization() { 23 | do { 24 | let message = try TestUtilities.allSet() 25 | let rawBytes = message.data() 26 | XCTAssertTrue(rawBytes.count == Int(message.serializedSize()), "") 27 | let message2 = try ProtobufUnittest.TestAllTypes.parseFrom(data:rawBytes) 28 | TestUtilities.assertAllFieldsSet(message2) 29 | } 30 | catch 31 | { 32 | XCTFail("testSerialization") 33 | } 34 | 35 | } 36 | 37 | func testSerializationPacked() { 38 | do { 39 | let message = try TestUtilities.packedSet() 40 | let rawBytes = message.data() 41 | XCTAssertTrue(rawBytes.count == Int(message.serializedSize()), "") 42 | let message2 = try ProtobufUnittest.TestPackedTypes.parseFrom(data:rawBytes) 43 | TestUtilities.assertPackedFieldsSet(message2) 44 | } 45 | catch { 46 | XCTFail("testSerializationPacked") 47 | } 48 | 49 | } 50 | 51 | func testSerializeExtensions() { 52 | do { 53 | let message = try TestUtilities.allExtensionsSet() 54 | let rawBytes = message.data() 55 | XCTAssertTrue(rawBytes.count == Int(message.serializedSize()), "") 56 | let message2 = try ProtobufUnittest.TestAllTypes.parseFrom(data:rawBytes) 57 | TestUtilities.assertAllFieldsSet(message2) 58 | } 59 | catch { 60 | XCTFail("testSerializeExtensions") 61 | } 62 | } 63 | func testSerializePackedExtensions() { 64 | do { 65 | // TestPackedTypes and TestPackedExtensions should have compatible wire 66 | // formats check that they serialize to the same string. 67 | let message = try TestUtilities.packedExtensionsSet() 68 | let rawBytes = message.data() 69 | let message2 = try TestUtilities.packedSet() 70 | let rawBytes2 = message2.data() 71 | XCTAssertTrue(rawBytes == rawBytes2, "") 72 | } 73 | catch { 74 | XCTFail("testSerializePackedExtensions") 75 | } 76 | 77 | } 78 | 79 | func testParseExtensions() { 80 | do { 81 | // TestAllTypes and TestAllExtensions should have compatible wire formats, 82 | // so if we serealize a TestAllTypes then parse it as TestAllExtensions 83 | // it should work. 84 | let message = try TestUtilities.allSet() 85 | let rawBytes = message.data() 86 | let registry = ExtensionRegistry() 87 | TestUtilities.registerAllExtensions(registry) 88 | let message2 = try ProtobufUnittest.TestAllExtensions.parseFrom(data:rawBytes, extensionRegistry:registry) 89 | TestUtilities.assertAllExtensionsSet(message2) 90 | } 91 | catch { 92 | XCTFail("testParseExtensions") 93 | } 94 | 95 | } 96 | 97 | func testExtensionsSerializedSize() { 98 | 99 | do { 100 | let allset = try TestUtilities.allSet().serializedSize() 101 | let extSet = try TestUtilities.allExtensionsSet().serializedSize() 102 | XCTAssertTrue(allset == extSet, "") 103 | } 104 | catch { 105 | XCTFail("testExtensionsSerializedSize") 106 | } 107 | 108 | } 109 | 110 | func testParsePackedExtensions() { 111 | do { 112 | let message = try TestUtilities.packedExtensionsSet() 113 | let rawBytes = message.data() 114 | let registry = TestUtilities.extensionRegistry() 115 | let message2 = try ProtobufUnittest.TestPackedExtensions.parseFrom(data:rawBytes, extensionRegistry:registry) 116 | TestUtilities.assertPackedExtensionsSet(message2) 117 | } 118 | catch { 119 | XCTFail("testParsePackedExtensions") 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /plugin/Tests/pbTests/ThreadingTest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TheradingTest.swift 3 | // ProtocolBuffers 4 | // 5 | // Created by Alexey Khokhlov on 01.06.15. 6 | // Copyright (c) 2015 alexeyxo. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import ProtocolBuffers 11 | import XCTest 12 | // 13 | //class Threading { 14 | // 15 | // let queue = dispatch_queue_create("test.testThread", DISPATCH_QUEUE_SERIAL) 16 | // 17 | // init() { 18 | // } 19 | // func send(message:GeneratedMessageBuilder?) { 20 | // if let messageBuilder = message { 21 | // queueToThread() { 22 | // messageBuilder.build().data() 23 | // print("\(messageBuilder.build().data())", appendNewline: false) 24 | // } 25 | // } 26 | // } 27 | // func queueToThread(runnable:() -> Void) { 28 | // dispatch_async(queue) { 29 | // runnable() 30 | // } 31 | // } 32 | //} 33 | // 34 | //class ThreadingTest: XCTestCase { 35 | // 36 | // override func setUp() { 37 | // super.setUp() 38 | // } 39 | // 40 | // override func tearDown() { 41 | // super.tearDown() 42 | // } 43 | // 44 | // func testThreading() { 45 | // 46 | // let message = ThreadingMessages.Builder() 47 | // message.testString = "sadfasdfa" 48 | // let threading = Threading() 49 | // threading.send(message) 50 | // } 51 | //} 52 | -------------------------------------------------------------------------------- /plugin/Tests/pbTests/UnittestEmpty.proto.swift: -------------------------------------------------------------------------------- 1 | /// Generated by the Protocol Buffers 3.6.0 compiler. DO NOT EDIT! 2 | /// Protobuf-swift version: 4.0.0 3 | /// Source file "unittest_empty.proto" 4 | /// Syntax "Proto2" 5 | 6 | import Foundation 7 | import ProtocolBuffers 8 | 9 | 10 | public struct UnittestEmptyRoot { 11 | public static let `default` = UnittestEmptyRoot() 12 | public var extensionRegistry:ExtensionRegistry 13 | 14 | init() { 15 | extensionRegistry = ExtensionRegistry() 16 | registerAllExtensions(registry: extensionRegistry) 17 | } 18 | public func registerAllExtensions(registry: ExtensionRegistry) { 19 | } 20 | } 21 | 22 | 23 | // @@protoc_insertion_point(global_scope) 24 | -------------------------------------------------------------------------------- /plugin/Tests/pbTests/testdata/bad_utf8_string: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexeyxo/protobuf-swift/f396f02cff0781db3857056b96adc424fb336b96/plugin/Tests/pbTests/testdata/bad_utf8_string -------------------------------------------------------------------------------- /plugin/Tests/pbTests/testdata/delimitedFile.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexeyxo/protobuf-swift/f396f02cff0781db3857056b96adc424fb336b96/plugin/Tests/pbTests/testdata/delimitedFile.dat -------------------------------------------------------------------------------- /plugin/Tests/pbTests/testdata/golden_message: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexeyxo/protobuf-swift/f396f02cff0781db3857056b96adc424fb336b96/plugin/Tests/pbTests/testdata/golden_message -------------------------------------------------------------------------------- /plugin/Tests/pbTests/testdata/golden_message_oneof_implemented: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexeyxo/protobuf-swift/f396f02cff0781db3857056b96adc424fb336b96/plugin/Tests/pbTests/testdata/golden_message_oneof_implemented -------------------------------------------------------------------------------- /plugin/Tests/pbTests/testdata/golden_packed_fields_message: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexeyxo/protobuf-swift/f396f02cff0781db3857056b96adc424fb336b96/plugin/Tests/pbTests/testdata/golden_packed_fields_message -------------------------------------------------------------------------------- /plugin/Tests/pbTests/testdata/text_format_unittest_data.txt: -------------------------------------------------------------------------------- 1 | optional_int32: 101 2 | optional_int64: 102 3 | optional_uint32: 103 4 | optional_uint64: 104 5 | optional_sint32: 105 6 | optional_sint64: 106 7 | optional_fixed32: 107 8 | optional_fixed64: 108 9 | optional_sfixed32: 109 10 | optional_sfixed64: 110 11 | optional_float: 111 12 | optional_double: 112 13 | optional_bool: true 14 | optional_string: "115" 15 | optional_bytes: "116" 16 | OptionalGroup { 17 | a: 117 18 | } 19 | optional_nested_message { 20 | bb: 118 21 | } 22 | optional_foreign_message { 23 | c: 119 24 | } 25 | optional_import_message { 26 | d: 120 27 | } 28 | optional_nested_enum: BAZ 29 | optional_foreign_enum: FOREIGN_BAZ 30 | optional_import_enum: IMPORT_BAZ 31 | optional_string_piece: "124" 32 | optional_cord: "125" 33 | optional_public_import_message { 34 | e: 126 35 | } 36 | optional_lazy_message { 37 | bb: 127 38 | } 39 | repeated_int32: 201 40 | repeated_int32: 301 41 | repeated_int64: 202 42 | repeated_int64: 302 43 | repeated_uint32: 203 44 | repeated_uint32: 303 45 | repeated_uint64: 204 46 | repeated_uint64: 304 47 | repeated_sint32: 205 48 | repeated_sint32: 305 49 | repeated_sint64: 206 50 | repeated_sint64: 306 51 | repeated_fixed32: 207 52 | repeated_fixed32: 307 53 | repeated_fixed64: 208 54 | repeated_fixed64: 308 55 | repeated_sfixed32: 209 56 | repeated_sfixed32: 309 57 | repeated_sfixed64: 210 58 | repeated_sfixed64: 310 59 | repeated_float: 211 60 | repeated_float: 311 61 | repeated_double: 212 62 | repeated_double: 312 63 | repeated_bool: true 64 | repeated_bool: false 65 | repeated_string: "215" 66 | repeated_string: "315" 67 | repeated_bytes: "216" 68 | repeated_bytes: "316" 69 | RepeatedGroup { 70 | a: 217 71 | } 72 | RepeatedGroup { 73 | a: 317 74 | } 75 | repeated_nested_message { 76 | bb: 218 77 | } 78 | repeated_nested_message { 79 | bb: 318 80 | } 81 | repeated_foreign_message { 82 | c: 219 83 | } 84 | repeated_foreign_message { 85 | c: 319 86 | } 87 | repeated_import_message { 88 | d: 220 89 | } 90 | repeated_import_message { 91 | d: 320 92 | } 93 | repeated_nested_enum: BAR 94 | repeated_nested_enum: BAZ 95 | repeated_foreign_enum: FOREIGN_BAR 96 | repeated_foreign_enum: FOREIGN_BAZ 97 | repeated_import_enum: IMPORT_BAR 98 | repeated_import_enum: IMPORT_BAZ 99 | repeated_string_piece: "224" 100 | repeated_string_piece: "324" 101 | repeated_cord: "225" 102 | repeated_cord: "325" 103 | repeated_lazy_message { 104 | bb: 227 105 | } 106 | repeated_lazy_message { 107 | bb: 327 108 | } 109 | default_int32: 401 110 | default_int64: 402 111 | default_uint32: 403 112 | default_uint64: 404 113 | default_sint32: 405 114 | default_sint64: 406 115 | default_fixed32: 407 116 | default_fixed64: 408 117 | default_sfixed32: 409 118 | default_sfixed64: 410 119 | default_float: 411 120 | default_double: 412 121 | default_bool: false 122 | default_string: "415" 123 | default_bytes: "416" 124 | default_nested_enum: FOO 125 | default_foreign_enum: FOREIGN_FOO 126 | default_import_enum: IMPORT_FOO 127 | default_string_piece: "424" 128 | default_cord: "425" 129 | oneof_uint32: 601 130 | oneof_nested_message { 131 | bb: 602 132 | } 133 | oneof_string: "603" 134 | oneof_bytes: "604" 135 | -------------------------------------------------------------------------------- /plugin/Tests/pbTests/testdata/text_format_unittest_data_oneof_implemented.txt: -------------------------------------------------------------------------------- 1 | optional_int32: 101 2 | optional_int64: 102 3 | optional_uint32: 103 4 | optional_uint64: 104 5 | optional_sint32: 105 6 | optional_sint64: 106 7 | optional_fixed32: 107 8 | optional_fixed64: 108 9 | optional_sfixed32: 109 10 | optional_sfixed64: 110 11 | optional_float: 111 12 | optional_double: 112 13 | optional_bool: true 14 | optional_string: "115" 15 | optional_bytes: "116" 16 | OptionalGroup { 17 | a: 117 18 | } 19 | optional_nested_message { 20 | bb: 118 21 | } 22 | optional_foreign_message { 23 | c: 119 24 | } 25 | optional_import_message { 26 | d: 120 27 | } 28 | optional_nested_enum: BAZ 29 | optional_foreign_enum: FOREIGN_BAZ 30 | optional_import_enum: IMPORT_BAZ 31 | optional_string_piece: "124" 32 | optional_cord: "125" 33 | optional_public_import_message { 34 | e: 126 35 | } 36 | optional_lazy_message { 37 | bb: 127 38 | } 39 | repeated_int32: 201 40 | repeated_int32: 301 41 | repeated_int64: 202 42 | repeated_int64: 302 43 | repeated_uint32: 203 44 | repeated_uint32: 303 45 | repeated_uint64: 204 46 | repeated_uint64: 304 47 | repeated_sint32: 205 48 | repeated_sint32: 305 49 | repeated_sint64: 206 50 | repeated_sint64: 306 51 | repeated_fixed32: 207 52 | repeated_fixed32: 307 53 | repeated_fixed64: 208 54 | repeated_fixed64: 308 55 | repeated_sfixed32: 209 56 | repeated_sfixed32: 309 57 | repeated_sfixed64: 210 58 | repeated_sfixed64: 310 59 | repeated_float: 211 60 | repeated_float: 311 61 | repeated_double: 212 62 | repeated_double: 312 63 | repeated_bool: true 64 | repeated_bool: false 65 | repeated_string: "215" 66 | repeated_string: "315" 67 | repeated_bytes: "216" 68 | repeated_bytes: "316" 69 | RepeatedGroup { 70 | a: 217 71 | } 72 | RepeatedGroup { 73 | a: 317 74 | } 75 | repeated_nested_message { 76 | bb: 218 77 | } 78 | repeated_nested_message { 79 | bb: 318 80 | } 81 | repeated_foreign_message { 82 | c: 219 83 | } 84 | repeated_foreign_message { 85 | c: 319 86 | } 87 | repeated_import_message { 88 | d: 220 89 | } 90 | repeated_import_message { 91 | d: 320 92 | } 93 | repeated_nested_enum: BAR 94 | repeated_nested_enum: BAZ 95 | repeated_foreign_enum: FOREIGN_BAR 96 | repeated_foreign_enum: FOREIGN_BAZ 97 | repeated_import_enum: IMPORT_BAR 98 | repeated_import_enum: IMPORT_BAZ 99 | repeated_string_piece: "224" 100 | repeated_string_piece: "324" 101 | repeated_cord: "225" 102 | repeated_cord: "325" 103 | repeated_lazy_message { 104 | bb: 227 105 | } 106 | repeated_lazy_message { 107 | bb: 327 108 | } 109 | default_int32: 401 110 | default_int64: 402 111 | default_uint32: 403 112 | default_uint64: 404 113 | default_sint32: 405 114 | default_sint64: 406 115 | default_fixed32: 407 116 | default_fixed64: 408 117 | default_sfixed32: 409 118 | default_sfixed64: 410 119 | default_float: 411 120 | default_double: 412 121 | default_bool: false 122 | default_string: "415" 123 | default_bytes: "416" 124 | default_nested_enum: FOO 125 | default_foreign_enum: FOREIGN_FOO 126 | default_import_enum: IMPORT_FOO 127 | default_string_piece: "424" 128 | default_cord: "425" 129 | oneof_bytes: "604" 130 | -------------------------------------------------------------------------------- /plugin/Tests/pbTests/testdata/text_format_unittest_data_pointy.txt: -------------------------------------------------------------------------------- 1 | optional_int32: 101 2 | optional_int64: 102 3 | optional_uint32: 103 4 | optional_uint64: 104 5 | optional_sint32: 105 6 | optional_sint64: 106 7 | optional_fixed32: 107 8 | optional_fixed64: 108 9 | optional_sfixed32: 109 10 | optional_sfixed64: 110 11 | optional_float: 111 12 | optional_double: 112 13 | optional_bool: true 14 | optional_string: "115" 15 | optional_bytes: "116" 16 | OptionalGroup < 17 | a: 117 18 | > 19 | optional_nested_message < 20 | bb: 118 21 | > 22 | optional_foreign_message < 23 | c: 119 24 | > 25 | optional_import_message < 26 | d: 120 27 | > 28 | optional_nested_enum: BAZ 29 | optional_foreign_enum: FOREIGN_BAZ 30 | optional_import_enum: IMPORT_BAZ 31 | optional_string_piece: "124" 32 | optional_cord: "125" 33 | optional_public_import_message < 34 | e: 126 35 | > 36 | optional_lazy_message < 37 | bb: 127 38 | > 39 | repeated_int32: 201 40 | repeated_int32: 301 41 | repeated_int64: 202 42 | repeated_int64: 302 43 | repeated_uint32: 203 44 | repeated_uint32: 303 45 | repeated_uint64: 204 46 | repeated_uint64: 304 47 | repeated_sint32: 205 48 | repeated_sint32: 305 49 | repeated_sint64: 206 50 | repeated_sint64: 306 51 | repeated_fixed32: 207 52 | repeated_fixed32: 307 53 | repeated_fixed64: 208 54 | repeated_fixed64: 308 55 | repeated_sfixed32: 209 56 | repeated_sfixed32: 309 57 | repeated_sfixed64: 210 58 | repeated_sfixed64: 310 59 | repeated_float: 211 60 | repeated_float: 311 61 | repeated_double: 212 62 | repeated_double: 312 63 | repeated_bool: true 64 | repeated_bool: false 65 | repeated_string: "215" 66 | repeated_string: "315" 67 | repeated_bytes: "216" 68 | repeated_bytes: "316" 69 | RepeatedGroup < 70 | a: 217 71 | > 72 | RepeatedGroup < 73 | a: 317 74 | > 75 | repeated_nested_message < 76 | bb: 218 77 | > 78 | repeated_nested_message < 79 | bb: 318 80 | > 81 | repeated_foreign_message < 82 | c: 219 83 | > 84 | repeated_foreign_message < 85 | c: 319 86 | > 87 | repeated_import_message < 88 | d: 220 89 | > 90 | repeated_import_message < 91 | d: 320 92 | > 93 | repeated_nested_enum: BAR 94 | repeated_nested_enum: BAZ 95 | repeated_foreign_enum: FOREIGN_BAR 96 | repeated_foreign_enum: FOREIGN_BAZ 97 | repeated_import_enum: IMPORT_BAR 98 | repeated_import_enum: IMPORT_BAZ 99 | repeated_string_piece: "224" 100 | repeated_string_piece: "324" 101 | repeated_cord: "225" 102 | repeated_cord: "325" 103 | repeated_lazy_message < 104 | bb: 227 105 | > 106 | repeated_lazy_message < 107 | bb: 327 108 | > 109 | default_int32: 401 110 | default_int64: 402 111 | default_uint32: 403 112 | default_uint64: 404 113 | default_sint32: 405 114 | default_sint64: 406 115 | default_fixed32: 407 116 | default_fixed64: 408 117 | default_sfixed32: 409 118 | default_sfixed64: 410 119 | default_float: 411 120 | default_double: 412 121 | default_bool: false 122 | default_string: "415" 123 | default_bytes: "416" 124 | default_nested_enum: FOO 125 | default_foreign_enum: FOREIGN_FOO 126 | default_import_enum: IMPORT_FOO 127 | default_string_piece: "424" 128 | default_cord: "425" 129 | oneof_uint32: 601 130 | oneof_nested_message < 131 | bb: 602 132 | > 133 | oneof_string: "603" 134 | oneof_bytes: "604" 135 | -------------------------------------------------------------------------------- /plugin/Tests/pbTests/testdata/text_format_unittest_data_pointy_oneof.txt: -------------------------------------------------------------------------------- 1 | optional_int32: 101 2 | optional_int64: 102 3 | optional_uint32: 103 4 | optional_uint64: 104 5 | optional_sint32: 105 6 | optional_sint64: 106 7 | optional_fixed32: 107 8 | optional_fixed64: 108 9 | optional_sfixed32: 109 10 | optional_sfixed64: 110 11 | optional_float: 111 12 | optional_double: 112 13 | optional_bool: true 14 | optional_string: "115" 15 | optional_bytes: "116" 16 | OptionalGroup < 17 | a: 117 18 | > 19 | optional_nested_message < 20 | bb: 118 21 | > 22 | optional_foreign_message < 23 | c: 119 24 | > 25 | optional_import_message < 26 | d: 120 27 | > 28 | optional_nested_enum: BAZ 29 | optional_foreign_enum: FOREIGN_BAZ 30 | optional_import_enum: IMPORT_BAZ 31 | optional_string_piece: "124" 32 | optional_cord: "125" 33 | optional_public_import_message < 34 | e: 126 35 | > 36 | optional_lazy_message < 37 | bb: 127 38 | > 39 | repeated_int32: 201 40 | repeated_int32: 301 41 | repeated_int64: 202 42 | repeated_int64: 302 43 | repeated_uint32: 203 44 | repeated_uint32: 303 45 | repeated_uint64: 204 46 | repeated_uint64: 304 47 | repeated_sint32: 205 48 | repeated_sint32: 305 49 | repeated_sint64: 206 50 | repeated_sint64: 306 51 | repeated_fixed32: 207 52 | repeated_fixed32: 307 53 | repeated_fixed64: 208 54 | repeated_fixed64: 308 55 | repeated_sfixed32: 209 56 | repeated_sfixed32: 309 57 | repeated_sfixed64: 210 58 | repeated_sfixed64: 310 59 | repeated_float: 211 60 | repeated_float: 311 61 | repeated_double: 212 62 | repeated_double: 312 63 | repeated_bool: true 64 | repeated_bool: false 65 | repeated_string: "215" 66 | repeated_string: "315" 67 | repeated_bytes: "216" 68 | repeated_bytes: "316" 69 | RepeatedGroup < 70 | a: 217 71 | > 72 | RepeatedGroup < 73 | a: 317 74 | > 75 | repeated_nested_message < 76 | bb: 218 77 | > 78 | repeated_nested_message < 79 | bb: 318 80 | > 81 | repeated_foreign_message < 82 | c: 219 83 | > 84 | repeated_foreign_message < 85 | c: 319 86 | > 87 | repeated_import_message < 88 | d: 220 89 | > 90 | repeated_import_message < 91 | d: 320 92 | > 93 | repeated_nested_enum: BAR 94 | repeated_nested_enum: BAZ 95 | repeated_foreign_enum: FOREIGN_BAR 96 | repeated_foreign_enum: FOREIGN_BAZ 97 | repeated_import_enum: IMPORT_BAR 98 | repeated_import_enum: IMPORT_BAZ 99 | repeated_string_piece: "224" 100 | repeated_string_piece: "324" 101 | repeated_cord: "225" 102 | repeated_cord: "325" 103 | repeated_lazy_message < 104 | bb: 227 105 | > 106 | repeated_lazy_message < 107 | bb: 327 108 | > 109 | default_int32: 401 110 | default_int64: 402 111 | default_uint32: 403 112 | default_uint64: 404 113 | default_sint32: 405 114 | default_sint64: 406 115 | default_fixed32: 407 116 | default_fixed64: 408 117 | default_sfixed32: 409 118 | default_sfixed64: 410 119 | default_float: 411 120 | default_double: 412 121 | default_bool: false 122 | default_string: "415" 123 | default_bytes: "416" 124 | default_nested_enum: FOO 125 | default_foreign_enum: FOREIGN_FOO 126 | default_import_enum: IMPORT_FOO 127 | default_string_piece: "424" 128 | default_cord: "425" 129 | oneof_bytes: "604" 130 | -------------------------------------------------------------------------------- /plugin/Tests/testdata/delimitedFile.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexeyxo/protobuf-swift/f396f02cff0781db3857056b96adc424fb336b96/plugin/Tests/testdata/delimitedFile.dat -------------------------------------------------------------------------------- /plugin/compiler/Makefile.am: -------------------------------------------------------------------------------- 1 | MAINTAINERCLEANFILES = \ 2 | Makefile.in 3 | bin_PROGRAMS = protoc-gen-swift protoc-gen-swift_react 4 | protoc_gen_swift_LDFLAGS = -lprotobuf -lprotoc 5 | protoc_gen_swift_SOURCES = \ 6 | main.cc \ 7 | swift_enum_field.cc \ 8 | swift_map_field.cc \ 9 | swift_file.cc \ 10 | swift_message_field.cc \ 11 | swift_oneof.cc \ 12 | swift_enum.cc \ 13 | swift_generator.cc \ 14 | swift_primitive_field.cc \ 15 | swift_extension.cc \ 16 | swift_helpers.cc \ 17 | swift_field.cc \ 18 | swift_message.cc \ 19 | google/protobuf/swift-descriptor.pb.cc 20 | 21 | protoc_gen_swift_react_LDFLAGS = -lprotobuf -lprotoc 22 | protoc_gen_swift_react_SOURCES = \ 23 | react_native/main.cc \ 24 | react_native/swift_file.cc \ 25 | react_native/swift_generator.cc \ 26 | react_native/swift_react.cc \ 27 | swift_helpers.cc \ 28 | react_native/swift_helpers_react.cc \ 29 | react_native/swift_react_enums.cc \ 30 | google/protobuf/swift-descriptor.pb.cc 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /plugin/compiler/RESERVEDWORDS: -------------------------------------------------------------------------------- 1 | "TYPE_BOOL", 2 | "@available", 3 | "#column", 4 | "#else", 5 | "#elseif", 6 | "#endif", 7 | "#file", 8 | "#function", 9 | "#if", 10 | "#line", 11 | "#selector", 12 | "description", 13 | "debugDescription", 14 | "as", 15 | "associatedtype", 16 | "break", 17 | "case", 18 | "catch", 19 | "class", 20 | "continue", 21 | "default", 22 | "defer", 23 | "deinit", 24 | "do", 25 | "dynamicType", 26 | "else", 27 | "enum", 28 | "extension", 29 | "fallthrough", 30 | "false", 31 | "for", 32 | "func", 33 | "guard", 34 | "if", 35 | "import", 36 | "in", 37 | "init", 38 | "inout", 39 | "internal", 40 | "is", 41 | "protocol", 42 | "public", 43 | "repeat", 44 | "rethrows", 45 | "return", 46 | "self", 47 | "Self", 48 | "static", 49 | "struct", 50 | "subscript", 51 | "super", 52 | "switch", 53 | "throw", 54 | "throws", 55 | "true", 56 | "try", 57 | "typealias", 58 | "var", 59 | "where", 60 | "while", 61 | "Any", 62 | "associativity", 63 | "convenience", 64 | "dynamic", 65 | "didSet", 66 | "final", 67 | "get", 68 | "infix", 69 | "indirect", 70 | "lazy", 71 | "left", 72 | "mutating", 73 | "none", 74 | "nonmutating", 75 | "optional", 76 | "override", 77 | "postfix", 78 | "Protocol", 79 | "required", 80 | "right", 81 | "set", 82 | "Type", 83 | "unowned", 84 | "weak", 85 | "willSet", 86 | "String", 87 | "nil", 88 | "operator", 89 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/.dirstamp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexeyxo/protobuf-swift/f396f02cff0781db3857056b96adc424fb336b96/plugin/compiler/google/protobuf/.dirstamp -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/any.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | syntax = "proto3"; 31 | 32 | import 'google/protobuf/swift-descriptor.proto'; 33 | option (.google.protobuf.swift_file_options).compile_for_framework = false; 34 | option (.google.protobuf.swift_file_options).entities_access_control = PublicEntities; 35 | 36 | package google.protobuf; 37 | 38 | option java_generate_equals_and_hash = true; 39 | option java_multiple_files = true; 40 | option java_outer_classname = "AnyProto"; 41 | option java_package = "com.google.protobuf"; 42 | option csharp_namespace = "Google.ProtocolBuffers"; 43 | option objc_class_prefix = "GPB"; 44 | 45 | 46 | // `Any` contains an arbitrary serialized message along with a URL 47 | // that describes the type of the serialized message. 48 | // 49 | // The proto runtimes and/or compiler will eventually 50 | // provide utilities to pack/unpack Any values (projected Q1/15). 51 | // 52 | // # JSON 53 | // The JSON representation of an `Any` value uses the regular 54 | // representation of the deserialized, embedded message, with an 55 | // additional field `@type` which contains the type URL. Example: 56 | // 57 | // package google.profile; 58 | // message Person { 59 | // string first_name = 1; 60 | // string last_name = 2; 61 | // } 62 | // 63 | // { 64 | // "@type": "type.googleapis.com/google.profile.Person", 65 | // "firstName": , 66 | // "lastName": 67 | // } 68 | // 69 | // If the embedded message type is well-known and has a custom JSON 70 | // representation, that representation will be embedded adding a field 71 | // `value` which holds the custom JSON in addition to the the `@type` 72 | // field. Example (for message [google.protobuf.Duration][google.protobuf.Duration]): 73 | // 74 | // { 75 | // "@type": "type.googleapis.com/google.protobuf.Duration", 76 | // "value": "1.212s" 77 | // } 78 | // 79 | message Any { 80 | // A URL/resource name whose content describes the type of the 81 | // serialized message. 82 | // 83 | // For URLs which use the schema `http`, `https`, or no schema, the 84 | // following restrictions and interpretations apply: 85 | // 86 | // * If no schema is provided, `https` is assumed. 87 | // * The last segment of the URL's path must represent the fully 88 | // qualified name of the type (as in `path/google.protobuf.Duration`). 89 | // * An HTTP GET on the URL must yield a [google.protobuf.Type][google.protobuf.Type] 90 | // value in binary format, or produce an error. 91 | // * Applications are allowed to cache lookup results based on the 92 | // URL, or have them precompiled into a binary to avoid any 93 | // lookup. Therefore, binary compatibility needs to be preserved 94 | // on changes to types. (Use versioned type names to manage 95 | // breaking changes.) 96 | // 97 | // Schemas other than `http`, `https` (or the empty schema) might be 98 | // used with implementation specific semantics. 99 | // 100 | // Types originating from the `google.*` package 101 | // namespace should use `type.googleapis.com/full.type.name` (without 102 | // schema and path). A type service will eventually become available which 103 | // serves those URLs (projected Q2/15). 104 | string type_url = 1; 105 | 106 | // Must be valid serialized data of the above specified type. 107 | bytes value = 2; 108 | } 109 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/any_test.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package protobuf_unittest; 34 | 35 | import "google/protobuf/any.proto"; 36 | 37 | message TestAny { 38 | int32 int32_value = 1; 39 | google.protobuf.Any any_value = 2; 40 | repeated google.protobuf.Any repeated_any_value = 3; 41 | } 42 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/api.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | syntax = "proto3"; 31 | 32 | import 'google/protobuf/swift-descriptor.proto'; 33 | option (.google.protobuf.swift_file_options).compile_for_framework = false; 34 | option (.google.protobuf.swift_file_options).entities_access_control = PublicEntities; 35 | 36 | package google.protobuf; 37 | 38 | import "google/protobuf/source_context.proto"; 39 | import "google/protobuf/type.proto"; 40 | 41 | option java_multiple_files = true; 42 | option java_outer_classname = "ApiProto"; 43 | option java_package = "com.google.protobuf"; 44 | option objc_class_prefix = "GPB"; 45 | 46 | 47 | // Api is a light-weight descriptor for a protocol buffer service. 48 | message Api { 49 | // The fully qualified name of this api, including package name 50 | // followed by the api's simple name. 51 | string name = 1; 52 | 53 | // The methods of this api, in unspecified order. 54 | repeated Method methods = 2; 55 | 56 | // Any metadata attached to the API. 57 | repeated Option options = 3; 58 | 59 | // A version string for this api. If specified, must have the form 60 | // `major-version.minor-version`, as in `1.10`. If the minor version 61 | // is omitted, it defaults to zero. If the entire version field is 62 | // empty, the major version is derived from the package name, as 63 | // outlined below. If the field is not empty, the version in the 64 | // package name will be verified to be consistent with what is 65 | // provided here. 66 | // 67 | // The versioning schema uses [semantic 68 | // versioning](http://semver.org) where the major version number 69 | // indicates a breaking change and the minor version an additive, 70 | // non-breaking change. Both version numbers are signals to users 71 | // what to expect from different versions, and should be carefully 72 | // chosen based on the product plan. 73 | // 74 | // The major version is also reflected in the package name of the 75 | // API, which must end in `v`, as in 76 | // `google.feature.v1`. For major versions 0 and 1, the suffix can 77 | // be omitted. Zero major versions must only be used for 78 | // experimental, none-GA apis. 79 | // 80 | // See also: [design doc](http://go/api-versioning). 81 | // 82 | // 83 | string version = 4; 84 | 85 | // Source context for the protocol buffer service represented by this 86 | // message. 87 | SourceContext source_context = 5; 88 | } 89 | 90 | // Method represents a method of an api. 91 | message Method { 92 | // The simple name of this method. 93 | string name = 1; 94 | 95 | // A URL of the input message type. 96 | string request_type_url = 2; 97 | 98 | // If true, the request is streamed. 99 | bool request_streaming = 3; 100 | 101 | // The URL of the output message type. 102 | string response_type_url = 4; 103 | 104 | // If true, the response is streamed. 105 | bool response_streaming = 5; 106 | 107 | // Any metadata attached to the method. 108 | repeated Option options = 6; 109 | } 110 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/duration.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | syntax = "proto3"; 31 | 32 | import 'google/protobuf/swift-descriptor.proto'; 33 | option (.google.protobuf.swift_file_options).compile_for_framework = false; 34 | option (.google.protobuf.swift_file_options).entities_access_control = PublicEntities; 35 | 36 | package google.protobuf; 37 | 38 | option java_generate_equals_and_hash = true; 39 | option java_multiple_files = true; 40 | option java_outer_classname = "DurationProto"; 41 | option java_package = "com.google.protobuf"; 42 | option csharp_namespace = "Google.ProtocolBuffers"; 43 | option objc_class_prefix = "GPB"; 44 | 45 | // A Duration represents a signed, fixed-length span of time represented 46 | // as a count of seconds and fractions of seconds at nanosecond 47 | // resolution. It is independent of any calendar and concepts like "day" 48 | // or "month". It is related to Timestamp in that the difference between 49 | // two Timestamp values is a Duration and it can be added or subtracted 50 | // from a Timestamp. Range is approximately +-10,000 years. 51 | // 52 | // Example 1: Compute Duration from two Timestamps in pseudo code. 53 | // 54 | // Timestamp start = ...; 55 | // Timestamp end = ...; 56 | // Duration duration = ...; 57 | // 58 | // duration.seconds = end.seconds - start.seconds; 59 | // duration.nanos = end.nanos - start.nanos; 60 | // 61 | // if (duration.seconds < 0 && duration.nanos > 0) { 62 | // duration.seconds += 1; 63 | // duration.nanos -= 1000000000; 64 | // } else if (durations.seconds > 0 && duration.nanos < 0) { 65 | // duration.seconds -= 1; 66 | // duration.nanos += 1000000000; 67 | // } 68 | // 69 | // Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. 70 | // 71 | // Timestamp start = ...; 72 | // Duration duration = ...; 73 | // Timestamp end = ...; 74 | // 75 | // end.seconds = start.seconds + duration.seconds; 76 | // end.nanos = start.nanos + duration.nanos; 77 | // 78 | // if (end.nanos < 0) { 79 | // end.seconds -= 1; 80 | // end.nanos += 1000000000; 81 | // } else if (end.nanos >= 1000000000) { 82 | // end.seconds += 1; 83 | // end.nanos -= 1000000000; 84 | // } 85 | // 86 | message Duration { 87 | // Signed seconds of the span of time. Must be from -315,576,000,000 88 | // to +315,576,000,000 inclusive. 89 | int64 seconds = 1; 90 | 91 | // Signed fractions of a second at nanosecond resolution of the span 92 | // of time. Durations less than one second are represented with a 0 93 | // `seconds` field and a positive or negative `nanos` field. For durations 94 | // of one second or more, a non-zero value for the `nanos` field must be 95 | // of the same sign as the `seconds` field. Must be from -999,999,999 96 | // to +999,999,999 inclusive. 97 | int32 nanos = 2; 98 | } 99 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/empty.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | syntax = "proto3"; 31 | 32 | import 'google/protobuf/swift-descriptor.proto'; 33 | option (.google.protobuf.swift_file_options).compile_for_framework = false; 34 | option (.google.protobuf.swift_file_options).entities_access_control = PublicEntities; 35 | 36 | package google.protobuf; 37 | 38 | option java_multiple_files = true; 39 | option java_outer_classname = "EmptyProto"; 40 | option java_package = "com.google.protobuf"; 41 | option objc_class_prefix = "GPB"; 42 | 43 | 44 | // A generic empty message that you can re-use to avoid defining duplicated 45 | // empty messages in your APIs. A typical example is to use it as the request 46 | // or the response type of an API method. For instance: 47 | // 48 | // service Foo { 49 | // rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); 50 | // } 51 | // 52 | message Empty { 53 | 54 | } 55 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/map_proto2_unittest.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | 34 | // We don't put this in a package within proto2 because we need to make sure 35 | // that the generated code doesn't depend on being in the proto2 namespace. 36 | // In map_test_util.h we do "using namespace unittest = protobuf_unittest". 37 | package protobuf_unittest; 38 | 39 | option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 40 | 41 | enum Proto2MapEnum { 42 | PROTO2_MAP_ENUM_FOO = 0; 43 | PROTO2_MAP_ENUM_BAR = 1; 44 | PROTO2_MAP_ENUM_BAZ = 2; 45 | } 46 | 47 | enum Proto2MapEnumPlusExtra { 48 | E_PROTO2_MAP_ENUM_FOO = 0; 49 | E_PROTO2_MAP_ENUM_BAR = 1; 50 | E_PROTO2_MAP_ENUM_BAZ = 2; 51 | E_PROTO2_MAP_ENUM_EXTRA = 3; 52 | } 53 | 54 | enum Proto2MapEnumStartWithNonZero { 55 | PROTO2_NON_ZERO_MAP_ENUM_FOO = 1; 56 | } 57 | 58 | message TestEnumMap { 59 | map known_map_field = 101; 60 | map unknown_map_field = 102; 61 | } 62 | 63 | message TestEnumMapPlusExtra { 64 | map known_map_field = 101; 65 | map unknown_map_field = 102; 66 | } 67 | 68 | message TestEnumStartWithNonZeroMap { 69 | map map_field = 101; 70 | } 71 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/map_unittest.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | option cc_enable_arenas = true; 34 | option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 35 | 36 | import "google/protobuf/unittest.proto"; 37 | 38 | // We don't put this in a package within proto2 because we need to make sure 39 | // that the generated code doesn't depend on being in the proto2 namespace. 40 | // In map_test_util.h we do "using namespace unittest = protobuf_unittest". 41 | package protobuf_unittest; 42 | 43 | // Tests maps. 44 | message TestMap { 45 | map map_int32_int32 = 1; 46 | map map_int64_int64 = 2; 47 | map map_uint32_uint32 = 3; 48 | map map_uint64_uint64 = 4; 49 | map map_sint32_sint32 = 5; 50 | map map_sint64_sint64 = 6; 51 | map map_fixed32_fixed32 = 7; 52 | map map_fixed64_fixed64 = 8; 53 | map map_sfixed32_sfixed32 = 9; 54 | map map_sfixed64_sfixed64 = 10; 55 | map map_int32_float = 11; 56 | map map_int32_double = 12; 57 | map map_bool_bool = 13; 58 | map map_string_string = 14; 59 | map map_int32_bytes = 15; 60 | map map_int32_enum = 16; 61 | map map_int32_foreign_message = 17; 62 | } 63 | 64 | message TestMapSubmessage { 65 | TestMap test_map = 1; 66 | } 67 | 68 | message TestMessageMap { 69 | map map_int32_message = 1; 70 | } 71 | 72 | // Two map fields share the same entry default instance. 73 | message TestSameTypeMap { 74 | map map1 = 1; 75 | map map2 = 2; 76 | } 77 | 78 | 79 | enum MapEnum { 80 | MAP_ENUM_FOO = 0; 81 | MAP_ENUM_BAR = 1; 82 | MAP_ENUM_BAZ = 2; 83 | } 84 | 85 | // Test embeded message with required fields 86 | message TestRequiredMessageMap { 87 | map map_field = 1; 88 | } 89 | 90 | message TestArenaMap { 91 | map map_int32_int32 = 1; 92 | map map_int64_int64 = 2; 93 | map map_uint32_uint32 = 3; 94 | map map_uint64_uint64 = 4; 95 | map map_sint32_sint32 = 5; 96 | map map_sint64_sint64 = 6; 97 | map map_fixed32_fixed32 = 7; 98 | map map_fixed64_fixed64 = 8; 99 | map map_sfixed32_sfixed32 = 9; 100 | map map_sfixed64_sfixed64 = 10; 101 | map map_int32_float = 11; 102 | map map_int32_double = 12; 103 | map map_bool_bool = 13; 104 | map map_int32_enum = 14; 105 | map map_int32_foreign_message = 15; 106 | } 107 | 108 | // Previously, message containing enum called Type cannot be used as value of 109 | // map field. 110 | message MessageContainingEnumCalledType { 111 | enum Type { 112 | TYPE_FOO = 0; 113 | } 114 | map type = 1; 115 | } 116 | 117 | // Previously, message cannot contain map field called "entry". 118 | message MessageContainingMapCalledEntry { 119 | map entry = 1; 120 | } 121 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/performance.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import "google/protobuf/swift-descriptor.proto"; 4 | 5 | option (.google.protobuf.swift_file_options).entities_access_control = InternalEntities; 6 | option (.google.protobuf.swift_file_options).class_prefix = "PB"; 7 | 8 | message User { 9 | optional Group group = 1; 10 | optional string groupName = 2; 11 | } 12 | 13 | message Group { 14 | optional User owner = 1; 15 | 16 | } 17 | 18 | message PerfomanceBatch { 19 | repeated Perfomance batch = 1; 20 | } 21 | 22 | message Perfomance { 23 | required int32 ints = 1; 24 | required int64 ints64 = 2; 25 | required double doubles = 3; 26 | required float floats = 4; 27 | optional string str = 5; 28 | optional bytes bytes = 6; 29 | optional string description = 7; 30 | } 31 | 32 | message ProtoPoint { 33 | required float latitude = 1; 34 | required float longitude = 2; 35 | } 36 | 37 | 38 | //ISSUE #57 39 | // enum Flavor { 40 | // CHOCOLATE = 1; 41 | // VANILLA = 2; 42 | // } 43 | 44 | message IceCreamCone { 45 | enum Flavor { 46 | CHOCOLATE = 1; 47 | VANILLA = 2; 48 | } 49 | optional int32 scoops = 1; 50 | optional Flavor flavor = 2; 51 | 52 | } 53 | 54 | //Subuilders 55 | message Foo { 56 | optional int32 val = 1; 57 | // some other fields. 58 | } 59 | 60 | message Bar { 61 | optional Foo foo = 1; 62 | // some other fields. 63 | } 64 | 65 | message Baz { 66 | optional Bar bar = 1; 67 | // some other fields. 68 | } 69 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/source_context.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | syntax = "proto3"; 31 | 32 | import 'google/protobuf/swift-descriptor.proto'; 33 | option (.google.protobuf.swift_file_options).compile_for_framework = false; 34 | option (.google.protobuf.swift_file_options).entities_access_control = PublicEntities; 35 | 36 | package google.protobuf; 37 | 38 | option java_multiple_files = true; 39 | option java_outer_classname = "SourceContextProto"; 40 | option java_package = "com.google.protobuf"; 41 | option objc_class_prefix = "GPB"; 42 | 43 | 44 | // `SourceContext` represents information about the source of a 45 | // protobuf element, like the file in which it is defined. 46 | message SourceContext { 47 | // The path-qualified name of the .proto file that contained the associated 48 | // protobuf element. For example: `"google/protobuf/source.proto"`. 49 | string file_name = 1; 50 | } 51 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/struct.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | syntax = "proto3"; 31 | 32 | import 'google/protobuf/swift-descriptor.proto'; 33 | option (.google.protobuf.swift_file_options).compile_for_framework = false; 34 | option (.google.protobuf.swift_file_options).entities_access_control = PublicEntities; 35 | 36 | package google.protobuf; 37 | 38 | option java_generate_equals_and_hash = true; 39 | option java_multiple_files = true; 40 | option java_outer_classname = "StructProto"; 41 | option java_package = "com.google.protobuf"; 42 | option csharp_namespace = "Google.ProtocolBuffers"; 43 | option objc_class_prefix = "GPB"; 44 | 45 | 46 | // `Struct` represents a structured data value, consisting of fields 47 | // which map to dynamically typed values. In some languages, `Struct` 48 | // might be supported by a native representation. For example, in 49 | // scripting languages like JS a struct is represented as an 50 | // object. The details of that representation are described together 51 | // with the proto support for the language. 52 | message Struct { 53 | // Map of dynamically typed values. 54 | map fields = 1; 55 | } 56 | 57 | // `Value` represents a dynamically typed value which can be either 58 | // null, a number, a string, a boolean, a recursive struct value, or a 59 | // list of values. A producer of value is expected to set one of that 60 | // variants, absence of any variant indicates an error. 61 | message Value { 62 | oneof kind { 63 | // Represents a null value. 64 | NullValue null_value = 1; 65 | 66 | // Represents a double value. 67 | double number_value = 2; 68 | 69 | // Represents a string value. 70 | string string_value = 3; 71 | 72 | // Represents a boolean value. 73 | bool bool_value = 4; 74 | 75 | // Represents a structured value. 76 | Struct struct_value = 5; 77 | 78 | // Represents a repeated `Value`. 79 | ListValue list_value = 6; 80 | } 81 | } 82 | 83 | // `ListValue` is a wrapper around a repeated field of values. 84 | message ListValue { 85 | // Repeated field of dynamically typed values. 86 | repeated Value values = 1; 87 | } 88 | 89 | // `NullValue` is a singleton enumeration to represent the null 90 | // value for the `Value` type union. 91 | enum NullValue { 92 | // Null value. 93 | NULL_VALUE = 0; 94 | } 95 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/swift-descriptor.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 AlexeyXo. 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | syntax = "proto2"; 18 | import "google/protobuf/descriptor.proto"; 19 | 20 | package google.protobuf; 21 | 22 | enum AccessControl { 23 | InternalEntities = 0; 24 | PublicEntities = 1; 25 | } 26 | 27 | message LinkedObject { 28 | required string fieldName = 1; 29 | required string fromType = 2; 30 | required string propertyName = 3; 31 | } 32 | 33 | message SwiftFileOptions { 34 | optional string class_prefix = 1; 35 | optional AccessControl entities_access_control = 2 [default = PublicEntities]; 36 | optional bool compile_for_framework = 3 [default = true]; 37 | optional bool generate_struct = 4 [default = false]; 38 | optional bool generate_realm_objects = 5 [default = false]; 39 | optional bool generate_react = 6 [default = false]; 40 | } 41 | 42 | message SwiftMessageOptions { 43 | optional bool generate_error_type = 1 [default = false]; 44 | optional bool generate_realm_object = 2 [default = false]; 45 | optional bool generate_react = 3 [default = false]; 46 | optional string additional_class_name = 4; 47 | repeated LinkedObject linkedObjects = 5; 48 | } 49 | 50 | enum RealmOverrideRepeated { 51 | OVERRIDE = 0; 52 | APPEND = 1; 53 | } 54 | message SwiftFieldOptions { 55 | optional bool realm_indexed_propertie = 1 [default = false]; 56 | optional bool realm_primary_key = 2 [default = false]; 57 | optional RealmOverrideRepeated realm_override_propertie = 3 [default = OVERRIDE]; 58 | } 59 | 60 | message SwiftEnumOptions { 61 | optional bool generate_error_type = 1 [default = false]; 62 | optional bool generate_react = 2 [default = false]; 63 | optional bool generate_realm_object = 3 [default = false]; 64 | } 65 | 66 | extend google.protobuf.FileOptions { 67 | optional SwiftFileOptions swift_file_options = 5100987; 68 | } 69 | 70 | extend google.protobuf.FieldOptions { 71 | optional SwiftFieldOptions swift_field_options = 5100986; 72 | } 73 | 74 | extend google.protobuf.MessageOptions { 75 | optional SwiftMessageOptions swift_message_options = 5100985; 76 | } 77 | 78 | extend google.protobuf.EnumOptions { 79 | optional SwiftEnumOptions swift_enum_options = 5100984; 80 | } 81 | 82 | option (.google.protobuf.swift_file_options).compile_for_framework = false; 83 | option (.google.protobuf.swift_file_options).entities_access_control = PublicEntities; 84 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/timestamp.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | syntax = "proto3"; 31 | 32 | import 'google/protobuf/swift-descriptor.proto'; 33 | option (.google.protobuf.swift_file_options).compile_for_framework = false; 34 | option (.google.protobuf.swift_file_options).entities_access_control = PublicEntities; 35 | 36 | package google.protobuf; 37 | 38 | option java_generate_equals_and_hash = true; 39 | option java_multiple_files = true; 40 | option java_outer_classname = "TimestampProto"; 41 | option java_package = "com.google.protobuf"; 42 | option csharp_namespace = "Google.ProtocolBuffers"; 43 | option objc_class_prefix = "GPB"; 44 | 45 | 46 | // A Timestamp represents a point in time independent of any time zone 47 | // or calendar, represented as seconds and fractions of seconds at 48 | // nanosecond resolution in UTC Epoch time. It is encoded using the 49 | // Proleptic Gregorian Calendar which extends the Gregorian calendar 50 | // backwards to year one. It is encoded assuming all minutes are 60 51 | // seconds long, i.e. leap seconds are "smeared" so that no leap second 52 | // table is needed for interpretation. Range is from 53 | // 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. 54 | // By restricting to that range, we ensure that we can convert to 55 | // and from RFC 3339 date strings. 56 | // See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). 57 | // 58 | // Example 1: Compute Timestamp from POSIX `time()`. 59 | // 60 | // Timestamp timestamp; 61 | // timestamp.set_seconds(time(NULL)); 62 | // timestamp.set_nanos(0); 63 | // 64 | // Example 2: Compute Timestamp from POSIX `gettimeofday()`. 65 | // 66 | // struct timeval tv; 67 | // gettimeofday(&tv, NULL); 68 | // 69 | // Timestamp timestamp; 70 | // timestamp.set_seconds(tv.tv_sec); 71 | // timestamp.set_nanos(tv.tv_usec * 1000); 72 | // 73 | // Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. 74 | // 75 | // FILETIME ft; 76 | // GetSystemTimeAsFileTime(&ft); 77 | // UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; 78 | // 79 | // // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z 80 | // // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. 81 | // Timestamp timestamp; 82 | // timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); 83 | // timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); 84 | // 85 | // Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. 86 | // 87 | // long millis = System.currentTimeMillis(); 88 | // 89 | // Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) 90 | // .setNanos((int) ((millis % 1000) * 1000000)).build(); 91 | // 92 | // Example 5: Compute Timestamp from Python `datetime.datetime`. 93 | // 94 | // now = datetime.datetime.utcnow() 95 | // seconds = int(time.mktime(now.timetuple())) 96 | // nanos = now.microsecond * 1000 97 | // timestamp = Timestamp(seconds=seconds, nanos=nanos) 98 | // 99 | message Timestamp { 100 | // Represents seconds of UTC time since Unix epoch 101 | // 1970-01-01T00:00:00Z. Must be from from 0001-01-01T00:00:00Z to 102 | // 9999-12-31T23:59:59Z inclusive. 103 | int64 seconds = 1; 104 | 105 | // Non-negative fractions of a second at nanosecond resolution. Negative 106 | // second values with fractions must still have non-negative nanos values 107 | // that count forward in time. Must be from 0 to 999,999,999 108 | // inclusive. 109 | int32 nanos = 2; 110 | } 111 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_arena.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | import "google/protobuf/unittest_no_arena_import.proto"; 34 | 35 | package proto2_arena_unittest; 36 | 37 | option cc_enable_arenas = true; 38 | 39 | message NestedMessage { 40 | optional int32 d = 1; 41 | } 42 | 43 | message ArenaMessage { 44 | repeated NestedMessage repeated_nested_message = 1; 45 | repeated ImportNoArenaNestedMessage repeated_import_no_arena_message = 2; 46 | }; 47 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_drop_unknown_fields.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package unittest_drop_unknown_fields; 34 | option objc_class_prefix = "DropUnknowns"; 35 | 36 | option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 37 | 38 | message Foo { 39 | enum NestedEnum { 40 | FOO = 0; 41 | BAR = 1; 42 | BAZ = 2; 43 | } 44 | int32 int32_value = 1; 45 | NestedEnum enum_value = 2; 46 | } 47 | 48 | message FooWithExtraFields { 49 | enum NestedEnum { 50 | FOO = 0; 51 | BAR = 1; 52 | BAZ = 2; 53 | QUX = 3; 54 | } 55 | int32 int32_value = 1; 56 | NestedEnum enum_value = 2; 57 | int32 extra_int32_value = 3; 58 | } 59 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_embed_optimize_for.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // A proto file which imports a proto file that uses optimize_for = CODE_SIZE. 36 | 37 | syntax = "proto2"; 38 | import "google/protobuf/unittest_optimize_for.proto"; 39 | 40 | package protobuf_unittest; 41 | 42 | option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 43 | 44 | // We optimize for speed here, but we are importing a proto that is optimized 45 | // for code size. 46 | option optimize_for = SPEED; 47 | 48 | message TestEmbedOptimizedForSize { 49 | // Test that embedding a message which has optimize_for = CODE_SIZE into 50 | // one optimized for speed works. 51 | optional TestOptimizedForSize optional_message = 1; 52 | repeated TestOptimizedForSize repeated_message = 2; 53 | } 54 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_empty.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // This file intentionally left blank. (At one point this wouldn't compile 36 | // correctly.) 37 | 38 | syntax = "proto2"; 39 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_error_type.proto: -------------------------------------------------------------------------------- 1 | import 'google/protobuf/swift-descriptor.proto'; 2 | 3 | enum ServiceError { 4 | option (.google.protobuf.swift_enum_options).generate_error_type = true; 5 | BadRequest = 0; 6 | InternalServerError = 1; 7 | } 8 | 9 | message UserProfile { 10 | message Request { 11 | required string userId = 1; 12 | } 13 | message Response { 14 | optional UserProfile profile = 1; 15 | optional ServiceError error = 2; 16 | optional Exception exception = 3; 17 | } 18 | 19 | message Exception { 20 | option (.google.protobuf.swift_message_options).generate_error_type = true; 21 | required int32 errorCode = 1; 22 | required string errorDescription = 2; 23 | } 24 | 25 | optional string firstName = 1; 26 | optional string lastName = 2; 27 | optional string avatarUrl = 3; 28 | } -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_import.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // A proto file which is imported by unittest.proto to test importing. 36 | 37 | syntax = "proto2"; 38 | 39 | // We don't put this in a package within proto2 because we need to make sure 40 | // that the generated code doesn't depend on being in the proto2 namespace. 41 | // In test_util.h we do 42 | // "using namespace unittest_import = protobuf_unittest_import". 43 | package protobuf_unittest_import; 44 | 45 | option optimize_for = SPEED; 46 | option cc_enable_arenas = true; 47 | 48 | // Exercise the java_package option. 49 | option java_package = "com.google.protobuf.test"; 50 | option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 51 | 52 | // Do not set a java_outer_classname here to verify that Proto2 works without 53 | // one. 54 | 55 | // Test public import 56 | import public "google/protobuf/unittest_import_public.proto"; 57 | 58 | message ImportMessage { 59 | optional int32 d = 1; 60 | } 61 | 62 | enum ImportEnum { 63 | IMPORT_FOO = 7; 64 | IMPORT_BAR = 8; 65 | IMPORT_BAZ = 9; 66 | } 67 | 68 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_import_lite.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // 33 | // This is like unittest_import.proto but with optimize_for = LITE_RUNTIME. 34 | 35 | syntax = "proto2"; 36 | package protobuf_unittest_import; 37 | 38 | option optimize_for = LITE_RUNTIME; 39 | 40 | option java_package = "com.google.protobuf"; 41 | option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 42 | 43 | import public "google/protobuf/unittest_import_public_lite.proto"; 44 | 45 | message ImportMessageLite { 46 | optional int32 d = 1; 47 | } 48 | 49 | enum ImportEnumLite { 50 | IMPORT_LITE_FOO = 7; 51 | IMPORT_LITE_BAR = 8; 52 | IMPORT_LITE_BAZ = 9; 53 | } 54 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_import_public.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: liujisi@google.com (Pherl Liu) 32 | 33 | syntax = "proto2"; 34 | 35 | package protobuf_unittest_import; 36 | 37 | option java_package = "com.google.protobuf.test"; 38 | option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 39 | 40 | message PublicImportMessage { 41 | optional int32 e = 1; 42 | } 43 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_import_public_lite.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: liujisi@google.com (Pherl Liu) 32 | 33 | syntax = "proto2"; 34 | 35 | package protobuf_unittest_import; 36 | 37 | option optimize_for = LITE_RUNTIME; 38 | 39 | option java_package = "com.google.protobuf"; 40 | option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 41 | 42 | message PublicImportMessageLite { 43 | optional int32 e = 1; 44 | } 45 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_lite_imports_nonlite.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // 33 | // Tests that a "lite" message can import a regular message. 34 | 35 | syntax = "proto2"; 36 | package protobuf_unittest; 37 | 38 | import "google/protobuf/unittest.proto"; 39 | 40 | option optimize_for = LITE_RUNTIME; 41 | option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 42 | 43 | message TestLiteImportsNonlite { 44 | optional TestAllTypes message = 1; 45 | } 46 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_maps.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package SwiftProtobufUnittest; 4 | 5 | message MapMessageValue 6 | { 7 | optional int32 valueInMapMessage = 1; 8 | } 9 | 10 | message MessageContainsMap 11 | { 12 | 13 | enum EnumMapValue 14 | { 15 | FirstValueEnum = 0; 16 | SecondValueEnum = 1; 17 | } 18 | 19 | map map_int32_int32= 1; 20 | map map_int64_int64= 2; 21 | map map_string_string = 3; 22 | map map_string_bytes = 4; 23 | map map_string_message = 5; 24 | map map_int32_enum = 6; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_mset.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // This file contains messages for testing message_set_wire_format. 36 | 37 | syntax = "proto2"; 38 | package protobuf_unittest; 39 | 40 | option cc_enable_arenas = true; 41 | option optimize_for = SPEED; 42 | option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 43 | 44 | // A message with message_set_wire_format. 45 | message TestMessageSet { 46 | option message_set_wire_format = true; 47 | extensions 4 to max; 48 | } 49 | 50 | message TestMessageSetContainer { 51 | optional TestMessageSet message_set = 1; 52 | } 53 | 54 | message TestMessageSetExtension1 { 55 | extend TestMessageSet { 56 | optional TestMessageSetExtension1 message_set_extension = 1545008; 57 | } 58 | optional int32 i = 15; 59 | } 60 | 61 | message TestMessageSetExtension2 { 62 | extend TestMessageSet { 63 | optional TestMessageSetExtension2 message_set_extension = 1547769; 64 | } 65 | optional string str = 25; 66 | } 67 | 68 | // This message was used to generate 69 | // //net/proto2/python/internal/testdata/message_set_message, but is commented 70 | // out since it must not actually exist in code, to simulate an "unknown" 71 | // extension. 72 | // message TestMessageSetUnknownExtension { 73 | // extend TestMessageSet { 74 | // optional TestMessageSetUnknownExtension message_set_extension = 56141421; 75 | // } 76 | // optional int64 a = 1; 77 | // } 78 | 79 | // MessageSet wire format is equivalent to this. 80 | message RawMessageSet { 81 | repeated group Item = 1 { 82 | required int32 type_id = 2; 83 | required bytes message = 3; 84 | } 85 | } 86 | 87 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_no_arena_import.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package proto2_arena_unittest; 34 | 35 | message ImportNoArenaNestedMessage { 36 | optional int32 d = 1; 37 | }; 38 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_no_generic_services.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | 33 | syntax = "proto2"; 34 | package google.protobuf.no_generic_services_test; 35 | 36 | 37 | // *_generic_services are false by default. 38 | 39 | message TestMessage { 40 | optional int32 a = 1; 41 | extensions 1000 to max; 42 | } 43 | 44 | enum TestEnum { 45 | FOO = 1; 46 | } 47 | 48 | extend TestMessage { 49 | optional int32 test_extension = 1000; 50 | } 51 | 52 | service TestService { 53 | rpc Foo(TestMessage) returns(TestMessage); 54 | } 55 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_optimize_for.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // A proto file which uses optimize_for = CODE_SIZE. 36 | 37 | syntax = "proto2"; 38 | import "google/protobuf/unittest.proto"; 39 | 40 | package protobuf_unittest; 41 | 42 | option optimize_for = CODE_SIZE; 43 | option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 44 | 45 | message TestOptimizedForSize { 46 | optional int32 i = 1; 47 | optional ForeignMessage msg = 19; 48 | 49 | extensions 1000 to max; 50 | 51 | extend TestOptimizedForSize { 52 | optional int32 test_extension = 1234; 53 | optional TestRequiredOptimizedForSize test_extension2 = 1235; 54 | } 55 | 56 | oneof foo { 57 | int32 integer_field = 2; 58 | string string_field = 3; 59 | } 60 | } 61 | 62 | message TestRequiredOptimizedForSize { 63 | required int32 x = 1; 64 | } 65 | 66 | message TestOptionalOptimizedForSize { 67 | optional TestRequiredOptimizedForSize o = 1; 68 | } 69 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_preserve_unknown_enum.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package proto3_preserve_unknown_enum_unittest; 34 | option objc_class_prefix = "UnknownEnums"; 35 | 36 | option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 37 | 38 | enum MyEnum { 39 | FOO = 0; 40 | BAR = 1; 41 | BAZ = 2; 42 | } 43 | 44 | enum MyEnumPlusExtra { 45 | E_FOO = 0; 46 | E_BAR = 1; 47 | E_BAZ = 2; 48 | E_EXTRA = 3; 49 | } 50 | 51 | message MyMessage { 52 | MyEnum e = 1; 53 | repeated MyEnum repeated_e = 2; 54 | repeated MyEnum repeated_packed_e = 3 [packed=true]; 55 | repeated MyEnumPlusExtra repeated_packed_unexpected_e = 4; // not packed 56 | oneof o { 57 | MyEnum oneof_e_1 = 5; 58 | MyEnum oneof_e_2 = 6; 59 | } 60 | } 61 | 62 | message MyMessagePlusExtra { 63 | MyEnumPlusExtra e = 1; 64 | repeated MyEnumPlusExtra repeated_e = 2; 65 | repeated MyEnumPlusExtra repeated_packed_e = 3 [packed=true]; 66 | repeated MyEnumPlusExtra repeated_packed_unexpected_e = 4 [packed=true]; 67 | oneof o { 68 | MyEnumPlusExtra oneof_e_1 = 5; 69 | MyEnumPlusExtra oneof_e_2 = 6; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_struct.proto: -------------------------------------------------------------------------------- 1 | import 'google/protobuf/swift-descriptor.proto'; 2 | 3 | option (.google.protobuf.swift_file_options).generate_struct = true; 4 | 5 | message UnitTestStruct { 6 | optional string testStr = 1; 7 | optional int32 testInt = 2; 8 | } -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_threading.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | message ThreadingMessages 3 | { 4 | string testString = 1; 5 | } 6 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unittest_well_known_types.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package protobuf_unittest; 4 | 5 | option java_multiple_files = true; 6 | option java_package = "com.google.protobuf.test"; 7 | 8 | import "google/protobuf/any.proto"; 9 | import "google/protobuf/api.proto"; 10 | import "google/protobuf/duration.proto"; 11 | import "google/protobuf/empty.proto"; 12 | import "google/protobuf/field_mask.proto"; 13 | import "google/protobuf/source_context.proto"; 14 | import "google/protobuf/struct.proto"; 15 | import "google/protobuf/timestamp.proto"; 16 | import "google/protobuf/type.proto"; 17 | import "google/protobuf/wrappers.proto"; 18 | 19 | // Test that we can include all well-known types. 20 | message TestWellKnownTypes { 21 | google.protobuf.Any any_field = 1; 22 | google.protobuf.Api api_field = 2; 23 | google.protobuf.Duration duration_field = 3; 24 | google.protobuf.Empty empty_field = 4; 25 | google.protobuf.FieldMask field_mask_field = 5; 26 | google.protobuf.SourceContext source_context_field = 6; 27 | google.protobuf.Struct struct_field = 7; 28 | google.protobuf.Timestamp timestamp_field = 8; 29 | google.protobuf.Type type_field = 9; 30 | google.protobuf.Int32Value int32_field = 10; 31 | } 32 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/unknown_enum_test.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Definitions of protos for testing cross-version compatibility. The 32 | // UpRevision message acts as if it were a newer version of the DownRevision 33 | // message. That is, UpRevision shares all the same fields as DownRevision, 34 | // but UpRevision can add fields and add enum values. 35 | syntax = "proto2"; 36 | 37 | package google.protobuf.util; 38 | 39 | option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 40 | 41 | message DownRevision { 42 | enum Enum { 43 | DEFAULT_VALUE = 2; 44 | NONDEFAULT_VALUE = 3; 45 | } 46 | 47 | optional Enum value = 1 [default = DEFAULT_VALUE]; 48 | repeated Enum values = 2; 49 | } 50 | 51 | message UpRevision { 52 | enum Enum { 53 | DEFAULT_VALUE = 2; 54 | NONDEFAULT_VALUE = 3; 55 | NEW_VALUE = 4; 56 | NEW_VALUE_2 = 5; 57 | NEW_VALUE_3 = 6; 58 | } 59 | 60 | optional Enum value = 1 [default = DEFAULT_VALUE]; 61 | repeated Enum values = 2; 62 | } 63 | -------------------------------------------------------------------------------- /plugin/compiler/google/protobuf/wrappers.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Wrappers for primitive (non-message) types. These types are useful 32 | // for embedding primitives in the `google.protobuf.Any` type and for places 33 | // where we need to distinguish between the absence of a primitive 34 | // typed field and its default value. 35 | 36 | syntax = "proto3"; 37 | 38 | import 'google/protobuf/swift-descriptor.proto'; 39 | option (.google.protobuf.swift_file_options).compile_for_framework = false; 40 | option (.google.protobuf.swift_file_options).entities_access_control = PublicEntities; 41 | 42 | package google.protobuf; 43 | 44 | option java_multiple_files = true; 45 | option java_outer_classname = "WrappersProto"; 46 | option java_package = "com.google.protobuf"; 47 | option csharp_namespace = "Google.ProtocolBuffers"; 48 | option objc_class_prefix = "GPB"; 49 | 50 | 51 | // Wrapper message for double. 52 | message DoubleValue { 53 | // The double value. 54 | double value = 1; 55 | } 56 | 57 | // Wrapper message for float. 58 | message FloatValue { 59 | // The float value. 60 | float value = 1; 61 | } 62 | 63 | // Wrapper message for int64. 64 | message Int64Value { 65 | // The int64 value. 66 | int64 value = 1; 67 | } 68 | 69 | // Wrapper message for uint64. 70 | message UInt64Value { 71 | // The uint64 value. 72 | uint64 value = 1; 73 | } 74 | 75 | // Wrapper message for int32. 76 | message Int32Value { 77 | // The int32 value. 78 | int32 value = 1; 79 | } 80 | 81 | // Wrapper message for uint32. 82 | message UInt32Value { 83 | // The uint32 value. 84 | uint32 value = 1; 85 | } 86 | 87 | // Wrapper message for bool. 88 | message BoolValue { 89 | // The bool value. 90 | bool value = 1; 91 | } 92 | 93 | // Wrapper message for string. 94 | message StringValue { 95 | // The string value. 96 | string value = 1; 97 | } 98 | 99 | // Wrapper message for bytes. 100 | message BytesValue { 101 | // The bytes value. 102 | bytes value = 1; 103 | } 104 | -------------------------------------------------------------------------------- /plugin/compiler/main.cc: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #include 19 | #include "swift_generator.h" 20 | #include 21 | #include 22 | 23 | using namespace google::protobuf::compiler::swift; 24 | 25 | int main(int argc, char **argv) 26 | { 27 | 28 | SwiftGenerator generator; 29 | return PluginMain(argc, argv, &generator); 30 | } 31 | -------------------------------------------------------------------------------- /plugin/compiler/react_native/.dirstamp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexeyxo/protobuf-swift/f396f02cff0781db3857056b96adc424fb336b96/plugin/compiler/react_native/.dirstamp -------------------------------------------------------------------------------- /plugin/compiler/react_native/main.cc: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #include 19 | #include "swift_generator.h" 20 | #include 21 | #include 22 | 23 | using namespace google::protobuf::compiler::swift; 24 | 25 | int main(int argc, char **argv) 26 | { 27 | 28 | SwiftGenerator generator; 29 | return PluginMain(argc, argv, &generator); 30 | } 31 | -------------------------------------------------------------------------------- /plugin/compiler/react_native/swift_file.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #ifndef swift_FILE_H__ 19 | #define swift_FILE_H__ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace google { 27 | namespace protobuf { 28 | class FileDescriptor; // descriptor.h 29 | namespace io { 30 | class Printer; // printer.h 31 | } 32 | } 33 | 34 | namespace protobuf { 35 | namespace compiler { 36 | namespace swift { 37 | 38 | class FileGenerator { 39 | public: 40 | explicit FileGenerator(const FileDescriptor* file); 41 | ~FileGenerator(); 42 | 43 | void GenerateSource(io::Printer* printer); 44 | 45 | const string& classname() { return classname_; } 46 | 47 | private: 48 | void GenerateImports(io::Printer* printer); 49 | const FileDescriptor* file_; 50 | string classname_; 51 | 52 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator); 53 | }; 54 | } // namespace swift 55 | } // namespace compiler 56 | } // namespace protobuf 57 | } // namespace google 58 | 59 | #endif // swift_FILE_H__ 60 | -------------------------------------------------------------------------------- /plugin/compiler/react_native/swift_generator.cc: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #include "swift_generator.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "swift_file.h" 27 | #include "swift_helpers.h" 28 | #include "swift_helpers_react.h" 29 | 30 | namespace google { namespace protobuf { namespace compiler { namespace swift { 31 | SwiftGenerator::SwiftGenerator() { 32 | } 33 | 34 | 35 | SwiftGenerator::~SwiftGenerator() { 36 | } 37 | 38 | bool SwiftGenerator::Generate(const FileDescriptor* file, 39 | const string& parameter, 40 | GeneratorContext* generator_context, 41 | string* error) const { 42 | 43 | 44 | 45 | static std::map packages; 46 | 47 | std::vector > options; 48 | ParseGeneratorParameter(parameter, &options); 49 | 50 | for (int i = 0; i < options.size(); i++) { 51 | *error = "Unknown generator option: " + options[i].first; 52 | return false; 53 | } 54 | 55 | 56 | FileGenerator file_generator(file); 57 | 58 | string filepath = FilePath(file); 59 | { 60 | 61 | string package_name; 62 | 63 | if (file->package() != "") { 64 | package_name = FullName(file); 65 | } 66 | 67 | if (!NeedGenerateReactFileClass(file)) { 68 | return true; 69 | } 70 | 71 | std::vector tokens = FullNameSplit(file); 72 | 73 | std::unique_ptr output(generator_context->Open(package_name + UnderscoresToCapitalizedCamelCase(UnderscoresToCapitalizedCamelCase(filepath)) + ".proto.js")); 74 | io::Printer printer(output.get(), '$'); 75 | 76 | printer.Print("/* @flow */\n"); 77 | printer.Print("// Generated by the Protocol Buffers $version$ compiler. DO NOT EDIT!\n", 78 | "version",internal::VersionString(GOOGLE_PROTOBUF_VERSION)); 79 | printer.Print("// Protobuf-swift version: $version$\n", "version", SWIFT_PROTOBUF_VERSION); 80 | printer.Print("// Source file \"$filePath$\"\n", 81 | "filePath", FileNameDescription(file)); 82 | 83 | if (file->syntax() == FileDescriptor::SYNTAX_PROTO2) { 84 | printer.Print("// Syntax \"Proto2\"\n\n"); 85 | } else { 86 | printer.Print("// Syntax \"Proto3\"\n\n"); 87 | } 88 | 89 | 90 | 91 | file_generator.GenerateSource(&printer); 92 | } 93 | 94 | return true; 95 | } 96 | 97 | } // namespace swift 98 | } // namespace compiler 99 | } // namespace protobuf 100 | } // namespace google 101 | -------------------------------------------------------------------------------- /plugin/compiler/react_native/swift_generator.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #ifndef SWIFT_GENERATOR_H 19 | #define SWIFT_GENERATOR_H 20 | 21 | #include 22 | #include 23 | 24 | namespace google { 25 | namespace protobuf { 26 | namespace compiler { 27 | namespace swift { 28 | 29 | class SwiftGenerator : public CodeGenerator { 30 | public: 31 | SwiftGenerator(); 32 | ~SwiftGenerator(); 33 | 34 | bool Generate(const FileDescriptor* file, 35 | const string& parameter, 36 | OutputDirectory* output_directory, 37 | string* error) const; 38 | 39 | private: 40 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SwiftGenerator); 41 | }; 42 | } // namespace swift 43 | } // namespace compiler 44 | } // namespace protobuf 45 | } // namespace google 46 | 47 | #endif // swift_GENERATOR_H 48 | -------------------------------------------------------------------------------- /plugin/compiler/react_native/swift_helpers_react.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #ifndef swift_HELPERS_REACT_H 19 | #define swift_HELPERS_REACT_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #define SWIFT_PROTOBUF_VERSION "4.0.0" 27 | 28 | namespace google { 29 | namespace protobuf { 30 | namespace compiler { 31 | namespace swift { 32 | 33 | //React 34 | string ClassNameReact(const Descriptor* descriptor); 35 | string ClassNameReact(const FieldDescriptor* descriptor); 36 | string ClassNameReact(const EnumDescriptor* descriptor); 37 | string ClassNameReactWorker(const Descriptor* descriptor); 38 | string ClassNameWorkers(const Descriptor* descriptor); 39 | 40 | string ClassNameReactReturnType(const Descriptor* descriptor); 41 | string ClassNameReactReturnType(const FieldDescriptor* descriptor); 42 | string ClassNameReactReturnType(const EnumDescriptor* descriptor); 43 | 44 | bool NeedGenerateReactFileClass(const FileDescriptor* message); 45 | bool NeedGenerateReactType(const Descriptor* message); 46 | bool NeedGenerateReactType(const EnumDescriptor* message); 47 | // bool NeedGenerateRealmFileClass(const FileDescriptor* file); 48 | // bool NeedGenerateRealmClass(const Descriptor* message); 49 | // 50 | // string RealmPrimaryKey(const Descriptor* message); 51 | // string RealmIndexedProperties(const Descriptor* message); 52 | string PrimitiveTypeReact(const FieldDescriptor* field); 53 | // string PrimitiveTypeRealmOptional(const FieldDescriptor* field); 54 | // string PrimitiveTypeCastingRealm(const FieldDescriptor* field); 55 | // string PrimitiveTypeCastingRealmRepresent(const FieldDescriptor* field); 56 | // string PrimitiveTypeRealmOptionalVariable(const FieldDescriptor* field); 57 | string DefaultValueReact(const FieldDescriptor* field); 58 | // 59 | 60 | } // namespace swift 61 | } // namespace compiler 62 | } // namespace protobuf 63 | } // namespace google 64 | 65 | #endif // swift_HELPERS_REACT_H 66 | -------------------------------------------------------------------------------- /plugin/compiler/react_native/swift_react.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #ifndef swift_REACT_H 19 | #define swift_REACT_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace google { 28 | namespace protobuf { 29 | namespace io { 30 | class Printer; // printer.h 31 | } 32 | } 33 | 34 | namespace protobuf { 35 | namespace compiler { 36 | namespace swift { 37 | 38 | class ReactGenerator { 39 | public: 40 | explicit ReactGenerator(const Descriptor* descriptor); 41 | ~ReactGenerator(); 42 | 43 | void GenerateSource(io::Printer* printer); 44 | void GenerateSourceImport(io::Printer* printer); 45 | 46 | const Descriptor* descriptor_; 47 | 48 | std::map variables_; 49 | 50 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ReactGenerator); 51 | 52 | private: 53 | void GeneratePrimitiveTypes(io::Printer* printer); 54 | void GenerateStaticInnerTypes(io::Printer* printer, const Descriptor* field); 55 | void GenerateStaticInnerTypes(io::Printer* printer, const EnumDescriptor* field); 56 | void GenerateConstructor(io::Printer* printer); 57 | 58 | 59 | }; 60 | } // namespace swift 61 | } // namespace compiler 62 | } // namespace protobuf 63 | } // namespace google 64 | 65 | #endif // swift_REACT_H 66 | -------------------------------------------------------------------------------- /plugin/compiler/react_native/swift_react_enums.cc: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #include "swift_react_enums.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "swift_helpers_react.h" 29 | #include "swift_helpers.h" 30 | 31 | namespace google { namespace protobuf { namespace compiler { namespace swift { 32 | 33 | using internal::WireFormat; 34 | using internal::WireFormatLite; 35 | 36 | namespace { 37 | 38 | void SetMapVariables(const EnumDescriptor* descriptor, std::map* variables) { 39 | (*variables)["classNameReaсt"] = ClassNameReact(descriptor); 40 | } 41 | 42 | } // namespace 43 | 44 | 45 | ReactEnumGenerator::ReactEnumGenerator(const EnumDescriptor* descriptor) : descriptor_(descriptor) { 46 | SetMapVariables(descriptor, &variables_); 47 | } 48 | 49 | 50 | ReactEnumGenerator::~ReactEnumGenerator() { 51 | 52 | } 53 | 54 | void ReactEnumGenerator::GenerateSourceImport(io::Printer* printer) { 55 | if (NeedGenerateReactType(descriptor_)) { 56 | printer->Print(variables_,"$classNameReaсt$"); 57 | } 58 | } 59 | 60 | void ReactEnumGenerator::GenerateSource(io::Printer* printer) { 61 | 62 | printer->Print(variables_,"export const $classNameReaсt$ : Object = {\n"); 63 | XCodeStandartIndent(printer); 64 | for (int i = 0; i < descriptor_->value_count(); i++) { 65 | const EnumValueDescriptor* value = descriptor_->value(i); 66 | const EnumValueDescriptor* canonical_value = descriptor_->FindValueByNumber(value->number()); 67 | printer->Print("$canonicalName$: \'$canonicalName$\'", 68 | "canonicalName", canonical_value->name()); 69 | if (descriptor_->value_count() - 1 > i) { 70 | printer->Print(",\n"); 71 | } else { 72 | printer->Print("\n"); 73 | } 74 | } 75 | 76 | XCodeStandartOutdent(printer); 77 | printer->Print("}\n\n"); 78 | 79 | } 80 | 81 | } // namespace swift 82 | } // namespace compiler 83 | } // namespace protobuf 84 | } // namespace google 85 | -------------------------------------------------------------------------------- /plugin/compiler/react_native/swift_react_enums.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #ifndef swift_REACT_ENUM_H 19 | #define swift_REACT_ENUM_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace google { 28 | namespace protobuf { 29 | namespace io { 30 | class Printer; // printer.h 31 | } 32 | } 33 | 34 | namespace protobuf { 35 | namespace compiler { 36 | namespace swift { 37 | 38 | class ReactEnumGenerator { 39 | public: 40 | explicit ReactEnumGenerator(const EnumDescriptor* descriptor); 41 | ~ReactEnumGenerator(); 42 | 43 | void GenerateSource(io::Printer* printer); 44 | void GenerateSourceImport(io::Printer* printer); 45 | 46 | const EnumDescriptor* descriptor_; 47 | 48 | std::map variables_; 49 | 50 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ReactEnumGenerator); 51 | 52 | private: 53 | 54 | }; 55 | } // namespace swift 56 | } // namespace compiler 57 | } // namespace protobuf 58 | } // namespace google 59 | 60 | #endif // swift_REACT_ENUM_H 61 | -------------------------------------------------------------------------------- /plugin/compiler/swift_enum.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #ifndef swift_ENUM_H 19 | #define swift_ENUM_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace google { 28 | namespace protobuf { 29 | namespace io { 30 | class Printer; // printer.h 31 | } 32 | } 33 | 34 | namespace protobuf { 35 | namespace compiler { 36 | namespace swift { 37 | 38 | class EnumGenerator { 39 | public: 40 | explicit EnumGenerator(const EnumDescriptor* descriptor); 41 | ~EnumGenerator(); 42 | 43 | void GenerateSource(io::Printer* printer); 44 | void GenerateDescription(io::Printer* printer); 45 | void GenerateCaseFields(io::Printer* printer); 46 | 47 | private: 48 | const EnumDescriptor* descriptor_; 49 | void GenerateRawRepresentable(io::Printer* printer); 50 | void GenerateInit(io::Printer* printer); 51 | void GenerateMethodThrow(io::Printer* printer); 52 | void GenerateHash(io::Printer* printer); 53 | std::vector canonical_values_; 54 | 55 | struct Alias { 56 | const EnumValueDescriptor* value; 57 | const EnumValueDescriptor* canonical_value; 58 | }; 59 | std::vector aliases_; 60 | 61 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator); 62 | }; 63 | 64 | } // namespace swift 65 | } // namespace compiler 66 | } // namespace protobuf 67 | } // namespace google 68 | 69 | #endif // swift_ENUM_H 70 | -------------------------------------------------------------------------------- /plugin/compiler/swift_enum_field.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #ifndef swift_ENUM_FIELD_H 19 | #define swift_ENUM_FIELD_H 20 | 21 | #include 22 | #include 23 | 24 | #include "swift_field.h" 25 | 26 | namespace google { 27 | namespace protobuf { 28 | namespace compiler { 29 | namespace swift { 30 | 31 | class EnumFieldGenerator : public FieldGenerator { 32 | public: 33 | explicit EnumFieldGenerator(const FieldDescriptor* descriptor); 34 | ~EnumFieldGenerator(); 35 | 36 | void GenerateExtensionSource(io::Printer* printer) const; 37 | void GenerateVariablesSource(io::Printer* printer) const; 38 | void GenerateSubscript(io::Printer* printer) const; 39 | void GenerateSetSubscript(io::Printer* printer) const; 40 | void GenerateInitializationSource(io::Printer* printer) const; 41 | void GenerateMembersSource(io::Printer* printer) const; 42 | void GenerateBuilderMembersSource(io::Printer* printer) const; 43 | void GenerateMergingCodeSource(io::Printer* printer) const; 44 | void GenerateBuildingCodeSource(io::Printer* printer) const; 45 | void GenerateParsingCodeSource(io::Printer* printer) const; 46 | void GenerateSerializationCodeSource(io::Printer* printer) const; 47 | void GenerateSerializedSizeCodeSource(io::Printer* printer) const; 48 | void GenerateDescriptionCodeSource(io::Printer* printer) const; 49 | void GenerateJSONEncodeCodeSource(io::Printer* printer) const; 50 | void GenerateJSONDecodeCodeSource(io::Printer* printer) const; 51 | void GenerateIsEqualCodeSource(io::Printer* printer) const; 52 | void GenerateHashCodeSource(io::Printer* printer) const; 53 | 54 | string GetBoxedType() const; 55 | 56 | private: 57 | const FieldDescriptor* descriptor_; 58 | std::map variables_; 59 | 60 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator); 61 | }; 62 | 63 | class RepeatedEnumFieldGenerator : public FieldGenerator { 64 | public: 65 | explicit RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor); 66 | ~RepeatedEnumFieldGenerator(); 67 | 68 | void GenerateExtensionSource(io::Printer* printer) const; 69 | void GenerateVariablesSource(io::Printer* printer) const; 70 | void GenerateSubscript(io::Printer* printer) const; 71 | void GenerateSetSubscript(io::Printer* printer) const; 72 | void GenerateInitializationSource(io::Printer* printer) const; 73 | void GenerateMembersSource(io::Printer* printer) const; 74 | void GenerateBuilderMembersSource(io::Printer* printer) const; 75 | void GenerateMergingCodeSource(io::Printer* printer) const; 76 | void GenerateBuildingCodeSource(io::Printer* printer) const; 77 | void GenerateParsingCodeSource(io::Printer* printer) const; 78 | void GenerateSerializationCodeSource(io::Printer* printer) const; 79 | void GenerateSerializedSizeCodeSource(io::Printer* printer) const; 80 | void GenerateDescriptionCodeSource(io::Printer* printer) const; 81 | void GenerateJSONEncodeCodeSource(io::Printer* printer) const; 82 | void GenerateJSONDecodeCodeSource(io::Printer* printer) const; 83 | void GenerateIsEqualCodeSource(io::Printer* printer) const; 84 | void GenerateHashCodeSource(io::Printer* printer) const; 85 | 86 | string GetBoxedType() const; 87 | 88 | private: 89 | const FieldDescriptor* descriptor_; 90 | std::map variables_; 91 | 92 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedEnumFieldGenerator); 93 | }; 94 | 95 | } // namespace swift 96 | } // namespace compiler 97 | } // namespace protobuf 98 | } // namespace google 99 | 100 | #endif // swift_ENUM_FIELD_H 101 | -------------------------------------------------------------------------------- /plugin/compiler/swift_extension.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #ifndef swift_EXTENSION_H 19 | #define swift_EXTENSION_H 20 | 21 | #include 22 | 23 | namespace google { 24 | namespace protobuf { 25 | class FieldDescriptor; // descriptor.h 26 | namespace io { 27 | class Printer; // printer.h 28 | } 29 | } 30 | 31 | namespace protobuf { 32 | namespace compiler { 33 | namespace swift { 34 | 35 | class ExtensionGenerator { 36 | public: 37 | explicit ExtensionGenerator(string classname, const FieldDescriptor* descriptor); 38 | ~ExtensionGenerator(); 39 | 40 | void GenerateMembersSource(io::Printer* printer); 41 | void GenerateMembersSourceExtensions(io::Printer* printer, string fileClass); 42 | void GenerateFieldsSource(io::Printer* printer); 43 | void GenerateFieldsGetterSource(io::Printer* printer, string rootclassname); 44 | void GenerateInitializationSource(io::Printer* printer); 45 | void GenerateRegistrationSource(io::Printer* printer); 46 | 47 | private: 48 | string classname_; 49 | const FieldDescriptor* descriptor_; 50 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator); 51 | }; 52 | } // namespace swift 53 | } // namespace compiler 54 | } // namespace protobuf 55 | } // namespace google 56 | 57 | #endif // swift_MESSAGE_H 58 | -------------------------------------------------------------------------------- /plugin/compiler/swift_field.cc: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #include "swift_field.h" 19 | 20 | #include 21 | #include 22 | #include "swift_field.h" 23 | #include "swift_helpers.h" 24 | #include "swift_primitive_field.h" 25 | #include "swift_map_field.h" 26 | #include "swift_enum_field.h" 27 | #include "swift_message_field.h" 28 | #include "swift_map_field.h" 29 | 30 | namespace google { namespace protobuf { namespace compiler { namespace swift { 31 | 32 | FieldGenerator::~FieldGenerator() { 33 | } 34 | 35 | 36 | FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor) 37 | : descriptor_(descriptor), 38 | field_generators_(new std::unique_ptr[descriptor->field_count()]), 39 | extension_generators_(new std::unique_ptr[descriptor->extension_count()]){ 40 | 41 | 42 | for (int i = 0; i < descriptor->field_count(); i++) { 43 | field_generators_[i].reset(MakeGenerator(descriptor->field(i))); 44 | } 45 | for (int i = 0; i < descriptor->extension_count(); i++) { 46 | extension_generators_[i].reset(MakeGenerator(descriptor->extension(i))); 47 | } 48 | 49 | } 50 | 51 | 52 | FieldGenerator* FieldGeneratorMap::MakeGenerator(const FieldDescriptor* field) { 53 | if (field->is_repeated()) { 54 | switch (GetSwiftType(field)) { 55 | case SWIFT_TYPE_MESSAGE: 56 | return new RepeatedMessageFieldGenerator(field); 57 | case SWIFT_TYPE_MAP: 58 | return new MapFieldGenerator(field); 59 | case SWIFT_TYPE_ENUM: 60 | return new RepeatedEnumFieldGenerator(field); 61 | default: 62 | return new RepeatedPrimitiveFieldGenerator(field); 63 | } 64 | } else { 65 | switch (GetSwiftType(field)) { 66 | case SWIFT_TYPE_MESSAGE: 67 | return new MessageFieldGenerator(field); 68 | case SWIFT_TYPE_ENUM: 69 | return new EnumFieldGenerator(field); 70 | default: 71 | return new PrimitiveFieldGenerator(field); 72 | } 73 | } 74 | } 75 | 76 | 77 | FieldGeneratorMap::~FieldGeneratorMap() { 78 | } 79 | 80 | 81 | const FieldGenerator& FieldGeneratorMap::get(const FieldDescriptor* field) const { 82 | GOOGLE_CHECK_EQ(field->containing_type(), descriptor_); 83 | return *field_generators_[field->index()]; 84 | } 85 | 86 | 87 | const FieldGenerator& FieldGeneratorMap::get_extension(int index) const { 88 | return *extension_generators_[index]; 89 | } 90 | } // namespace swift 91 | } // namespace compiler 92 | } // namespace protobuf 93 | } // namespace google 94 | -------------------------------------------------------------------------------- /plugin/compiler/swift_field.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #ifndef swift_FIELD_H 19 | #define swift_FIELD_H 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | namespace google { 26 | namespace protobuf { 27 | namespace io { 28 | class Printer; // printer.h 29 | } 30 | } 31 | 32 | namespace protobuf { 33 | namespace compiler { 34 | namespace swift { 35 | 36 | class FieldGenerator { 37 | public: 38 | FieldGenerator() {} 39 | virtual ~FieldGenerator(); 40 | 41 | virtual void GenerateExtensionSource(io::Printer* printer) const = 0; 42 | virtual void GenerateVariablesSource(io::Printer* printer) const = 0; 43 | virtual void GenerateSubscript(io::Printer* printer) const = 0; 44 | virtual void GenerateSetSubscript(io::Printer* printer) const = 0; 45 | virtual void GenerateInitializationSource(io::Printer* printer) const = 0; 46 | virtual void GenerateMembersSource(io::Printer* printer) const = 0; 47 | virtual void GenerateBuilderMembersSource(io::Printer* printer) const = 0; 48 | virtual void GenerateMergingCodeSource(io::Printer* printer) const = 0; 49 | virtual void GenerateBuildingCodeSource(io::Printer* printer) const = 0; 50 | virtual void GenerateParsingCodeSource(io::Printer* printer) const = 0; 51 | virtual void GenerateSerializationCodeSource(io::Printer* printer) const = 0; 52 | virtual void GenerateSerializedSizeCodeSource(io::Printer* printer) const = 0; 53 | virtual void GenerateDescriptionCodeSource(io::Printer* printer) const = 0; 54 | virtual void GenerateJSONEncodeCodeSource(io::Printer* printer) const = 0; 55 | virtual void GenerateJSONDecodeCodeSource(io::Printer* printer) const = 0; 56 | virtual void GenerateIsEqualCodeSource(io::Printer* printer) const = 0; 57 | virtual void GenerateHashCodeSource(io::Printer* printer) const = 0; 58 | 59 | private: 60 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator); 61 | }; 62 | 63 | // Convenience class which constructs FieldGenerators for a Descriptor. 64 | class FieldGeneratorMap { 65 | public: 66 | explicit FieldGeneratorMap(const Descriptor* descriptor); 67 | ~FieldGeneratorMap(); 68 | 69 | const FieldGenerator& get(const FieldDescriptor* field) const; 70 | const FieldGenerator& get_extension(int index) const; 71 | 72 | private: 73 | const Descriptor* descriptor_; 74 | std::unique_ptr[]> field_generators_; 75 | std::unique_ptr[]> extension_generators_; 76 | std::unique_ptr[]> oneof_generators_; 77 | 78 | static FieldGenerator* MakeGenerator(const FieldDescriptor* field); 79 | 80 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap); 81 | }; 82 | } // namespace swift 83 | } // namespace compiler 84 | } // namespace protobuf 85 | } // namespace google 86 | 87 | #endif // swift_FIELD_H 88 | -------------------------------------------------------------------------------- /plugin/compiler/swift_file.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #ifndef swift_FILE_H__ 19 | #define swift_FILE_H__ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace google { 27 | namespace protobuf { 28 | class FileDescriptor; // descriptor.h 29 | namespace io { 30 | class Printer; // printer.h 31 | } 32 | } 33 | 34 | namespace protobuf { 35 | namespace compiler { 36 | namespace swift { 37 | 38 | class FileGenerator { 39 | public: 40 | explicit FileGenerator(const FileDescriptor* file); 41 | ~FileGenerator(); 42 | 43 | void GenerateSource(io::Printer* printer); 44 | 45 | const string& classname() { return classname_; } 46 | 47 | private: 48 | const FileDescriptor* file_; 49 | string classname_; 50 | 51 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator); 52 | }; 53 | } // namespace swift 54 | } // namespace compiler 55 | } // namespace protobuf 56 | } // namespace google 57 | 58 | #endif // swift_FILE_H__ 59 | -------------------------------------------------------------------------------- /plugin/compiler/swift_generator.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #ifndef SWIFT_GENERATOR_H 19 | #define SWIFT_GENERATOR_H 20 | 21 | #include 22 | #include 23 | 24 | namespace google { 25 | namespace protobuf { 26 | namespace compiler { 27 | namespace swift { 28 | 29 | class SwiftGenerator : public CodeGenerator { 30 | public: 31 | SwiftGenerator(); 32 | ~SwiftGenerator(); 33 | 34 | bool Generate(const FileDescriptor* file, 35 | const string& parameter, 36 | OutputDirectory* output_directory, 37 | string* error) const; 38 | 39 | private: 40 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SwiftGenerator); 41 | }; 42 | } // namespace swift 43 | } // namespace compiler 44 | } // namespace protobuf 45 | } // namespace google 46 | 47 | #endif // swift_GENERATOR_H 48 | -------------------------------------------------------------------------------- /plugin/compiler/swift_map_field.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #ifndef SWIFT_MAP_FIELD_H 19 | #define SWIFT_MAP_FIELD_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include "swift_field.h" 25 | 26 | namespace google { 27 | namespace protobuf { 28 | namespace compiler { 29 | namespace swift { 30 | 31 | class MapFieldGenerator : public FieldGenerator { 32 | public: 33 | explicit MapFieldGenerator(const FieldDescriptor* descriptor); 34 | ~MapFieldGenerator(); 35 | 36 | void GenerateExtensionSource(io::Printer* printer) const; 37 | void GenerateVariablesSource(io::Printer* printer) const; 38 | void GenerateSubscript(io::Printer* printer) const; 39 | void GenerateSetSubscript(io::Printer* printer) const; 40 | void GenerateInitializationSource(io::Printer* printer) const; 41 | void GenerateMembersSource(io::Printer* printer) const; 42 | void GenerateBuilderMembersSource(io::Printer* printer) const; 43 | void GenerateBuildingCodeSource(io::Printer* printer) const; 44 | void GenerateMergingCodeSource(io::Printer* printer) const; 45 | void GenerateParsingCodeSource(io::Printer* printer) const; 46 | void GenerateSerializationCodeSource(io::Printer* printer) const; 47 | void GenerateSerializedSizeCodeSource(io::Printer* printer) const; 48 | void GenerateDescriptionCodeSource(io::Printer* printer) const; 49 | void GenerateJSONEncodeCodeSource(io::Printer* printer) const; 50 | void GenerateJSONDecodeCodeSource(io::Printer* printer) const; 51 | void GenerateIsEqualCodeSource(io::Printer* printer) const; 52 | void GenerateHashCodeSource(io::Printer* printer) const; 53 | 54 | private: 55 | const FieldDescriptor* descriptor_; 56 | std::map variables_; 57 | 58 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapFieldGenerator); 59 | }; 60 | 61 | } // namespace swift 62 | } // namespace compiler 63 | } // namespace protobuf 64 | } // namespace google 65 | 66 | #endif // SWIFT_Map_FIELD_H 67 | -------------------------------------------------------------------------------- /plugin/compiler/swift_message.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #ifndef swift_MESSAGE_H 19 | #define swift_MESSAGE_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "swift_field.h" 27 | 28 | namespace google { 29 | namespace protobuf { 30 | namespace io { 31 | class Printer; // printer.h 32 | } 33 | } 34 | 35 | namespace protobuf { 36 | namespace compiler { 37 | namespace swift { 38 | 39 | class MessageGenerator { 40 | public: 41 | explicit MessageGenerator(const Descriptor* descriptor); 42 | ~MessageGenerator(); 43 | 44 | void GenerateStaticVariablesInitialization(io::Printer* printer); 45 | void GenerateStaticVariablesSource(io::Printer* printer); 46 | void GenerateSource(io::Printer* printer); 47 | void GenerateMessageIsEqualSource(io::Printer* printer); 48 | void GenerateExtensionRegistrationSource(io::Printer* printer); 49 | void GenerateGlobalStaticVariablesSource(io::Printer* printer, string rootclass); 50 | void GenerateParseFromMethodsSource(io::Printer* printer); 51 | void GenerateSubscript(io::Printer* printer) const; 52 | void GenerateSetSubscript(io::Printer* printer) const; 53 | 54 | void GenerateBuilderExtensions(io::Printer* printer); 55 | private: 56 | 57 | void GenerateMessageSerializationMethodsSource(io::Printer* printer); 58 | 59 | void GenerateSerializeOneFieldSource(io::Printer* printer, 60 | const FieldDescriptor* field); 61 | void GenerateSerializeOneExtensionRangeSource( 62 | io::Printer* printer, const Descriptor::ExtensionRange* range); 63 | 64 | void GenerateMessageDescriptionSource(io::Printer* printer); 65 | 66 | void GenerateMessageJSONSource(io::Printer* printer); 67 | 68 | void GenerateMessageBuilderJSONSource(io::Printer* printer); 69 | 70 | void GenerateDescriptionOneFieldSource(io::Printer* printer, 71 | const FieldDescriptor* field); 72 | void GenerateDescriptionOneExtensionRangeSource( 73 | io::Printer* printer, const Descriptor::ExtensionRange* range); 74 | 75 | 76 | void GenerateIsEqualOneFieldSource(io::Printer* printer, 77 | const FieldDescriptor* field); 78 | void GenerateIsEqualOneExtensionRangeSource( 79 | io::Printer* printer, const Descriptor::ExtensionRange* range); 80 | 81 | void GenerateMessageHashSource(io::Printer* printer); 82 | void GenerateHashOneFieldSource(io::Printer* printer, 83 | const FieldDescriptor* field); 84 | void GenerateHashOneExtensionRangeSource( 85 | io::Printer* printer, const Descriptor::ExtensionRange* range); 86 | 87 | void GenerateBuilderSource(io::Printer* printer); 88 | void GenerateCommonBuilderMethodsSource(io::Printer* printer); 89 | void GenerateBuilderParsingMethodsSource(io::Printer* printer); 90 | void GenerateIsInitializedSource(io::Printer* printer); 91 | 92 | 93 | 94 | 95 | const Descriptor* descriptor_; 96 | FieldGeneratorMap field_generators_; 97 | 98 | std::map variables_; 99 | 100 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator); 101 | 102 | 103 | 104 | 105 | }; 106 | } // namespace swift 107 | } // namespace compiler 108 | } // namespace protobuf 109 | } // namespace google 110 | 111 | #endif // swift_MESSAGE_H 112 | -------------------------------------------------------------------------------- /plugin/compiler/swift_message_field.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #ifndef swift_MESSAGE_FIELD_H 19 | #define swift_MESSAGE_FIELD_H 20 | 21 | #include 22 | #include 23 | 24 | #include "swift_field.h" 25 | 26 | namespace google { 27 | namespace protobuf { 28 | namespace compiler { 29 | namespace swift { 30 | 31 | class MessageFieldGenerator : public FieldGenerator { 32 | public: 33 | explicit MessageFieldGenerator(const FieldDescriptor* descriptor); 34 | ~MessageFieldGenerator(); 35 | 36 | void GenerateExtensionSource(io::Printer* printer) const; 37 | void GenerateVariablesSource(io::Printer* printer) const; 38 | void GenerateSubscript(io::Printer* printer) const; 39 | void GenerateSetSubscript(io::Printer* printer) const; 40 | void GenerateInitializationSource(io::Printer* printer) const; 41 | void GenerateMembersSource(io::Printer* printer) const; 42 | void GenerateBuilderMembersSource(io::Printer* printer) const; 43 | void GenerateMergingCodeSource(io::Printer* printer) const; 44 | void GenerateBuildingCodeSource(io::Printer* printer) const; 45 | void GenerateParsingCodeSource(io::Printer* printer) const; 46 | void GenerateSerializationCodeSource(io::Printer* printer) const; 47 | void GenerateSerializedSizeCodeSource(io::Printer* printer) const; 48 | void GenerateDescriptionCodeSource(io::Printer* printer) const; 49 | void GenerateJSONEncodeCodeSource(io::Printer* printer) const; 50 | void GenerateJSONDecodeCodeSource(io::Printer* printer) const; 51 | void GenerateIsEqualCodeSource(io::Printer* printer) const; 52 | void GenerateHashCodeSource(io::Printer* printer) const; 53 | 54 | string GetBoxedType() const; 55 | 56 | private: 57 | const FieldDescriptor* descriptor_; 58 | std::map variables_; 59 | 60 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator); 61 | }; 62 | 63 | class RepeatedMessageFieldGenerator : public FieldGenerator { 64 | public: 65 | explicit RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor); 66 | ~RepeatedMessageFieldGenerator(); 67 | 68 | void GenerateExtensionSource(io::Printer* printer) const; 69 | void GenerateVariablesSource(io::Printer* printer) const; 70 | void GenerateSubscript(io::Printer* printer) const; 71 | void GenerateSetSubscript(io::Printer* printer) const; 72 | void GenerateInitializationSource(io::Printer* printer) const; 73 | void GenerateMembersSource(io::Printer* printer) const; 74 | void GenerateBuilderMembersSource(io::Printer* printer) const; 75 | void GenerateMergingCodeSource(io::Printer* printer) const; 76 | void GenerateBuildingCodeSource(io::Printer* printer) const; 77 | void GenerateParsingCodeSource(io::Printer* printer) const; 78 | void GenerateSerializationCodeSource(io::Printer* printer) const; 79 | void GenerateSerializedSizeCodeSource(io::Printer* printer) const; 80 | void GenerateDescriptionCodeSource(io::Printer* printer) const; 81 | void GenerateJSONEncodeCodeSource(io::Printer* printer) const; 82 | void GenerateJSONDecodeCodeSource(io::Printer* printer) const; 83 | void GenerateIsEqualCodeSource(io::Printer* printer) const; 84 | void GenerateHashCodeSource(io::Printer* printer) const; 85 | 86 | string GetBoxedType() const; 87 | 88 | private: 89 | const FieldDescriptor* descriptor_; 90 | std::map variables_; 91 | 92 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedMessageFieldGenerator); 93 | }; 94 | } // namespace swift 95 | } // namespace compiler 96 | } // namespace protobuf 97 | } // namespace google 98 | 99 | #endif // swift_MESSAGE_FIELD_H 100 | -------------------------------------------------------------------------------- /plugin/compiler/swift_oneof.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #ifndef swift_ONEOF_H 19 | #define swift_ONEOF_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace google { 27 | namespace protobuf { 28 | namespace io { 29 | class Printer; // printer.h 30 | } 31 | } 32 | 33 | namespace protobuf { 34 | namespace compiler { 35 | namespace swift { 36 | 37 | class OneofGenerator { 38 | public: 39 | explicit OneofGenerator(const OneofDescriptor* descriptor); 40 | ~OneofGenerator(); 41 | 42 | void GenerateSource(io::Printer* printer); 43 | 44 | private: 45 | const OneofDescriptor* descriptor_; 46 | 47 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OneofGenerator); 48 | }; 49 | 50 | } // namespace swift 51 | } // namespace compiler 52 | } // namespace protobuf 53 | } // namespace google 54 | 55 | #endif // swift_ENUM_H 56 | -------------------------------------------------------------------------------- /plugin/compiler/swift_primitive_field.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Swift 2 | // 3 | // Copyright 2014 Alexey Khohklov(AlexeyXo). 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #ifndef SWIFT_PRIMITIVE_FIELD_H 19 | #define SWIFT_PRIMITIVE_FIELD_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include "swift_field.h" 25 | namespace google { 26 | namespace protobuf { 27 | namespace compiler { 28 | namespace swift { 29 | 30 | class PrimitiveFieldGenerator : public FieldGenerator { 31 | public: 32 | explicit PrimitiveFieldGenerator(const FieldDescriptor* descriptor); 33 | ~PrimitiveFieldGenerator(); 34 | 35 | void GenerateExtensionSource(io::Printer* printer) const; 36 | void GenerateVariablesSource(io::Printer* printer) const; 37 | void GenerateSubscript(io::Printer* printer) const; 38 | void GenerateSetSubscript(io::Printer* printer) const; 39 | void GenerateInitializationSource(io::Printer* printer) const; 40 | void GenerateMembersSource(io::Printer* printer) const; 41 | void GenerateBuilderMembersSource(io::Printer* printer) const; 42 | void GenerateMergingCodeSource(io::Printer* printer) const; 43 | void GenerateBuildingCodeSource(io::Printer* printer) const; 44 | void GenerateParsingCodeSource(io::Printer* printer) const; 45 | void GenerateSerializationCodeSource(io::Printer* printer) const; 46 | void GenerateSerializedSizeCodeSource(io::Printer* printer) const; 47 | void GenerateDescriptionCodeSource(io::Printer* printer) const; 48 | void GenerateJSONEncodeCodeSource(io::Printer* printer) const; 49 | void GenerateJSONDecodeCodeSource(io::Printer* printer) const; 50 | void GenerateIsEqualCodeSource(io::Printer* printer) const; 51 | void GenerateHashCodeSource(io::Printer* printer) const; 52 | 53 | private: 54 | const FieldDescriptor* descriptor_; 55 | std::map variables_; 56 | 57 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveFieldGenerator); 58 | }; 59 | 60 | class RepeatedPrimitiveFieldGenerator : public FieldGenerator { 61 | public: 62 | explicit RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor); 63 | ~RepeatedPrimitiveFieldGenerator(); 64 | 65 | void GenerateExtensionSource(io::Printer* printer) const; 66 | void GenerateVariablesSource(io::Printer* printer) const; 67 | void GenerateSubscript(io::Printer* printer) const; 68 | void GenerateSetSubscript(io::Printer* printer) const; 69 | void GenerateInitializationSource(io::Printer* printer) const; 70 | void GenerateMembersSource(io::Printer* printer) const; 71 | void GenerateBuilderMembersSource(io::Printer* printer) const; 72 | void GenerateMergingCodeSource(io::Printer* printer) const; 73 | void GenerateBuildingCodeSource(io::Printer* printer) const; 74 | void GenerateParsingCodeSource(io::Printer* printer) const; 75 | void GenerateSerializationCodeSource(io::Printer* printer) const; 76 | void GenerateSerializedSizeCodeSource(io::Printer* printer) const; 77 | void GenerateDescriptionCodeSource(io::Printer* printer) const; 78 | void GenerateJSONEncodeCodeSource(io::Printer* printer) const; 79 | void GenerateJSONDecodeCodeSource(io::Printer* printer) const; 80 | void GenerateIsEqualCodeSource(io::Printer* printer) const; 81 | void GenerateHashCodeSource(io::Printer* printer) const; 82 | 83 | private: 84 | const FieldDescriptor* descriptor_; 85 | std::map variables_; 86 | 87 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPrimitiveFieldGenerator); 88 | }; 89 | } // namespace swift 90 | } // namespace compiler 91 | } // namespace protobuf 92 | } // namespace google 93 | 94 | #endif // SWIFT_PRIMITIVE_FIELD_H 95 | -------------------------------------------------------------------------------- /plugin/compiler/tests/bar/foo.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package bar; 3 | 4 | message Foo { 5 | optional string hello = 1; 6 | } 7 | -------------------------------------------------------------------------------- /plugin/compiler/tests/baz/foo.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package baz; 3 | 4 | message Foo { 5 | optional string hello = 1; 6 | } 7 | -------------------------------------------------------------------------------- /protobuf-swift.rb: -------------------------------------------------------------------------------- 1 | class ProtobufSwift < Formula 2 | homepage "https://github.com/alexeyxo/protobuf-swift" 3 | url "https://github.com/alexeyxo/protobuf-swift/archive/1.6.tar.gz" 4 | sha256 "1581301212fd8c3aa735e3a9a42444e4f5cb86ac9caf5f477a917f4dfe0eb2e1" 5 | 6 | depends_on "autoconf" => :build 7 | depends_on "automake" => :build 8 | depends_on "libtool" => :build 9 | depends_on "protobuf" 10 | 11 | def install 12 | system "./autogen.sh" 13 | system "./configure", "--prefix=#{prefix}" 14 | system "make" 15 | system "make", "install" 16 | end 17 | 18 | test do 19 | testdata = <<-EOS.undent 20 | enum Flavor{ 21 | CHOCOLATE = 1; 22 | VANILLA = 2; 23 | } 24 | message IceCreamCone { 25 | optional int32 scoops = 1; 26 | optional Flavor flavor = 2; 27 | } 28 | EOS 29 | (testpath/"test.proto").write(testdata) 30 | system "protoc", "test.proto", "--swift_out=." 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /scripts/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | set -ex 4 | 5 | ./autogen.sh 6 | ./configure CXXFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib64 7 | make clean 8 | make -j8 && make install 9 | -------------------------------------------------------------------------------- /scripts/makeDescriptor.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | set -ex 4 | 5 | compiler_root=plugin/compiler 6 | 7 | PATH=$PATH:$compiler_root 8 | 9 | # we need this for bootstrapping 10 | protoc -I$compiler_root $compiler_root/google/protobuf/{,swift-}descriptor.proto --cpp_out=$compiler_root 11 | # build the swift generator 12 | scripts/build.sh 13 | 14 | # compile the swift descriptors and utils into the runtime library 15 | protoc -I$compiler_root $compiler_root/google/protobuf/{,swift-}descriptor.proto --swift_out=Source/ 16 | # protoc -I$compiler_root $compiler_root/google/protobuf/plugin.proto --swift_out=Source/ 17 | # protoc -I$compiler_root $compiler_root/google/protobuf/Utilities/*.proto --swift_out=Source/ 18 | protoc -I$compiler_root $compiler_root/google/protobuf/api.proto --swift_out=Source/ 19 | protoc -I$compiler_root $compiler_root/google/protobuf/any.proto --swift_out=Source/ 20 | protoc -I$compiler_root $compiler_root/google/protobuf/duration.proto --swift_out=Source/ 21 | protoc -I$compiler_root $compiler_root/google/protobuf/empty.proto --swift_out=Source/ 22 | protoc -I$compiler_root $compiler_root/google/protobuf/field_mask.proto --swift_out=Source/ 23 | protoc -I$compiler_root $compiler_root/google/protobuf/source_context.proto --swift_out=Source/ 24 | protoc -I$compiler_root $compiler_root/google/protobuf/struct.proto --swift_out=Source/ 25 | protoc -I$compiler_root $compiler_root/google/protobuf/timestamp.proto --swift_out=Source/ 26 | protoc -I$compiler_root $compiler_root/google/protobuf/type.proto --swift_out=Source/ 27 | protoc -I$compiler_root $compiler_root/google/protobuf/wrappers.proto --swift_out=Source/ 28 | -------------------------------------------------------------------------------- /scripts/makeTests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | set -ex 4 | 5 | compiler_root=plugin/compiler 6 | 7 | PATH=$PATH:$compiler_root 8 | 9 | # compile the unit tests into the runtime library's fixture directory 10 | protoc -I$compiler_root $compiler_root/google/protobuf/unittest*.proto --swift_out=plugin/Tests/pbTests/ 11 | protoc -I$compiler_root $compiler_root/tests/**/*.proto --swift_out=plugin/Tests/pbTests/ 12 | 13 | # compile the performance proto into the runtime 14 | protoc -I$compiler_root $compiler_root/google/protobuf/performance.proto --swift_out=plugin/Tests 15 | --------------------------------------------------------------------------------