├── .editorconfig ├── .git-blame-ignore-revs ├── .github ├── issue_template.md ├── release.yml └── workflows │ ├── build.yml │ ├── check_upstream_protos.yml │ ├── pull_request_label.yml │ └── regular_conformance.yml ├── .gitignore ├── .jazzy.yaml ├── .spi.yml ├── .swift-format ├── CMakeLists.txt ├── CompileTests ├── InternalImportsByDefault │ ├── Package.swift │ ├── Package@swift-5.10.swift │ ├── README.md │ └── Sources │ │ └── InternalImportsByDefault │ │ ├── Protos │ │ ├── ServiceOnly.proto │ │ └── SomeProtoWithBytes.proto │ │ ├── main.swift │ │ └── swift-protobuf-config.json └── MultiModule │ ├── Package.swift │ ├── Package@swift-5.10.swift │ ├── README.md │ ├── Sources │ ├── ImportsAPublicly │ │ └── imports_a_publicly.pb.swift │ ├── ImportsImportsAPublicly │ │ └── imports_imports_a_publicly.pb.swift │ ├── ModuleA │ │ └── a.pb.swift │ └── ReExportAOnly │ │ └── reexport_a_only.pb.swift │ └── Tests │ ├── Test1 │ ├── test1.swift │ └── uses_a_transitively.pb.swift │ └── Test2 │ ├── test2.swift │ └── uses_a_transitively2.pb.swift ├── DevTools ├── CopyrightFixup.sh └── LibraryVersions.py ├── Documentation ├── API.md ├── CONFORMANCE_TESTS.md ├── FAQ.md ├── INTERNALS.md ├── PLUGIN.md ├── RELEASING.md └── STYLE_GUIDELINES.md ├── FuzzTesting ├── .gitignore ├── FailCases │ ├── Binary-packed-float-double-growth │ ├── JSON-Any │ ├── JSON-malformed-utf8 │ ├── TextFormat-ending-minus │ ├── TextFormat-ending-zero │ ├── TextFormat-map-loops-forever │ ├── TextFormat-map-loops-forever2 │ ├── TextFormat-octal-out-of-range │ ├── clusterfuzz-testcase-FuzzJSON_release-5596804654694400 │ ├── clusterfuzz-testcase-FuzzTextFormat_release-4619956026146816 │ ├── clusterfuzz-testcase-minimized-FuzzAsyncMessageSequence_debug-5217919734513664 │ ├── clusterfuzz-testcase-minimized-FuzzBinaryDelimited_debug-4802082831204352 │ ├── clusterfuzz-testcase-minimized-FuzzBinaryDelimited_debug-5927982738046976 │ ├── clusterfuzz-testcase-minimized-FuzzBinaryDelimited_release-5166893326794752 │ ├── clusterfuzz-testcase-minimized-FuzzBinary_release-5649532441460736 │ ├── clusterfuzz-testcase-minimized-FuzzJSON_debug-4506617283477504 │ ├── clusterfuzz-testcase-minimized-FuzzJSON_debug-5207244346621952 │ ├── clusterfuzz-testcase-minimized-FuzzJSON_debug-5467498116415488 │ ├── clusterfuzz-testcase-minimized-FuzzJSON_debug-5491136978878464 │ ├── clusterfuzz-testcase-minimized-FuzzJSON_debug-6286338012282880 │ ├── clusterfuzz-testcase-minimized-FuzzJSON_release-4623064839618560 │ ├── clusterfuzz-testcase-minimized-FuzzJSON_release-4827369236463616 │ ├── clusterfuzz-testcase-minimized-FuzzJSON_release-4929034878844928 │ ├── clusterfuzz-testcase-minimized-FuzzJSON_release-5689942715006976 │ ├── clusterfuzz-testcase-minimized-FuzzTextFormat_debug-5687602305433600 │ ├── clusterfuzz-testcase-minimized-FuzzTextFormat_debug-5700784104275968 │ ├── clusterfuzz-testcase-minimized-FuzzTextFormat_release-4519429842010112 │ ├── clusterfuzz-testcase-minimized-FuzzTextFormat_release-4619956026146816 │ ├── clusterfuzz-testcase-minimized-FuzzTextFormat_release-4769249378304000 │ ├── clusterfuzz-testcase-minimized-FuzzTextFormat_release-5003886170537984 │ ├── clusterfuzz-testcase-minimized-FuzzTextFormat_release-5109315292233728 │ ├── clusterfuzz-testcase-minimized-FuzzTextFormat_release-5835603108298752 │ ├── clusterfuzz-testcase-minimized-FuzzTextFormat_release-5836572361621504 │ ├── clusterfuzz-testcase-minimized-FuzzTextFormat_release-6026353006215168 │ ├── clusterfuzz-testcase-minimized-swift-protobuf-fuzz-4649469707681792 │ ├── clusterfuzz-testcase-minimized-swift-protobuf-fuzz-4901281945747456 │ ├── clusterfuzz-testcase-minimized-swift-protobuf-fuzz-5029515526012928 │ └── oom-fb8c6ebb36a5ad53472bc2c006de6e7c6e2d10e3 ├── FuzzAsyncMessageSequence.dict ├── FuzzBinary.dict ├── FuzzBinaryDelimited.dict ├── FuzzJSON.dict ├── FuzzTextFormat.dict ├── Package.swift ├── README.md ├── Sources │ ├── FuzzAsyncMessageSequence │ │ └── main.swift │ ├── FuzzBinary │ │ └── main.swift │ ├── FuzzBinaryDelimited │ │ └── main.swift │ ├── FuzzCommon │ │ ├── Options.swift │ │ └── fuzz_testing.pb.swift │ ├── FuzzJSON │ │ └── main.swift │ └── FuzzTextFormat │ │ └── main.swift ├── Tests │ └── FuzzCommonTests │ │ └── Test_Options.swift ├── do_build.sh └── make_FuzzBinary_dict ├── LICENSE.txt ├── Makefile ├── Package.swift ├── Performance ├── .gitignore ├── Harness.cc ├── Harness.h ├── Harness.swift ├── Protobuf.tracetemplate ├── css │ └── harness-visualization.css ├── generators │ ├── cpp.sh │ ├── proto.sh │ └── swift.sh ├── harness-visualization.html ├── js │ ├── harness-visualization.js │ └── results.js.template ├── main.cc ├── main.swift ├── perf_runner.sh └── runners │ ├── CMakeLists.txt │ ├── cpp.sh │ └── swift.sh ├── PluginExamples ├── Package.swift ├── Package@swift-5.10.swift └── Sources │ ├── AccessLevelOnImport │ ├── AccessLevelOnImport │ │ └── AccessLevelOnImport.proto │ ├── Dependency │ │ └── Dependency.proto │ ├── empty.swift │ └── swift-protobuf-config.json │ ├── ExampleTests │ ├── AccessLevelOnImportTests.swift │ └── ExampleTests.swift │ ├── Import │ ├── Bar │ │ └── Bar.proto │ ├── Foo │ │ └── Foo.proto │ ├── empty.swift │ └── swift-protobuf-config.json │ ├── Nested │ ├── Nested │ │ └── Nested.proto │ ├── empty.swift │ └── swift-protobuf-config.json │ └── Simple │ ├── Simple.proto │ ├── empty.swift │ └── swift-protobuf-config.json ├── Plugins └── SwiftProtobufPlugin │ └── plugin.swift ├── Protos ├── CompileTests │ ├── InternalImportsByDefault │ │ ├── ServiceOnly.proto │ │ └── SomeProtoWithBytes.proto │ └── MultiModule │ │ ├── Sources │ │ ├── ImportsAPublicly │ │ │ └── imports_a_publicly.proto │ │ ├── ImportsImportsAPublicly │ │ │ └── imports_imports_a_publicly.proto │ │ ├── ModuleA │ │ │ └── a.proto │ │ └── ReExportAOnly │ │ │ └── reexport_a_only.proto │ │ ├── Tests │ │ ├── Test1 │ │ │ └── uses_a_transitively.proto │ │ └── Test2 │ │ │ └── uses_a_transitively2.proto │ │ └── module_mappings.pbascii ├── Conformance │ ├── conformance │ │ ├── conformance.proto │ │ └── test_protos │ │ │ └── test_messages_edition2023.proto │ ├── editions │ │ ├── test_messages_proto2_editions.proto │ │ └── test_messages_proto3_editions.proto │ └── google │ │ └── protobuf │ │ ├── test_messages_proto2.proto │ │ └── test_messages_proto3.proto ├── README.md ├── SwiftProtobuf │ └── google │ │ └── protobuf │ │ ├── any.proto │ │ ├── api.proto │ │ ├── descriptor.proto │ │ ├── duration.proto │ │ ├── empty.proto │ │ ├── field_mask.proto │ │ ├── source_context.proto │ │ ├── struct.proto │ │ ├── timestamp.proto │ │ ├── type.proto │ │ └── wrappers.proto ├── SwiftProtobufPluginLibrary │ ├── google │ │ └── protobuf │ │ │ └── compiler │ │ │ └── plugin.proto │ └── swift_protobuf_module_mappings.proto ├── SwiftProtobufPluginLibraryTests │ ├── pluginlib_descriptor_delimited.proto │ ├── pluginlib_descriptor_test.proto │ ├── pluginlib_descriptor_test2.proto │ ├── pluginlib_descriptor_test_import.proto │ ├── test_features.proto │ ├── unittest_delimited.proto │ └── unittest_delimited_import.proto ├── SwiftProtobufTests │ ├── any_test.proto │ ├── fuzz_testing.proto │ ├── generated_swift_names_enum_cases.proto │ ├── generated_swift_names_enums.proto │ ├── generated_swift_names_fields.proto │ ├── generated_swift_names_messages.proto │ ├── map_proto2_unittest.proto │ ├── map_unittest.proto │ ├── test_messages_proto3.proto │ ├── unittest.proto │ ├── unittest_import.proto │ ├── unittest_import_public.proto │ ├── unittest_mset.proto │ ├── unittest_mset_wire_format.proto │ ├── unittest_preserve_unknown_enum.proto │ ├── unittest_preserve_unknown_enum2.proto │ ├── unittest_proto3.proto │ ├── unittest_proto3_optional.proto │ ├── unittest_swift_all_required_types.proto │ ├── unittest_swift_cycle.proto │ ├── unittest_swift_deprecated.proto │ ├── unittest_swift_deprecated_file.proto │ ├── unittest_swift_enum_optional_default.proto │ ├── unittest_swift_enum_proto2.proto │ ├── unittest_swift_enum_proto3.proto │ ├── unittest_swift_extension.proto │ ├── unittest_swift_extension2.proto │ ├── unittest_swift_extension3.proto │ ├── unittest_swift_extension4.proto │ ├── unittest_swift_fieldorder.proto │ ├── unittest_swift_groups.proto │ ├── unittest_swift_json.proto │ ├── unittest_swift_naming.proto │ ├── unittest_swift_naming_no_prefix.proto │ ├── unittest_swift_naming_number_prefix.proto │ ├── unittest_swift_oneof_all_required.proto │ ├── unittest_swift_oneof_merging.proto │ ├── unittest_swift_reserved.proto │ ├── unittest_swift_reserved_ext.proto │ ├── unittest_swift_runtime_proto2.proto │ ├── unittest_swift_runtime_proto3.proto │ └── unittest_well_known_types.proto ├── protoc-gen-swiftTests │ └── plugin_descriptor_test.proto └── upstream │ ├── conformance │ ├── conformance.proto │ └── test_protos │ │ └── test_messages_edition2023.proto │ ├── editions │ └── golden │ │ ├── test_messages_proto2_editions.proto │ │ └── test_messages_proto3_editions.proto │ └── google │ └── protobuf │ ├── any.proto │ ├── any_test.proto │ ├── api.proto │ ├── compiler │ └── plugin.proto │ ├── cpp_features.proto │ ├── descriptor.proto │ ├── duration.proto │ ├── edition_unittest.proto │ ├── empty.proto │ ├── field_mask.proto │ ├── late_loaded_option.proto │ ├── late_loaded_option_user.proto │ ├── map_lite_unittest.proto │ ├── map_proto2_unittest.proto │ ├── map_proto3_unittest.proto │ ├── map_unittest.proto │ ├── only_one_enum_test.proto │ ├── sample_messages_edition.proto │ ├── source_context.proto │ ├── struct.proto │ ├── test_messages_proto2.proto │ ├── test_messages_proto3.proto │ ├── timestamp.proto │ ├── type.proto │ ├── unittest.proto │ ├── unittest_arena.proto │ ├── unittest_custom_options.proto │ ├── unittest_delimited.proto │ ├── unittest_delimited_import.proto │ ├── unittest_drop_unknown_fields.proto │ ├── unittest_embed_optimize_for.proto │ ├── unittest_empty.proto │ ├── unittest_enormous_descriptor.proto │ ├── unittest_extension_set.proto │ ├── unittest_features.proto │ ├── unittest_import.proto │ ├── unittest_import_lite.proto │ ├── unittest_import_public.proto │ ├── unittest_import_public_lite.proto │ ├── unittest_invalid_features.proto │ ├── unittest_lazy_dependencies.proto │ ├── unittest_lazy_dependencies_custom_option.proto │ ├── unittest_lazy_dependencies_enum.proto │ ├── unittest_legacy_features.proto │ ├── unittest_lite.proto │ ├── unittest_lite_imports_nonlite.proto │ ├── unittest_mset.proto │ ├── unittest_mset_wire_format.proto │ ├── unittest_no_field_presence.proto │ ├── unittest_no_generic_services.proto │ ├── unittest_optimize_for.proto │ ├── unittest_preserve_unknown_enum.proto │ ├── unittest_preserve_unknown_enum2.proto │ ├── unittest_proto3.proto │ ├── unittest_proto3_arena.proto │ ├── unittest_proto3_arena_lite.proto │ ├── unittest_proto3_bad_macros.proto │ ├── unittest_proto3_extensions.proto │ ├── unittest_proto3_lite.proto │ ├── unittest_proto3_optional.proto │ ├── unittest_redaction.proto │ ├── unittest_retention.proto │ ├── unittest_string_type.proto │ ├── unittest_string_view.proto │ ├── unittest_well_known_types.proto │ └── wrappers.proto ├── README.md ├── Reference ├── CompileTests │ ├── InternalImportsByDefault │ │ ├── ServiceOnly.pb.swift │ │ └── SomeProtoWithBytes.pb.swift │ └── MultiModule │ │ ├── Sources │ │ ├── ImportsAPublicly │ │ │ └── imports_a_publicly.pb.swift │ │ ├── ImportsImportsAPublicly │ │ │ └── imports_imports_a_publicly.pb.swift │ │ ├── ModuleA │ │ │ └── a.pb.swift │ │ └── ReExportAOnly │ │ │ └── reexport_a_only.pb.swift │ │ └── Tests │ │ ├── Test1 │ │ └── uses_a_transitively.pb.swift │ │ └── Test2 │ │ └── uses_a_transitively2.pb.swift ├── Conformance │ ├── conformance │ │ ├── conformance.pb.swift │ │ └── test_protos │ │ │ └── test_messages_edition2023.pb.swift │ ├── editions │ │ ├── test_messages_proto2_editions.pb.swift │ │ └── test_messages_proto3_editions.pb.swift │ └── google │ │ └── protobuf │ │ ├── test_messages_proto2.pb.swift │ │ └── test_messages_proto3.pb.swift ├── SwiftProtobuf │ └── google │ │ └── protobuf │ │ ├── any.pb.swift │ │ ├── api.pb.swift │ │ ├── descriptor.pb.swift │ │ ├── duration.pb.swift │ │ ├── empty.pb.swift │ │ ├── field_mask.pb.swift │ │ ├── source_context.pb.swift │ │ ├── struct.pb.swift │ │ ├── timestamp.pb.swift │ │ ├── type.pb.swift │ │ └── wrappers.pb.swift ├── SwiftProtobufPluginLibrary │ ├── google │ │ └── protobuf │ │ │ └── compiler │ │ │ └── plugin.pb.swift │ └── swift_protobuf_module_mappings.pb.swift ├── SwiftProtobufPluginLibraryTests │ ├── pluginlib_descriptor_delimited.pb.swift │ ├── pluginlib_descriptor_test.pb.swift │ ├── pluginlib_descriptor_test2.pb.swift │ ├── pluginlib_descriptor_test_import.pb.swift │ ├── test_features.pb.swift │ ├── unittest_delimited.pb.swift │ └── unittest_delimited_import.pb.swift ├── SwiftProtobufTests │ ├── any_test.pb.swift │ ├── fuzz_testing.pb.swift │ ├── generated_swift_names_enum_cases.pb.swift │ ├── generated_swift_names_enums.pb.swift │ ├── generated_swift_names_fields.pb.swift │ ├── generated_swift_names_messages.pb.swift │ ├── map_proto2_unittest.pb.swift │ ├── map_unittest.pb.swift │ ├── test_messages_proto3.pb.swift │ ├── unittest.pb.swift │ ├── unittest_import.pb.swift │ ├── unittest_import_public.pb.swift │ ├── unittest_mset.pb.swift │ ├── unittest_mset_wire_format.pb.swift │ ├── unittest_preserve_unknown_enum.pb.swift │ ├── unittest_preserve_unknown_enum2.pb.swift │ ├── unittest_proto3.pb.swift │ ├── unittest_proto3_optional.pb.swift │ ├── unittest_swift_all_required_types.pb.swift │ ├── unittest_swift_cycle.pb.swift │ ├── unittest_swift_deprecated.pb.swift │ ├── unittest_swift_deprecated_file.pb.swift │ ├── unittest_swift_enum_optional_default.pb.swift │ ├── unittest_swift_enum_proto2.pb.swift │ ├── unittest_swift_enum_proto3.pb.swift │ ├── unittest_swift_extension.pb.swift │ ├── unittest_swift_extension2.pb.swift │ ├── unittest_swift_extension3.pb.swift │ ├── unittest_swift_extension4.pb.swift │ ├── unittest_swift_fieldorder.pb.swift │ ├── unittest_swift_groups.pb.swift │ ├── unittest_swift_json.pb.swift │ ├── unittest_swift_naming.pb.swift │ ├── unittest_swift_naming_no_prefix.pb.swift │ ├── unittest_swift_naming_number_prefix.pb.swift │ ├── unittest_swift_oneof_all_required.pb.swift │ ├── unittest_swift_oneof_merging.pb.swift │ ├── unittest_swift_reserved.pb.swift │ ├── unittest_swift_reserved_ext.pb.swift │ ├── unittest_swift_runtime_proto2.pb.swift │ ├── unittest_swift_runtime_proto3.pb.swift │ └── unittest_well_known_types.pb.swift ├── protoc-gen-swiftTests │ └── plugin_descriptor_test.pb.swift └── upstream │ ├── conformance │ ├── conformance.pb.swift │ └── test_protos │ │ └── test_messages_edition2023.pb.swift │ ├── editions │ └── golden │ │ ├── test_messages_proto2_editions.pb.swift │ │ └── test_messages_proto3_editions.pb.swift │ └── google │ └── protobuf │ ├── any.pb.swift │ ├── any_test.pb.swift │ ├── api.pb.swift │ ├── compiler │ └── plugin.pb.swift │ ├── cpp_features.pb.swift │ ├── descriptor.pb.swift │ ├── duration.pb.swift │ ├── edition_unittest.pb.swift │ ├── empty.pb.swift │ ├── field_mask.pb.swift │ ├── late_loaded_option.pb.swift │ ├── late_loaded_option_user.pb.swift │ ├── map_lite_unittest.pb.swift │ ├── map_proto2_unittest.pb.swift │ ├── map_proto3_unittest.pb.swift │ ├── map_unittest.pb.swift │ ├── only_one_enum_test.pb.swift │ ├── sample_messages_edition.pb.swift │ ├── source_context.pb.swift │ ├── struct.pb.swift │ ├── test_messages_proto2.pb.swift │ ├── test_messages_proto3.pb.swift │ ├── timestamp.pb.swift │ ├── type.pb.swift │ ├── unittest.pb.swift │ ├── unittest_arena.pb.swift │ ├── unittest_custom_options.pb.swift │ ├── unittest_delimited.pb.swift │ ├── unittest_delimited_import.pb.swift │ ├── unittest_drop_unknown_fields.pb.swift │ ├── unittest_embed_optimize_for.pb.swift │ ├── unittest_empty.pb.swift │ ├── unittest_enormous_descriptor.pb.swift │ ├── unittest_extension_set.pb.swift │ ├── unittest_features.pb.swift │ ├── unittest_import.pb.swift │ ├── unittest_import_lite.pb.swift │ ├── unittest_import_public.pb.swift │ ├── unittest_import_public_lite.pb.swift │ ├── unittest_invalid_features.pb.swift │ ├── unittest_lazy_dependencies.pb.swift │ ├── unittest_lazy_dependencies_custom_option.pb.swift │ ├── unittest_lazy_dependencies_enum.pb.swift │ ├── unittest_legacy_features.pb.swift │ ├── unittest_lite.pb.swift │ ├── unittest_lite_imports_nonlite.pb.swift │ ├── unittest_mset.pb.swift │ ├── unittest_mset_wire_format.pb.swift │ ├── unittest_no_field_presence.pb.swift │ ├── unittest_no_generic_services.pb.swift │ ├── unittest_optimize_for.pb.swift │ ├── unittest_preserve_unknown_enum.pb.swift │ ├── unittest_preserve_unknown_enum2.pb.swift │ ├── unittest_proto3.pb.swift │ ├── unittest_proto3_arena.pb.swift │ ├── unittest_proto3_arena_lite.pb.swift │ ├── unittest_proto3_bad_macros.pb.swift │ ├── unittest_proto3_extensions.pb.swift │ ├── unittest_proto3_lite.pb.swift │ ├── unittest_proto3_optional.pb.swift │ ├── unittest_redaction.pb.swift │ ├── unittest_retention.pb.swift │ ├── unittest_string_type.pb.swift │ ├── unittest_string_view.pb.swift │ ├── unittest_well_known_types.pb.swift │ └── wrappers.pb.swift ├── Sources ├── CMakeLists.txt ├── Conformance │ ├── Docs.docc │ │ └── index.md │ ├── conformance.pb.swift │ ├── failure_list_swift.txt │ ├── main.swift │ ├── test_messages_edition2023.pb.swift │ ├── test_messages_proto2.pb.swift │ ├── test_messages_proto2_editions.pb.swift │ ├── test_messages_proto3.pb.swift │ ├── test_messages_proto3_editions.pb.swift │ └── text_format_failure_list_swift.txt ├── SwiftProtobuf │ ├── AnyMessageStorage.swift │ ├── AnyUnpackError.swift │ ├── AsyncMessageSequence.swift │ ├── BinaryDecoder.swift │ ├── BinaryDecodingError.swift │ ├── BinaryDecodingOptions.swift │ ├── BinaryDelimited.swift │ ├── BinaryEncoder.swift │ ├── BinaryEncodingError.swift │ ├── BinaryEncodingOptions.swift │ ├── BinaryEncodingSizeVisitor.swift │ ├── BinaryEncodingVisitor.swift │ ├── CMakeLists.txt │ ├── CustomJSONCodable.swift │ ├── Decoder.swift │ ├── Docs.docc │ │ ├── API.md │ │ └── index.md │ ├── DoubleParser.swift │ ├── Enum.swift │ ├── ExtensibleMessage.swift │ ├── ExtensionFieldValueSet.swift │ ├── ExtensionFields.swift │ ├── ExtensionMap.swift │ ├── FieldTag.swift │ ├── FieldTypes.swift │ ├── Google_Protobuf_Any+Extensions.swift │ ├── Google_Protobuf_Any+Registry.swift │ ├── Google_Protobuf_Duration+Extensions.swift │ ├── Google_Protobuf_FieldMask+Extensions.swift │ ├── Google_Protobuf_ListValue+Extensions.swift │ ├── Google_Protobuf_NullValue+Extensions.swift │ ├── Google_Protobuf_Struct+Extensions.swift │ ├── Google_Protobuf_Timestamp+Extensions.swift │ ├── Google_Protobuf_Value+Extensions.swift │ ├── Google_Protobuf_Wrappers+Extensions.swift │ ├── HashVisitor.swift │ ├── Internal.swift │ ├── JSONDecoder.swift │ ├── JSONDecodingError.swift │ ├── JSONDecodingOptions.swift │ ├── JSONEncoder.swift │ ├── JSONEncodingError.swift │ ├── JSONEncodingOptions.swift │ ├── JSONEncodingVisitor.swift │ ├── JSONMapEncodingVisitor.swift │ ├── JSONScanner.swift │ ├── MathUtils.swift │ ├── Message+AnyAdditions.swift │ ├── Message+BinaryAdditions.swift │ ├── Message+BinaryAdditions_Data.swift │ ├── Message+FieldMask.swift │ ├── Message+JSONAdditions.swift │ ├── Message+JSONAdditions_Data.swift │ ├── Message+JSONArrayAdditions.swift │ ├── Message+JSONArrayAdditions_Data.swift │ ├── Message+TextFormatAdditions.swift │ ├── Message.swift │ ├── MessageExtension.swift │ ├── NameMap.swift │ ├── PathDecoder.swift │ ├── PathVisitor.swift │ ├── PrivacyInfo.xcprivacy │ ├── ProtoNameProviding.swift │ ├── ProtobufAPIVersionCheck.swift │ ├── ProtobufMap.swift │ ├── SelectiveVisitor.swift │ ├── SimpleExtensionMap.swift │ ├── StringUtils.swift │ ├── SwiftProtobufContiguousBytes.swift │ ├── SwiftProtobufError.swift │ ├── TextFormatDecoder.swift │ ├── TextFormatDecodingError.swift │ ├── TextFormatDecodingOptions.swift │ ├── TextFormatEncoder.swift │ ├── TextFormatEncodingOptions.swift │ ├── TextFormatEncodingVisitor.swift │ ├── TextFormatScanner.swift │ ├── TimeUtils.swift │ ├── UnknownStorage.swift │ ├── UnsafeRawPointer+Shims.swift │ ├── Varint.swift │ ├── Version.swift │ ├── Visitor.swift │ ├── WireFormat.swift │ ├── ZigZag.swift │ ├── any.pb.swift │ ├── api.pb.swift │ ├── descriptor.pb.swift │ ├── duration.pb.swift │ ├── empty.pb.swift │ ├── field_mask.pb.swift │ ├── source_context.pb.swift │ ├── struct.pb.swift │ ├── timestamp.pb.swift │ ├── type.pb.swift │ └── wrappers.pb.swift ├── SwiftProtobufPluginLibrary │ ├── CMakeLists.txt │ ├── CodeGenerator.swift │ ├── CodeGeneratorParameter.swift │ ├── CodePrinter.swift │ ├── Descriptor+Extensions.swift │ ├── Descriptor.swift │ ├── Docs.docc │ │ └── index.md │ ├── FeatureResolver.swift │ ├── FieldNumbers.swift │ ├── GeneratorOutputs.swift │ ├── Google_Protobuf_Compiler_CodeGeneratorResponse+Extensions.swift │ ├── Google_Protobuf_Edition+Extensions.swift │ ├── Google_Protobuf_SourceCodeInfo+Extensions.swift │ ├── NamingUtils.swift │ ├── PluginLibEditionDefaults.swift │ ├── PrivacyInfo.xcprivacy │ ├── ProtoCompilerContext.swift │ ├── ProtoFileToModuleMappings.swift │ ├── ProvidesDeprecationComment.swift │ ├── ProvidesLocationPath.swift │ ├── ProvidesSourceCodeLocation.swift │ ├── StandardErrorOutputStream.swift │ ├── StringUtils.swift │ ├── SwiftLanguage.swift │ ├── SwiftProtobufInfo.swift │ ├── SwiftProtobufNamer.swift │ ├── UnicodeScalar+Extensions.swift │ ├── plugin.pb.swift │ └── swift_protobuf_module_mappings.pb.swift ├── SwiftProtobufTestHelpers │ └── Descriptor+TestHelpers.swift └── protoc-gen-swift │ ├── CMakeLists.txt │ ├── CommandLine+Extensions.swift │ ├── Descriptor+Extensions.swift │ ├── Docs.docc │ ├── index.md │ └── spm-plugin.md │ ├── EnumGenerator.swift │ ├── ExtensionSetGenerator.swift │ ├── FieldGenerator.swift │ ├── FileGenerator.swift │ ├── FileIo.swift │ ├── GenerationError.swift │ ├── GeneratorOptions.swift │ ├── Google_Protobuf_FileDescriptorProto+Extensions.swift │ ├── MessageFieldGenerator.swift │ ├── MessageGenerator.swift │ ├── MessageStorageClassGenerator.swift │ ├── MessageStorageDecision.swift │ ├── OneofGenerator.swift │ ├── ProvidesDeprecationComment+Extensions.swift │ ├── ProvidesSourceCodeLocation+Extensions.swift │ ├── Range+Extensions.swift │ ├── StringUtils.swift │ ├── SwiftGeneratorPlugin.swift │ ├── SwiftProtobufNamer+Extensions.swift │ └── Version.swift ├── SwiftProtobuf.podspec ├── Tests ├── SwiftProtobufPluginLibraryTests │ ├── DescriptorTestData.swift │ ├── PluginLibTestingEditionDefaults.swift │ ├── Test_Descriptor.swift │ ├── Test_Descriptor_FeatureResolution.swift │ ├── Test_FeatureResolver.swift │ ├── Test_NamingUtils.swift │ ├── Test_ProtoFileToModuleMappings.swift │ ├── Test_SwiftLanguage.swift │ ├── Test_SwiftProtobufNamer.swift │ ├── pluginlib_descriptor_delimited.pb.swift │ ├── pluginlib_descriptor_test.pb.swift │ ├── pluginlib_descriptor_test2.pb.swift │ ├── pluginlib_descriptor_test_import.pb.swift │ ├── test_features.pb.swift │ ├── unittest_delimited.pb.swift │ └── unittest_delimited_import.pb.swift ├── SwiftProtobufTests │ ├── Data+TestHelpers.swift │ ├── TestHelpers.swift │ ├── Test_AllTypes.swift │ ├── Test_AllTypes_Proto3.swift │ ├── Test_AllTypes_Proto3_Optional.swift │ ├── Test_Any.swift │ ├── Test_Api.swift │ ├── Test_AsyncMessageSequence.swift │ ├── Test_BasicFields_Access_Proto2.swift │ ├── Test_BasicFields_Access_Proto3.swift │ ├── Test_BinaryDecodingOptions.swift │ ├── Test_BinaryDelimited.swift │ ├── Test_BinaryEncodingOptions.swift │ ├── Test_Conformance.swift │ ├── Test_Duration.swift │ ├── Test_Empty.swift │ ├── Test_Enum.swift │ ├── Test_EnumWithAliases.swift │ ├── Test_Enum_Proto2.swift │ ├── Test_Extensions.swift │ ├── Test_ExtremeDefaultValues.swift │ ├── Test_FieldMask.swift │ ├── Test_FieldOrdering.swift │ ├── Test_FuzzTests.swift │ ├── Test_GroupWithGroups.swift │ ├── Test_JSON.swift │ ├── Test_JSONDecodingOptions.swift │ ├── Test_JSONEncodingOptions.swift │ ├── Test_JSON_Array.swift │ ├── Test_JSON_Conformance.swift │ ├── Test_JSON_Extensions.swift │ ├── Test_JSON_Group.swift │ ├── Test_JSON_Performance.swift │ ├── Test_Map.swift │ ├── Test_MapFields_Access_Proto2.swift │ ├── Test_MapFields_Access_Proto3.swift │ ├── Test_Map_JSON.swift │ ├── Test_Merge.swift │ ├── Test_MessageSet.swift │ ├── Test_Naming.swift │ ├── Test_OneofFields_Access_Proto2.swift │ ├── Test_OneofFields_Access_Proto3.swift │ ├── Test_Packed.swift │ ├── Test_ParsingMerge.swift │ ├── Test_ReallyLargeTagNumber.swift │ ├── Test_RecursiveMap.swift │ ├── Test_Required.swift │ ├── Test_Reserved.swift │ ├── Test_SimpleExtensionMap.swift │ ├── Test_Struct.swift │ ├── Test_TextFormatDecodingOptions.swift │ ├── Test_TextFormat_Map_proto3.swift │ ├── Test_TextFormat_Performance.swift │ ├── Test_TextFormat_Unknown.swift │ ├── Test_TextFormat_WKT_proto3.swift │ ├── Test_TextFormat_proto2.swift │ ├── Test_TextFormat_proto2_extensions.swift │ ├── Test_TextFormat_proto3.swift │ ├── Test_Timestamp.swift │ ├── Test_Type.swift │ ├── Test_Unknown_proto2.swift │ ├── Test_Unknown_proto3.swift │ ├── Test_Wrappers.swift │ ├── any_test.pb.swift │ ├── fuzz_testing.pb.swift │ ├── generated_swift_names_enum_cases.pb.swift │ ├── generated_swift_names_enums.pb.swift │ ├── generated_swift_names_fields.pb.swift │ ├── generated_swift_names_messages.pb.swift │ ├── map_proto2_unittest.pb.swift │ ├── map_unittest.pb.swift │ ├── test_messages_proto3.pb.swift │ ├── unittest.pb.swift │ ├── unittest_import.pb.swift │ ├── unittest_import_public.pb.swift │ ├── unittest_mset.pb.swift │ ├── unittest_mset_wire_format.pb.swift │ ├── unittest_preserve_unknown_enum.pb.swift │ ├── unittest_preserve_unknown_enum2.pb.swift │ ├── unittest_proto3.pb.swift │ ├── unittest_proto3_optional.pb.swift │ ├── unittest_swift_all_required_types.pb.swift │ ├── unittest_swift_cycle.pb.swift │ ├── unittest_swift_deprecated.pb.swift │ ├── unittest_swift_deprecated_file.pb.swift │ ├── unittest_swift_enum_optional_default.pb.swift │ ├── unittest_swift_enum_proto2.pb.swift │ ├── unittest_swift_enum_proto3.pb.swift │ ├── unittest_swift_extension.pb.swift │ ├── unittest_swift_extension2.pb.swift │ ├── unittest_swift_extension3.pb.swift │ ├── unittest_swift_extension4.pb.swift │ ├── unittest_swift_fieldorder.pb.swift │ ├── unittest_swift_groups.pb.swift │ ├── unittest_swift_json.pb.swift │ ├── unittest_swift_naming.pb.swift │ ├── unittest_swift_naming_no_prefix.pb.swift │ ├── unittest_swift_naming_number_prefix.pb.swift │ ├── unittest_swift_oneof_all_required.pb.swift │ ├── unittest_swift_oneof_merging.pb.swift │ ├── unittest_swift_reserved.pb.swift │ ├── unittest_swift_reserved_ext.pb.swift │ ├── unittest_swift_runtime_proto2.pb.swift │ ├── unittest_swift_runtime_proto3.pb.swift │ └── unittest_well_known_types.pb.swift └── protoc-gen-swiftTests │ ├── DescriptorTestData.swift │ ├── Test_DescriptorExtensions.swift │ └── Test_SwiftProtobufNamerExtensions.swift └── cmake └── modules └── SwiftSupport.cmake /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | -------------------------------------------------------------------------------- /.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | # Ignore the commit where all the sources were reformatted with no other changes. 2 | ac8da77c937f3c98c3959f72e76184b6b577cf38 3 | # Ignore some followup commits for things swift-format lint reported. 4 | e1c4ca3714b1d423b2257a4f4050b73d7a46f04d 5 | 10ed2c6e30d5ea7982590f6424e161386bfc444d 6 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | Before opening a new issue, please double check the past issues (both open and 2 | closed ones) to see if your problem has been discussed before and already 3 | contains an answer/solution. Likewise, check the FAQ in the Documentation folder 4 | for some common things - 5 | https://github.com/apple/swift-protobuf/blob/main/Documentation/FAQ.md 6 | 7 | 8 | Please be sure to include: 9 | 10 | * what OS you are developing on (Linux or macOS, including the version) 11 | 12 | * for macOS, what version of Xcode you are using (`xcodebuild -version`), 13 | for Linux, what version of Swift (`swift --version`) 14 | 15 | * what version of Swift is your code set to compile with (i.e. from project 16 | settings, etc.) 17 | 18 | * what branch/tag of SwiftProtobuf you are using (1.0.0, etc.) 19 | 20 | * if you are getting compile errors, please be sure include all errors/warnings, 21 | sometimes the error before the one you are stuck on is important. 22 | 23 | * lastly, if it all possible, provide a snippet of `.proto` and/or source 24 | that shows the problem. 25 | 26 | Thank you! 27 | -------------------------------------------------------------------------------- /.github/release.yml: -------------------------------------------------------------------------------- 1 | changelog: 2 | categories: 3 | - title: SemVer Major 4 | labels: 5 | - ⚠️ semver/major 6 | - title: SemVer Minor 7 | labels: 8 | - 🆕 semver/minor 9 | - title: SemVer Patch 10 | labels: 11 | - 🔨 semver/patch 12 | - title: Other Changes 13 | labels: 14 | - semver/none 15 | -------------------------------------------------------------------------------- /.github/workflows/check_upstream_protos.yml: -------------------------------------------------------------------------------- 1 | name: Check Upstream Proto Files 2 | 3 | on: 4 | schedule: 5 | # Every Sunday at 4am. 6 | - cron: '0 4 * * 0' 7 | # Also allow manual triggering from the github UX to revalidate things. 8 | workflow_dispatch: 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v4 16 | with: 17 | path: swift-protobuf 18 | - name: Checkout protobufbuffers/protobuf 19 | uses: actions/checkout@v4 20 | with: 21 | repository: protocolbuffers/protobuf 22 | path: protobuf 23 | - name: Check Upstream Proto Files 24 | working-directory: swift-protobuf 25 | run: make check-proto-files 26 | -------------------------------------------------------------------------------- /.github/workflows/pull_request_label.yml: -------------------------------------------------------------------------------- 1 | name: PR label 2 | 3 | on: 4 | pull_request: 5 | types: [labeled, unlabeled, opened, reopened, synchronize] 6 | 7 | jobs: 8 | semver-label-check: 9 | name: Semantic version label check 10 | runs-on: ubuntu-latest 11 | timeout-minutes: 1 12 | steps: 13 | - name: Checkout repository 14 | uses: actions/checkout@v4 15 | with: 16 | persist-credentials: false 17 | - name: Check for Semantic Version label 18 | uses: apple/swift-nio/.github/actions/pull_request_semver_label_checker@main 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /.swiftpm 4 | /Packages 5 | *~ 6 | xcuserdata 7 | xcbaselines 8 | /_test 9 | /docs 10 | /build 11 | mined_words.txt 12 | /CompileTests/MultiModule/.build 13 | /CompileTests/MultiModule/.swiftpm 14 | /CompileTests/InternalImportsByDefault/.build 15 | /CompileTests/InternalImportsByDefault/.swiftpm 16 | /*DescriptorTestData.bin 17 | /Package.resolved 18 | /PluginLibEditionDefaults.bin 19 | /PluginLibTestingEditionDefaults.bin 20 | 21 | # Intermediate conformance test outputs 22 | failing_tests.txt 23 | nonexistent_tests.txt 24 | succeeding_tests.txt 25 | 26 | PluginExamples/.build 27 | PluginExamples/.swiftpm/ 28 | -------------------------------------------------------------------------------- /.jazzy.yaml: -------------------------------------------------------------------------------- 1 | documentation: "Documentation/{API,GENERATED_CODE,PLUGIN}.md" 2 | -------------------------------------------------------------------------------- /.spi.yml: -------------------------------------------------------------------------------- 1 | version: 1 2 | builder: 3 | configs: 4 | - platform: ios 5 | documentation_targets: [SwiftProtobuf] 6 | scheme: SwiftProtobuf 7 | - platform: tvos 8 | scheme: SwiftProtobuf 9 | - platform: watchos 10 | scheme: SwiftProtobuf 11 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | project(protobuf 3 | LANGUAGES Swift) 4 | 5 | list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules) 6 | 7 | set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift) 8 | 9 | include(SwiftSupport) 10 | 11 | add_subdirectory(Sources) 12 | -------------------------------------------------------------------------------- /CompileTests/InternalImportsByDefault/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 6.0 2 | 3 | // Package.swift 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See LICENSE.txt for license information: 9 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 10 | 11 | import PackageDescription 12 | 13 | let package = Package( 14 | name: "CompileTests", 15 | dependencies: [ 16 | .package(path: "../..") 17 | ], 18 | targets: [ 19 | .executableTarget( 20 | name: "InternalImportsByDefault", 21 | dependencies: [ 22 | .product(name: "SwiftProtobuf", package: "swift-protobuf") 23 | ], 24 | exclude: [ 25 | "Protos/SomeProtoWithBytes.proto", 26 | "Protos/ServiceOnly.proto", 27 | ], 28 | swiftSettings: [ 29 | .enableExperimentalFeature("InternalImportsByDefault"), 30 | .enableExperimentalFeature("AccessLevelOnImport"), 31 | // Enable warnings as errors so the build fails if warnings are 32 | // present in generated code. 33 | .unsafeFlags(["-warnings-as-errors"]), 34 | ], 35 | plugins: [ 36 | .plugin(name: "SwiftProtobufPlugin", package: "swift-protobuf") 37 | ] 38 | ) 39 | ], 40 | swiftLanguageModes: [.v6] 41 | ) 42 | -------------------------------------------------------------------------------- /CompileTests/InternalImportsByDefault/Package@swift-5.10.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 5.10 2 | 3 | // Package.swift 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See LICENSE.txt for license information: 9 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 10 | 11 | import PackageDescription 12 | 13 | let package = Package( 14 | name: "CompileTests", 15 | dependencies: [ 16 | .package(path: "../..") 17 | ], 18 | targets: [ 19 | .executableTarget( 20 | name: "InternalImportsByDefault", 21 | dependencies: [ 22 | .product(name: "SwiftProtobuf", package: "swift-protobuf") 23 | ], 24 | exclude: [ 25 | "Protos/SomeProtoWithBytes.proto", 26 | "Protos/ServiceOnly.proto", 27 | ], 28 | swiftSettings: [ 29 | .enableExperimentalFeature("InternalImportsByDefault"), 30 | .enableExperimentalFeature("AccessLevelOnImport"), 31 | // Enable warnings as errors so the build fails if warnings are 32 | // present in generated code. 33 | .unsafeFlags(["-warnings-as-errors"]), 34 | ], 35 | plugins: [ 36 | .plugin(name: "SwiftProtobufPlugin", package: "swift-protobuf") 37 | ] 38 | ) 39 | ] 40 | ) 41 | -------------------------------------------------------------------------------- /CompileTests/InternalImportsByDefault/README.md: -------------------------------------------------------------------------------- 1 | # CompileTests/InternalImportsByDefault 2 | 3 | This is a test case that ensures that generated code builds correctly when 4 | `InternalImportsByDefault` is enabled and the code is generated with public 5 | visibility. 6 | 7 | When support for access level modifiers on imports was first added, an issue 8 | was encountered where publicly-generated protos would generate build errors and 9 | warnings when `InternalImportsByDefault` was enabled, as some dependencies were 10 | imported without an explicit access level modifier (i.e. `Foundation`), and some 11 | where sometimes imported as `public` without actually being used in the 12 | generated code at all (i.e. `Foundation` and `SwiftProtobuf`). 13 | -------------------------------------------------------------------------------- /CompileTests/InternalImportsByDefault/Sources/InternalImportsByDefault/Protos/ServiceOnly.proto: -------------------------------------------------------------------------------- 1 | // This proto file should generate an empty file, since the plugin will ignore 2 | // service definitions. 3 | // This is here to make sure we don't import Foundation or SwiftProtobuf when 4 | // it's not necessary. 5 | 6 | service SomeService { 7 | } 8 | -------------------------------------------------------------------------------- /CompileTests/InternalImportsByDefault/Sources/InternalImportsByDefault/Protos/SomeProtoWithBytes.proto: -------------------------------------------------------------------------------- 1 | // This proto will generate a Swift file that imports Foundation, because it 2 | // defines a bytes field. 3 | // Because InternalImportsByDefault is enabled on this module and we generate 4 | // protos with public visibility, the build will fail if the access level 5 | // modifier is missing (or wrong) since it will default the import to `internal` 6 | // and cause a conflict of access levels, since the `someBytes` property defined 7 | // on the message will be public. 8 | 9 | message SomeProtoWithBytes { 10 | optional bytes someBytes = 2; 11 | optional string ext_str = 100; 12 | } 13 | -------------------------------------------------------------------------------- /CompileTests/InternalImportsByDefault/Sources/InternalImportsByDefault/main.swift: -------------------------------------------------------------------------------- 1 | // main.swift 2 | // 3 | // Copyright (c) 2024 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | 9 | private import Foundation 10 | 11 | struct InternalImportsByDefault { 12 | static func main() { 13 | let protoWithBytes = SomeProtoWithBytes.with { proto in 14 | proto.someBytes = Data() 15 | proto.extStr = "" 16 | } 17 | blackhole(protoWithBytes) 18 | } 19 | } 20 | 21 | @inline(never) 22 | func blackhole(_: T) {} 23 | -------------------------------------------------------------------------------- /CompileTests/InternalImportsByDefault/Sources/InternalImportsByDefault/swift-protobuf-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "invocations": [ 3 | { 4 | "protoFiles": [ 5 | "Protos/SomeProtoWithBytes.proto", 6 | "Protos/ServiceOnly.proto", 7 | ], 8 | "visibility": "public", 9 | "useAccessLevelOnImports": true 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /CompileTests/MultiModule/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 6.0 2 | 3 | import PackageDescription 4 | 5 | let package = Package( 6 | name: "CompileTests", 7 | dependencies: [ 8 | .package(name: "swift-protobuf", path: "../..") 9 | ], 10 | targets: [ 11 | .testTarget( 12 | name: "Test1", 13 | dependencies: ["ImportsAPublicly"] 14 | ), 15 | .testTarget( 16 | name: "Test2", 17 | dependencies: ["ImportsImportsAPublicly"] 18 | ), 19 | .target( 20 | name: "ModuleA", 21 | dependencies: [ 22 | .product(name: "SwiftProtobuf", package: "swift-protobuf") 23 | ] 24 | ), 25 | .target( 26 | name: "ImportsAPublicly", 27 | dependencies: [ 28 | .product(name: "SwiftProtobuf", package: "swift-protobuf"), 29 | .target(name: "ModuleA"), 30 | ] 31 | ), 32 | .target( 33 | name: "ImportsImportsAPublicly", 34 | dependencies: [ 35 | .product(name: "SwiftProtobuf", package: "swift-protobuf"), 36 | .target(name: "ImportsAPublicly"), 37 | ] 38 | ), 39 | ], 40 | swiftLanguageModes: [.v6] 41 | ) 42 | -------------------------------------------------------------------------------- /CompileTests/MultiModule/Package@swift-5.10.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 5.10 2 | 3 | import PackageDescription 4 | 5 | let package = Package( 6 | name: "CompileTests", 7 | dependencies: [ 8 | .package(name: "swift-protobuf", path: "../..") 9 | ], 10 | targets: [ 11 | .testTarget( 12 | name: "Test1", 13 | dependencies: ["ImportsAPublicly"] 14 | ), 15 | .testTarget( 16 | name: "Test2", 17 | dependencies: ["ImportsImportsAPublicly"] 18 | ), 19 | .target( 20 | name: "ModuleA", 21 | dependencies: [ 22 | .product(name: "SwiftProtobuf", package: "swift-protobuf") 23 | ] 24 | ), 25 | .target( 26 | name: "ImportsAPublicly", 27 | dependencies: [ 28 | .product(name: "SwiftProtobuf", package: "swift-protobuf"), 29 | .target(name: "ModuleA"), 30 | ] 31 | ), 32 | .target( 33 | name: "ImportsImportsAPublicly", 34 | dependencies: [ 35 | .product(name: "SwiftProtobuf", package: "swift-protobuf"), 36 | .target(name: "ImportsAPublicly"), 37 | ] 38 | ), 39 | ] 40 | ) 41 | -------------------------------------------------------------------------------- /CompileTests/MultiModule/README.md: -------------------------------------------------------------------------------- 1 | # CompileTests/MultiModule 2 | 3 | This is a test case that uses sources generated into multiple modules and 4 | ensures the generated code compiles with the cross modules references. 5 | 6 | This can't use the SwiftPM Plugin as that currently doesn't have support for the 7 | module mappings. 8 | -------------------------------------------------------------------------------- /CompileTests/MultiModule/Sources/ReExportAOnly/reexport_a_only.pb.swift: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. 2 | // swift-format-ignore-file 3 | // swiftlint:disable all 4 | // 5 | // Generated by the Swift generator plugin for the protocol buffer compiler. 6 | // Source: Sources/ReExportAOnly/reexport_a_only.proto 7 | // 8 | // For information on using the generated types, please see the documentation: 9 | // https://github.com/apple/swift-protobuf/ 10 | 11 | // Use of 'import public' causes re-exports: 12 | @_exported import enum ModuleA.E 13 | @_exported import let ModuleA.Extensions_ext_str 14 | @_exported import struct ModuleA.A 15 | 16 | // This file contained no messages, enums, or extensions. 17 | -------------------------------------------------------------------------------- /CompileTests/MultiModule/Tests/Test1/test1.swift: -------------------------------------------------------------------------------- 1 | import ImportsAPublicly 2 | import XCTest 3 | 4 | // Don't need to import ModuleA because of the file being a `import public` 5 | 6 | final class ExampleTests: XCTestCase { 7 | func testA() { 8 | let anA = A.with { $0.e = .a } 9 | XCTAssertEqual(anA.e, .a) 10 | } 11 | 12 | func testImportsAPublicly() { 13 | let imports = ImportsAPublicly.with { $0.a.e = .a } 14 | XCTAssertEqual(imports.a.e, .a) 15 | } 16 | 17 | func testInterop() { 18 | let anA = A.with { $0.e = .b } 19 | let imports = ImportsAPublicly.with { 20 | $0.a = anA 21 | $0.e = .b 22 | } 23 | XCTAssertEqual(imports.a.e, imports.e) 24 | let transitively = UsesATransitively.with { 25 | $0.a = anA 26 | $0.e = imports.e 27 | } 28 | XCTAssertEqual(transitively.a, anA) 29 | XCTAssertEqual(transitively.e, imports.e) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CompileTests/MultiModule/Tests/Test2/test2.swift: -------------------------------------------------------------------------------- 1 | import ImportsImportsAPublicly 2 | import XCTest 3 | 4 | // Don't need to import ModuleA because of the file being a `import public` 5 | 6 | final class ExampleTests: XCTestCase { 7 | func testA() { 8 | let anA = A.with { $0.e = .a } 9 | XCTAssertEqual(anA.e, .a) 10 | } 11 | 12 | func testImportsImportsAPublicly() { 13 | let imports = ImportsImportsAPublicly.with { $0.a.e = .a } 14 | XCTAssertEqual(imports.a.e, .a) 15 | } 16 | 17 | func testInterop() { 18 | let anA = A.with { $0.e = .b } 19 | let imports = ImportsImportsAPublicly.with { 20 | $0.a = anA 21 | $0.e = .b 22 | } 23 | XCTAssertEqual(imports.a.e, imports.e) 24 | let transitively = UsesATransitively2.with { 25 | $0.a = anA 26 | $0.e = imports.e 27 | } 28 | XCTAssertEqual(transitively.a, anA) 29 | XCTAssertEqual(transitively.e, imports.e) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /DevTools/CopyrightFixup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -eu 4 | 5 | readonly DevToolsDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")") 6 | readonly RootDir="${DevToolsDir}/.." 7 | 8 | cd "${RootDir}" 9 | 10 | for f in `find . -name '*.swift' -o -name '*.cc' | sed -e 's|./||' | grep -v '.pb.swift'`; do 11 | if head -n 4 $f | grep 'DO NOT EDIT' > /dev/null; then 12 | # If the first lines contain 'DO NOT EDIT', then 13 | # this is a generated file and we should not 14 | # try to check or edit the copyright message. 15 | # But: print the filename; all such files should be .pb.swift 16 | # files that we're not even looking at here. 17 | echo "DO NOT EDIT: $f" 18 | else 19 | tmp=$f~ 20 | mv $f $tmp 21 | if head -n 10 $tmp | grep 'Copyright.*Apple' > /dev/null; then 22 | # This has a copyright message, update it 23 | # Edit the first line to have the correct filename 24 | head -n 1 $tmp | sed "s|// [^-]* - \(.*\)|// $f - \1|" >$f 25 | # Followed by the current copyright text: 26 | cat <>$f 27 | // 28 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 29 | // Licensed under Apache License v2.0 with Runtime Library Exception 30 | // 31 | // See LICENSE.txt for license information: 32 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 33 | EOF 34 | # Followed by the body of the file 35 | # The copyright message ends at the first blank comment line after 36 | # the first line containing "LICENSE.txt": 37 | cat $tmp | sed -n '/LICENSE.txt/,$ p' | sed -n '/^\/\/$/,$ p' >> $f 38 | rm $tmp 39 | else 40 | # This does not have a copyright message, insert one 41 | echo "Inserting copyright >> $f" 42 | cat <>$f 43 | // $f - description 44 | // 45 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 46 | // Licensed under Apache License v2.0 with Runtime Library Exception 47 | // 48 | // See LICENSE.txt for license information: 49 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 50 | // 51 | 52 | EOF 53 | cat $tmp >> $f 54 | fi 55 | fi 56 | done 57 | -------------------------------------------------------------------------------- /FuzzTesting/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /.swiftpm 4 | /Packages 5 | /*.xcodeproj 6 | xcuserdata/ 7 | /crash-* 8 | -------------------------------------------------------------------------------- /FuzzTesting/FailCases/Binary-packed-float-double-growth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/FuzzTesting/FailCases/Binary-packed-float-double-growth -------------------------------------------------------------------------------- /FuzzTesting/FailCases/JSON-Any: -------------------------------------------------------------------------------- 1 | {"wktAny":{"ny":{ -------------------------------------------------------------------------------- /FuzzTesting/FailCases/JSON-malformed-utf8: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/FuzzTesting/FailCases/JSON-malformed-utf8 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/TextFormat-ending-minus: -------------------------------------------------------------------------------- 1 | 1:0 1:0 5:- -------------------------------------------------------------------------------- /FuzzTesting/FailCases/TextFormat-ending-zero: -------------------------------------------------------------------------------- 1 | 1:0 1:0 1:0 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/TextFormat-map-loops-forever: -------------------------------------------------------------------------------- 1 | 104< -------------------------------------------------------------------------------- /FuzzTesting/FailCases/TextFormat-map-loops-forever2: -------------------------------------------------------------------------------- 1 | 104{ -------------------------------------------------------------------------------- /FuzzTesting/FailCases/TextFormat-octal-out-of-range: -------------------------------------------------------------------------------- 1 | 44:'2\50191<1:' -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-FuzzTextFormat_release-4619956026146816: -------------------------------------------------------------------------------- 1 | rsingular_sint64:- -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzAsyncMessageSequence_debug-5217919734513664: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzAsyncMessageSequence_debug-5217919734513664 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzBinaryDelimited_debug-4802082831204352: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzBinaryDelimited_debug-4802082831204352 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzBinaryDelimited_debug-5927982738046976: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzBinaryDelimited_debug-5927982738046976 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzBinaryDelimited_release-5166893326794752: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzBinaryDelimited_release-5166893326794752 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzBinary_release-5649532441460736: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzBinary_release-5649532441460736 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzJSON_debug-4506617283477504: -------------------------------------------------------------------------------- 1 | {"[fuzz.testing.singular_bytes_ext]":null -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzJSON_debug-5207244346621952: -------------------------------------------------------------------------------- 1 | {"wktTimestamp":"3560-10-10T00:00:00.0"mapSfixed64Fixed64":0 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzJSON_debug-5491136978878464: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzJSON_debug-5491136978878464 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzJSON_debug-6286338012282880: -------------------------------------------------------------------------------- 1 | {"wktTimestamp":"9999-12-31T23:59:60Z"} -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzJSON_release-4623064839618560: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzJSON_release-4623064839618560 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzJSON_release-4827369236463616: -------------------------------------------------------------------------------- 1 | {"wktFieldMask":"{H̱ܻ̻ܻ̻ܶܶAܻD"} -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzJSON_release-4929034878844928: -------------------------------------------------------------------------------- 1 | {"wktAny": {}} -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzJSON_release-5689942715006976: -------------------------------------------------------------------------------- 1 | {"[fuzz.testing.singular_enum_ext]":null -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzTextFormat_debug-5687602305433600: -------------------------------------------------------------------------------- 1 | 79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{49{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{49{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}49{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}49{79{79{79{79{79{79{79{79{79{79{79{79{79{79{79{}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}#49{79{79{7}{7 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzTextFormat_debug-5700784104275968: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzTextFormat_debug-5700784104275968 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzTextFormat_release-4519429842010112: -------------------------------------------------------------------------------- 1 | 40#BB#4: 2 | : 3 | [0 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzTextFormat_release-4619956026146816: -------------------------------------------------------------------------------- 1 |  l :- -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzTextFormat_release-4769249378304000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzTextFormat_release-4769249378304000 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzTextFormat_release-5109315292233728: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzTextFormat_release-5109315292233728 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzTextFormat_release-5836572361621504: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/FuzzTesting/FailCases/clusterfuzz-testcase-minimized-FuzzTextFormat_release-5836572361621504 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-swift-protobuf-fuzz-4649469707681792: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/FuzzTesting/FailCases/clusterfuzz-testcase-minimized-swift-protobuf-fuzz-4649469707681792 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-swift-protobuf-fuzz-4901281945747456: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/FuzzTesting/FailCases/clusterfuzz-testcase-minimized-swift-protobuf-fuzz-4901281945747456 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/clusterfuzz-testcase-minimized-swift-protobuf-fuzz-5029515526012928: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/FuzzTesting/FailCases/clusterfuzz-testcase-minimized-swift-protobuf-fuzz-5029515526012928 -------------------------------------------------------------------------------- /FuzzTesting/FailCases/oom-fb8c6ebb36a5ad53472bc2c006de6e7c6e2d10e3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/FuzzTesting/FailCases/oom-fb8c6ebb36a5ad53472bc2c006de6e7c6e2d10e3 -------------------------------------------------------------------------------- /FuzzTesting/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.3 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | // **NOTE**: 5.3 due to https://github.com/swiftlang/swift/issues/75800 4 | 5 | import PackageDescription 6 | 7 | let package = Package( 8 | name: "FuzzTesting", 9 | platforms: [ 10 | .macOS(.v10_15) 11 | ], 12 | dependencies: [ 13 | .package(name: "SwiftProtobuf", path: "..") 14 | ], 15 | targets: [ 16 | .target( 17 | name: "FuzzCommon", 18 | dependencies: ["SwiftProtobuf"] 19 | ), 20 | .target( 21 | name: "FuzzBinary", 22 | dependencies: ["SwiftProtobuf", "FuzzCommon"] 23 | ), 24 | .target( 25 | name: "FuzzBinaryDelimited", 26 | dependencies: ["SwiftProtobuf", "FuzzCommon"] 27 | ), 28 | .target( 29 | name: "FuzzAsyncMessageSequence", 30 | dependencies: ["SwiftProtobuf", "FuzzCommon"] 31 | ), 32 | .target( 33 | name: "FuzzJSON", 34 | dependencies: ["SwiftProtobuf", "FuzzCommon"] 35 | ), 36 | .target( 37 | name: "FuzzTextFormat", 38 | dependencies: ["SwiftProtobuf", "FuzzCommon"] 39 | ), 40 | .testTarget( 41 | name: "FuzzCommonTests", 42 | dependencies: ["FuzzCommon"] 43 | ), 44 | ] 45 | ) 46 | -------------------------------------------------------------------------------- /FuzzTesting/README.md: -------------------------------------------------------------------------------- 1 | # FuzzTesting 2 | 3 | This subpackage build binaries to be use with Fuzz testing. 4 | 5 | NOTE: The Swift toolchain distributed with Xcode do not include the fuzzing 6 | support, so for macOS, one needs to install the swift.org toolchain and use that 7 | instead. 8 | 9 | To build on macOS: 10 | 11 | ``` 12 | xcrun \ 13 | --toolchain swift \ 14 | swift build -c debug -Xswiftc -sanitize=fuzzer,address -Xswiftc -parse-as-library 15 | ``` 16 | 17 | To build on linux: 18 | 19 | ``` 20 | swift build -c debug -Xswiftc -sanitize=fuzzer,address -Xswiftc -parse-as-library 21 | ``` 22 | 23 | Then the binaries will be found in `.build/debug`. 24 | 25 | Note: You can also use `-c release` to build/test in release instead as that 26 | could find different issues. 27 | 28 | In this directory you will also find a `do_build.sh` script. By default it 29 | builds for both _debug_ and _release_. You can also pass `--run-regressions` to 30 | have it run the the build against the previous failcases to check for 31 | regressions. 32 | 33 | When issues are found: 34 | 35 | 1. Make sure you add a file to `FailCases` subdirectory so regressions can 36 | easily be watched for. The GitHub workflow runs against there. 37 | 38 | 2. Consider adding them to `Tests/SwiftProtobufTests/Test_FuzzTests.swift`, this 39 | help in debugging while working on the failure, but also provides yet another way 40 | to ensure things don't regress and if they do, it is much easier to immediately 41 | debug the issue. 42 | 43 | A note about memory issues, the address sanitizer is enabled in the fuzz tests 44 | and in that context can find different things that what are found running the 45 | unittests with the address sanitizer. So having test cases in both places can be 46 | needed to help ensure something is less likely to regress. 47 | 48 | There are dictionaries to help steer the fuzzing of JSON and TextFormat, to run 49 | with them, just add `-dict=FuzzJSON.dict` or `-dict=FuzzTextFormat.dict` to the 50 | invocation of the fuzz binary. 51 | -------------------------------------------------------------------------------- /FuzzTesting/Sources/FuzzBinary/main.swift: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2024 Apple Inc. and the project authors 2 | // Licensed under Apache License v2.0 with Runtime Library Exception 3 | // 4 | // See LICENSE.txt for license information: 5 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 6 | // 7 | // ----------------------------------------------------------------------------- 8 | 9 | import FuzzCommon 10 | import SwiftProtobuf 11 | 12 | @_cdecl("LLVMFuzzerTestOneInput") 13 | public func FuzzBinary(_ start: UnsafeRawPointer, _ count: Int) -> CInt { 14 | guard let (options, bytes) = BinaryDecodingOptions.extractOptions(start, count) else { 15 | return 1 16 | } 17 | var msg: SwiftProtoTesting_Fuzz_Message? 18 | do { 19 | msg = try SwiftProtoTesting_Fuzz_Message( 20 | serializedBytes: Array(bytes), 21 | extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions, 22 | options: options 23 | ) 24 | } catch { 25 | // Error parsing are to be expected since not all input will be well formed. 26 | } 27 | // Test serialization for completeness. 28 | // If a message was parsed, it should not fail to serialize, so assert as such. 29 | let _: [UInt8]? = try! msg?.serializedBytes() 30 | 31 | return 0 32 | } 33 | -------------------------------------------------------------------------------- /FuzzTesting/Sources/FuzzBinaryDelimited/main.swift: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2024 Apple Inc. and the project authors 2 | // Licensed under Apache License v2.0 with Runtime Library Exception 3 | // 4 | // See LICENSE.txt for license information: 5 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 6 | // 7 | // ----------------------------------------------------------------------------- 8 | 9 | import Foundation 10 | import FuzzCommon 11 | import SwiftProtobuf 12 | 13 | @_cdecl("LLVMFuzzerTestOneInput") 14 | public func FuzzDelimited(_ start: UnsafeRawPointer, _ count: Int) -> CInt { 15 | // No decoding options here, a leading zero is actually valid (zero length message), 16 | // so we rely on the other Binary fuzz tester to test options, and just let this 17 | // one focus on issue around framing of the messages on the stream. 18 | let bytes = UnsafeRawBufferPointer(start: start, count: count) 19 | let istream = InputStream(data: Data(bytes)) 20 | istream.open() 21 | while true { 22 | let msg: SwiftProtoTesting_Fuzz_Message? 23 | do { 24 | msg = try BinaryDelimited.parse( 25 | messageType: SwiftProtoTesting_Fuzz_Message.self, 26 | from: istream, 27 | extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions 28 | ) 29 | } catch { 30 | // Error parsing are to be expected since not all input will be well formed. 31 | break 32 | } 33 | // Test serialization for completeness. 34 | // If a message was parsed, it should not fail to serialize, so assert as such. 35 | if let msg = msg { 36 | // Could use one stream for all messages, but since fuzz tests have 37 | // memory limits, attempt to avoid hitting that limit with a new stream 38 | // for each output attempt. 39 | let ostream = OutputStream.toMemory() 40 | ostream.open() 41 | try! BinaryDelimited.serialize(message: msg, to: ostream) 42 | } 43 | } 44 | 45 | return 0 46 | } 47 | -------------------------------------------------------------------------------- /FuzzTesting/Sources/FuzzJSON/main.swift: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2024 Apple Inc. and the project authors 2 | // Licensed under Apache License v2.0 with Runtime Library Exception 3 | // 4 | // See LICENSE.txt for license information: 5 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 6 | // 7 | // ----------------------------------------------------------------------------- 8 | 9 | import Foundation 10 | import FuzzCommon 11 | import SwiftProtobuf 12 | 13 | @_cdecl("LLVMFuzzerTestOneInput") 14 | public func FuzzJSON(_ start: UnsafeRawPointer, _ count: Int) -> CInt { 15 | guard let (options, bytes) = JSONDecodingOptions.extractOptions(start, count) else { 16 | return 1 17 | } 18 | var msg: SwiftProtoTesting_Fuzz_Message? 19 | do { 20 | msg = try SwiftProtoTesting_Fuzz_Message( 21 | jsonUTF8Data: Data(bytes), 22 | extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions, 23 | options: options 24 | ) 25 | } catch { 26 | // Error parsing are to be expected since not all input will be well formed. 27 | } 28 | // Test serialization for completeness. 29 | // If a message was parsed, it should not fail to serialize, so assert as such. 30 | let _ = try! msg?.jsonString() 31 | return 0 32 | } 33 | -------------------------------------------------------------------------------- /FuzzTesting/Sources/FuzzTextFormat/main.swift: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2024 Apple Inc. and the project authors 2 | // Licensed under Apache License v2.0 with Runtime Library Exception 3 | // 4 | // See LICENSE.txt for license information: 5 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 6 | // 7 | // ----------------------------------------------------------------------------- 8 | 9 | import Foundation 10 | import FuzzCommon 11 | import SwiftProtobuf 12 | 13 | @_cdecl("LLVMFuzzerTestOneInput") 14 | public func FuzzTextFormat(_ start: UnsafeRawPointer, _ count: Int) -> CInt { 15 | guard let (options, bytes) = TextFormatDecodingOptions.extractOptions(start, count) else { 16 | return 1 17 | } 18 | guard let str = String(data: Data(bytes), encoding: .utf8) else { return 0 } 19 | var msg: SwiftProtoTesting_Fuzz_Message? 20 | do { 21 | msg = try SwiftProtoTesting_Fuzz_Message( 22 | textFormatString: str, 23 | options: options, 24 | extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions 25 | ) 26 | } catch { 27 | // Error parsing are to be expected since not all input will be well formed. 28 | } 29 | // Test serialization for completeness. 30 | let _ = msg?.textFormatString() 31 | 32 | return 0 33 | } 34 | -------------------------------------------------------------------------------- /Performance/.gitignore: -------------------------------------------------------------------------------- 1 | _generated/ 2 | _results/ 3 | -------------------------------------------------------------------------------- /Performance/Harness.cc: -------------------------------------------------------------------------------- 1 | // Performance/Harness.cc - C++ performance harness definition 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Defines the class that runs the performance tests. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "Harness.h" 24 | 25 | using std::chrono::duration_cast; 26 | using std::chrono::steady_clock; 27 | using std::endl; 28 | using std::function; 29 | using std::ostream; 30 | using std::result_of; 31 | using std::sqrt; 32 | using std::string; 33 | using std::vector; 34 | 35 | Harness::Harness(std::ostream* results_stream) : 36 | results_stream(results_stream), 37 | measurement_count(10), 38 | repeated_count(10) {} 39 | 40 | void Harness::write_to_log(const string& name, 41 | const vector& timings) const { 42 | if (results_stream == nullptr) { 43 | return; 44 | } 45 | 46 | (*results_stream) << "\"" << name << "\": ["; 47 | for (const auto& duration : timings) { 48 | auto micros = duration_cast(duration); 49 | (*results_stream) << micros.count() / run_count() << ", "; 50 | } 51 | (*results_stream) << "]," << endl; 52 | } 53 | 54 | Harness::Statistics Harness::compute_statistics( 55 | const vector& timings) const { 56 | microseconds_d::rep sum = 0; 57 | microseconds_d::rep sqsum = 0; 58 | 59 | for (const auto& duration : timings) { 60 | auto micros = duration_cast(duration); 61 | auto count = micros.count(); 62 | sum += count; 63 | sqsum += count * count; 64 | } 65 | 66 | auto n = timings.size(); 67 | Statistics stats; 68 | stats.mean = sum / n; 69 | stats.stddev = sqrt(sqsum / n - stats.mean * stats.mean); 70 | return stats; 71 | } 72 | -------------------------------------------------------------------------------- /Performance/Protobuf.tracetemplate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/swift-protobuf/afd9ddf43b7f72d39901958eff72e9f7ec6778fa/Performance/Protobuf.tracetemplate -------------------------------------------------------------------------------- /Performance/css/harness-visualization.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 16px; 3 | } 4 | 5 | p.info-text { 6 | padding: 16px; 7 | } 8 | 9 | h3 > small { 10 | float: right; 11 | } 12 | 13 | table.numeric td { 14 | text-align: right; 15 | } 16 | 17 | table.numeric th { 18 | background-color: #eee; 19 | text-align: center; 20 | } 21 | 22 | table.numeric tfoot td { 23 | font-size: 12px; 24 | font-style: italic; 25 | } 26 | 27 | table.numeric td:first-child, 28 | table.numeric th:first-child { 29 | text-align: left; 30 | } 31 | -------------------------------------------------------------------------------- /Performance/harness-visualization.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Swift Protobuf Performance Harness Visualization 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |

Most recent sessions are listed first.

16 |
17 | 18 |
19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Performance/js/results.js.template: -------------------------------------------------------------------------------- 1 | sessions = [ 2 | //NEW-DATA-HERE 3 | ]; 4 | -------------------------------------------------------------------------------- /Performance/main.cc: -------------------------------------------------------------------------------- 1 | // Performance/main.cc - C++ performance harness entry point 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Entry point for the C++ performance harness. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | #include 16 | 17 | #include "Harness.h" 18 | 19 | using std::ios_base; 20 | using std::ofstream; 21 | 22 | int main(int argc, char **argv) { 23 | ofstream* results_stream = (argc > 1) ? 24 | new ofstream(argv[1], ios_base::app) : nullptr; 25 | 26 | Harness harness(results_stream); 27 | harness.run(); 28 | 29 | if (results_stream) { 30 | results_stream->close(); 31 | delete results_stream; 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Performance/main.swift: -------------------------------------------------------------------------------- 1 | // Performance/main.swift - Performance harness entry point 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Entry point that creates the performance harness and runs it. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | import Foundation 16 | 17 | let args = CommandLine.arguments 18 | let resultsFile = args.count > 1 ? FileHandle(forWritingAtPath: args[1]) : nil 19 | resultsFile?.seekToEndOfFile() 20 | 21 | let harness = Harness(resultsFile: resultsFile) 22 | harness.run() 23 | 24 | resultsFile?.closeFile() 25 | -------------------------------------------------------------------------------- /Performance/runners/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # cmake configuration file for building the C++ test harness 3 | # 4 | # This assumes you have a protobuf source checkout handy, 5 | # and have used `git submodule update` to obtain all the 6 | # related source repos. 7 | # 8 | # This script uses the protobuf sources to build libprotobuf and 9 | # statically links it into the test harness executable. 10 | # (This is probably not necessary; updates to this file to 11 | # use a better strategy would be appreciated.) 12 | # 13 | # Also assumes that you have abseil_cpp and googletest installed 14 | # locally via e.g., 15 | # brew install googletest 16 | # brew install abseil 17 | # 18 | 19 | cmake_minimum_required(VERSION 3.10...3.26) 20 | set(CMAKE_CXX_STANDARD 17) 21 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 22 | set(CMAKE_BUILD_TYPE RelWithDebInfo) 23 | 24 | project(swiftprotobuf-perf C CXX) 25 | 26 | # Update this with the appropriate path to the protobuf source 27 | # checkout, starting from the directory holding this file. 28 | # Default here assumes that `protobuf` is checked out beside 29 | # `swift-protobuf` 30 | set(protobuf_SOURCE_DIR ${CMAKE_SOURCE_DIR}/../../../protobuf) 31 | set(protobuf_VERSION "999.999") 32 | 33 | # Use protobuf cmake scripts to locate suitable abseil package: 34 | set(protobuf_ABSL_PROVIDER "package") 35 | include(${protobuf_SOURCE_DIR}/cmake/abseil-cpp.cmake) 36 | 37 | # Use protobuf cmake scripts for building libprotobuf 38 | include(${protobuf_SOURCE_DIR}/cmake/libprotobuf.cmake) 39 | 40 | # Use utf8_range from protobuf checkout 41 | set(utf8_range_SOURCE_DIR ${protobuf_SOURCE_DIR}/third_party/utf8_range) 42 | add_subdirectory(${utf8_range_SOURCE_DIR} third_party/utf8_range) 43 | 44 | include_directories( 45 | ${protobuf_SOURCE_DIR}/src 46 | ${utf8_range_SOURCE_DIR} 47 | ) 48 | 49 | add_executable(harness_cpp 50 | ../main.cc 51 | ../Harness.cc 52 | ../_generated/Harness+Generated.cc 53 | ../_generated/message.pb.cc 54 | ) 55 | 56 | target_include_directories(harness_cpp PRIVATE 57 | ${CMAKE_SOURCE_DIR} 58 | ${CMAKE_SOURCE_DIR}/.. 59 | ${ABSL_ROOT_DIR} 60 | ${utf8_range_SOURCE_DIR} 61 | ) 62 | 63 | target_link_libraries(harness_cpp PRIVATE libprotobuf) 64 | -------------------------------------------------------------------------------- /Performance/runners/cpp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # SwiftProtobuf/Performance/runners/cpp.sh - C++ test harness runner 4 | # 5 | # This source file is part of the Swift.org open source project 6 | # 7 | # Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors 8 | # Licensed under Apache License v2.0 with Runtime Library Exception 9 | # 10 | # See http://swift.org/LICENSE.txt for license information 11 | # See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 12 | # 13 | # ----------------------------------------------------------------------------- 14 | # 15 | # Functions for running the C++ harness. 16 | # 17 | # ----------------------------------------------------------------------------- 18 | 19 | function run_cpp_harness() { 20 | ( 21 | harness="$1" 22 | 23 | source "$script_dir/generators/cpp.sh" 24 | 25 | echo "Generating C++ harness source..." 26 | gen_harness_path="$script_dir/_generated/Harness+Generated.cc" 27 | generate_cpp_harness 28 | 29 | echo 30 | echo "Building C++ libprotobuf and performance test harness..." 31 | echo 32 | 33 | pushd $script_dir/runners 34 | cmake -B ../_generated -S . 35 | cmake --build ../_generated 36 | popd 37 | 38 | run_harness_and_concatenate_results "C++" "$harness" "$partial_results" 39 | echo 40 | ) 41 | } 42 | -------------------------------------------------------------------------------- /PluginExamples/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 6.0 2 | 3 | import PackageDescription 4 | 5 | let package = Package( 6 | name: "PluginExamples", 7 | dependencies: [ 8 | .package(path: "../") 9 | ], 10 | targets: [ 11 | .target( 12 | name: "Simple", 13 | dependencies: [ 14 | .product(name: "SwiftProtobuf", package: "swift-protobuf") 15 | ], 16 | plugins: [ 17 | .plugin(name: "SwiftProtobufPlugin", package: "swift-protobuf") 18 | ] 19 | ), 20 | .target( 21 | name: "Nested", 22 | dependencies: [ 23 | .product(name: "SwiftProtobuf", package: "swift-protobuf") 24 | ], 25 | plugins: [ 26 | .plugin(name: "SwiftProtobufPlugin", package: "swift-protobuf") 27 | ] 28 | ), 29 | .target( 30 | name: "Import", 31 | dependencies: [ 32 | .product(name: "SwiftProtobuf", package: "swift-protobuf") 33 | ], 34 | plugins: [ 35 | .plugin(name: "SwiftProtobufPlugin", package: "swift-protobuf") 36 | ] 37 | ), 38 | .target( 39 | name: "AccessLevelOnImport", 40 | dependencies: [ 41 | .product(name: "SwiftProtobuf", package: "swift-protobuf") 42 | ], 43 | swiftSettings: [ 44 | .enableExperimentalFeature("AccessLevelOnImport") 45 | ], 46 | plugins: [ 47 | .plugin(name: "SwiftProtobufPlugin", package: "swift-protobuf") 48 | ] 49 | ), 50 | .testTarget( 51 | name: "ExampleTests", 52 | dependencies: [ 53 | .target(name: "Simple"), 54 | .target(name: "Nested"), 55 | .target(name: "Import"), 56 | .target(name: "AccessLevelOnImport"), 57 | ] 58 | ), 59 | ], 60 | swiftLanguageModes: [.v6] 61 | ) 62 | -------------------------------------------------------------------------------- /PluginExamples/Package@swift-5.10.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 5.10 2 | 3 | import PackageDescription 4 | 5 | let package = Package( 6 | name: "PluginExamples", 7 | dependencies: [ 8 | .package(path: "../") 9 | ], 10 | targets: [ 11 | .target( 12 | name: "Simple", 13 | dependencies: [ 14 | .product(name: "SwiftProtobuf", package: "swift-protobuf") 15 | ], 16 | plugins: [ 17 | .plugin(name: "SwiftProtobufPlugin", package: "swift-protobuf") 18 | ] 19 | ), 20 | .target( 21 | name: "Nested", 22 | dependencies: [ 23 | .product(name: "SwiftProtobuf", package: "swift-protobuf") 24 | ], 25 | plugins: [ 26 | .plugin(name: "SwiftProtobufPlugin", package: "swift-protobuf") 27 | ] 28 | ), 29 | .target( 30 | name: "Import", 31 | dependencies: [ 32 | .product(name: "SwiftProtobuf", package: "swift-protobuf") 33 | ], 34 | plugins: [ 35 | .plugin(name: "SwiftProtobufPlugin", package: "swift-protobuf") 36 | ] 37 | ), 38 | .target( 39 | name: "AccessLevelOnImport", 40 | dependencies: [ 41 | .product(name: "SwiftProtobuf", package: "swift-protobuf") 42 | ], 43 | swiftSettings: [ 44 | .enableExperimentalFeature("AccessLevelOnImport") 45 | ], 46 | plugins: [ 47 | .plugin(name: "SwiftProtobufPlugin", package: "swift-protobuf") 48 | ] 49 | ), 50 | .testTarget( 51 | name: "ExampleTests", 52 | dependencies: [ 53 | .target(name: "Simple"), 54 | .target(name: "Nested"), 55 | .target(name: "Import"), 56 | .target(name: "AccessLevelOnImport"), 57 | ] 58 | ), 59 | ] 60 | ) 61 | -------------------------------------------------------------------------------- /PluginExamples/Sources/AccessLevelOnImport/AccessLevelOnImport/AccessLevelOnImport.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "Dependency/Dependency.proto"; 4 | 5 | message AccessLevelOnImport { 6 | Dependency dependency = 1; 7 | } 8 | -------------------------------------------------------------------------------- /PluginExamples/Sources/AccessLevelOnImport/Dependency/Dependency.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message Dependency { 4 | string name = 1; 5 | } 6 | -------------------------------------------------------------------------------- /PluginExamples/Sources/AccessLevelOnImport/empty.swift: -------------------------------------------------------------------------------- 1 | /// DO NOT DELETE. 2 | /// 3 | /// We need to keep this file otherwise the plugin is not running. 4 | -------------------------------------------------------------------------------- /PluginExamples/Sources/AccessLevelOnImport/swift-protobuf-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "invocations": [ 3 | { 4 | "protoFiles": [ 5 | "AccessLevelOnImport/AccessLevelOnImport.proto", 6 | "Dependency/Dependency.proto", 7 | ], 8 | "visibility": "public", 9 | "useAccessLevelOnImports": true 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /PluginExamples/Sources/ExampleTests/AccessLevelOnImportTests.swift: -------------------------------------------------------------------------------- 1 | import AccessLevelOnImport 2 | import XCTest 3 | 4 | final class AccessLevelOnImportTests: XCTestCase { 5 | func testAccessLevelOnImport() { 6 | let access = AccessLevelOnImport.with { $0.dependency = .with { $0.name = "Dependency" } } 7 | XCTAssertEqual(access.dependency.name, "Dependency") 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /PluginExamples/Sources/ExampleTests/ExampleTests.swift: -------------------------------------------------------------------------------- 1 | import Import 2 | import Nested 3 | import Simple 4 | import XCTest 5 | 6 | final class ExampleTests: XCTestCase { 7 | func testSimple() { 8 | let simple = Simple.with { $0.name = "Simple" } 9 | XCTAssertEqual(simple.name, "Simple") 10 | } 11 | 12 | func testNested() { 13 | let nested = Nested.with { $0.name = "Nested" } 14 | XCTAssertEqual(nested.name, "Nested") 15 | } 16 | 17 | func testImport() { 18 | let foo = Foo.with { $0.bar = .with { $0.name = "Bar" } } 19 | XCTAssertEqual(foo.bar.name, "Bar") 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /PluginExamples/Sources/Import/Bar/Bar.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message Bar { 4 | string name = 1; 5 | } 6 | -------------------------------------------------------------------------------- /PluginExamples/Sources/Import/Foo/Foo.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "Bar/Bar.proto"; 4 | 5 | message Foo { 6 | Bar bar = 1; 7 | } 8 | -------------------------------------------------------------------------------- /PluginExamples/Sources/Import/empty.swift: -------------------------------------------------------------------------------- 1 | /// DO NOT DELETE. 2 | /// 3 | /// We need to keep this file otherwise the plugin is not running. 4 | -------------------------------------------------------------------------------- /PluginExamples/Sources/Import/swift-protobuf-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "invocations": [ 3 | { 4 | "protoFiles": [ 5 | "Bar/Bar.proto", 6 | "Foo/Foo.proto", 7 | ], 8 | "visibility": "public" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /PluginExamples/Sources/Nested/Nested/Nested.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message Nested { 4 | string name = 1; 5 | Nested next = 2; 6 | } 7 | -------------------------------------------------------------------------------- /PluginExamples/Sources/Nested/empty.swift: -------------------------------------------------------------------------------- 1 | /// DO NOT DELETE. 2 | /// 3 | /// We need to keep this file otherwise the plugin is not running. 4 | -------------------------------------------------------------------------------- /PluginExamples/Sources/Nested/swift-protobuf-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "invocations": [ 3 | { 4 | "protoFiles": [ 5 | "Nested/Nested.proto", 6 | ], 7 | "visibility": "public" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /PluginExamples/Sources/Simple/Simple.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message Simple { 4 | string name = 1; 5 | } 6 | -------------------------------------------------------------------------------- /PluginExamples/Sources/Simple/empty.swift: -------------------------------------------------------------------------------- 1 | /// DO NOT DELETE. 2 | /// 3 | /// We need to keep this file otherwise the plugin is not running. 4 | -------------------------------------------------------------------------------- /PluginExamples/Sources/Simple/swift-protobuf-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "invocations": [ 3 | { 4 | "protoFiles": [ 5 | "Simple.proto", 6 | ], 7 | "visibility": "public" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /Protos/CompileTests/InternalImportsByDefault/ServiceOnly.proto: -------------------------------------------------------------------------------- 1 | // This proto file should generate an empty file, since the plugin will ignore 2 | // service definitions. 3 | // This is here to make sure we don't import Foundation or SwiftProtobuf when 4 | // it's not necessary. 5 | 6 | service SomeService { 7 | } 8 | -------------------------------------------------------------------------------- /Protos/CompileTests/InternalImportsByDefault/SomeProtoWithBytes.proto: -------------------------------------------------------------------------------- 1 | // This proto will generate a Swift file that imports Foundation, because it 2 | // defines a bytes field. 3 | // Because InternalImportsByDefault is enabled on this module and we generate 4 | // protos with public visibility, the build will fail if the access level 5 | // modifier is missing (or wrong) since it will default the import to `internal` 6 | // and cause a conflict of access levels, since the `someBytes` property defined 7 | // on the message will be public. 8 | 9 | message SomeProtoWithBytes { 10 | optional bytes someBytes = 2; 11 | optional string ext_str = 100; 12 | } 13 | -------------------------------------------------------------------------------- /Protos/CompileTests/MultiModule/Sources/ImportsAPublicly/imports_a_publicly.proto: -------------------------------------------------------------------------------- 1 | import public "Sources/ModuleA/a.proto"; 2 | 3 | message ImportsAPublicly { 4 | optional A a = 11; 5 | optional E e = 12; 6 | } 7 | -------------------------------------------------------------------------------- /Protos/CompileTests/MultiModule/Sources/ImportsImportsAPublicly/imports_imports_a_publicly.proto: -------------------------------------------------------------------------------- 1 | import public "Sources/ImportsAPublicly/imports_a_publicly.proto"; 2 | 3 | message ImportsImportsAPublicly { 4 | optional A a = 21; 5 | optional E e = 22; 6 | } 7 | -------------------------------------------------------------------------------- /Protos/CompileTests/MultiModule/Sources/ModuleA/a.proto: -------------------------------------------------------------------------------- 1 | enum E { 2 | E_UNSET = 0; 3 | E_A = 1; 4 | E_B = 2; 5 | } 6 | 7 | message A { 8 | optional E e = 1; 9 | extensions 100 to 1000; 10 | } 11 | 12 | extend A { 13 | optional string ext_str = 100; 14 | } 15 | -------------------------------------------------------------------------------- /Protos/CompileTests/MultiModule/Sources/ReExportAOnly/reexport_a_only.proto: -------------------------------------------------------------------------------- 1 | import public "Sources/ModuleA/a.proto"; 2 | -------------------------------------------------------------------------------- /Protos/CompileTests/MultiModule/Tests/Test1/uses_a_transitively.proto: -------------------------------------------------------------------------------- 1 | import "Sources/ImportsAPublicly/imports_a_publicly.proto"; 2 | 3 | message UsesATransitively { 4 | optional A a = 101; 5 | optional E e = 102; 6 | } 7 | -------------------------------------------------------------------------------- /Protos/CompileTests/MultiModule/Tests/Test2/uses_a_transitively2.proto: -------------------------------------------------------------------------------- 1 | import "Sources/ImportsImportsAPublicly/imports_imports_a_publicly.proto"; 2 | 3 | message UsesATransitively2 { 4 | optional A a = 111; 5 | optional E e = 122; 6 | } 7 | -------------------------------------------------------------------------------- /Protos/CompileTests/MultiModule/module_mappings.pbascii: -------------------------------------------------------------------------------- 1 | mapping { 2 | module_name: "ModuleA" 3 | proto_file_path: "Sources/ModuleA/a.proto" 4 | } 5 | mapping { 6 | module_name: "ImportsAPublicly" 7 | proto_file_path: "Sources/ImportsAPublicly/imports_a_publicly.proto" 8 | } 9 | mapping { 10 | module_name: "ImportsImportsAPublicly" 11 | proto_file_path: "Sources/ImportsImportsAPublicly/imports_imports_a_publicly.proto" 12 | } 13 | mapping { 14 | module_name: "ReExportAOnly" 15 | proto_file_path: "Sources/ReExportAOnly/reexport_a_only.proto" 16 | } 17 | -------------------------------------------------------------------------------- /Protos/README.md: -------------------------------------------------------------------------------- 1 | Various test protos that are used to stress the code generator. 2 | 3 | Many of these were copied from Google's protoc project with only minor changes, hence the Google copyright notices. 4 | 5 | Others were created specifically to test Apple's Swift generator. 6 | 7 | Some are used in various Test cases, but others serve as tests just by verifying that they compile. 8 | -------------------------------------------------------------------------------- /Protos/SwiftProtobufPluginLibrary/swift_protobuf_module_mappings.proto: -------------------------------------------------------------------------------- 1 | // Protos/SwiftProtobufPluginLibrary/swift_protobuf_module_mappings.proto - Swift Module mappings configuration 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See http://swift.org/LICENSE.txt for license information 9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | 12 | syntax = "proto3"; 13 | 14 | package swift_protobuf.gen_swift; 15 | 16 | // Configuration used to define the mappings for generated proto files 17 | // to the Swift module they will be included in. 18 | message ModuleMappings { 19 | 20 | // Individual listing of the module name and the files that will go 21 | // into it. 22 | message Entry { 23 | 24 | // The Swift module name that will be imported and used to scope all 25 | // the types from the given proto files. 26 | string module_name = 1; 27 | 28 | // The proto files that should be considered it this module. The values 29 | // should be the how they are expressed to the generated; i.e. - how they 30 | // are used in import states to be used from other files, so `my_file.proto` 31 | // or `path/to/file.proto`. 32 | repeated string proto_file_path = 2; 33 | } 34 | 35 | // The mappings. 36 | repeated Entry mapping = 1; 37 | } 38 | -------------------------------------------------------------------------------- /Protos/SwiftProtobufPluginLibraryTests/pluginlib_descriptor_delimited.proto: -------------------------------------------------------------------------------- 1 | // Protos/pluginlib_descriptor_test.proto - test proto 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See http://swift.org/LICENSE.txt for license information 9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | // ----------------------------------------------------------------------------- 12 | /// 13 | /// Test proto for Tests/SwiftProtobufPluginLibraryTests/Test_Descriptor.swift 14 | /// 15 | // ----------------------------------------------------------------------------- 16 | 17 | edition = "2023"; 18 | 19 | package swift_descriptor_test; 20 | 21 | option features.message_encoding = DELIMITED; 22 | 23 | message EditionsMessageForDelimited { 24 | int32 scalar_field = 1; 25 | map map_field = 2; 26 | map message_map_field = 3; 27 | EditionsMessageForDelimited delimited_field = 4; 28 | EditionsMessageForDelimited length_prefixed_field = 5 [ 29 | features.message_encoding = LENGTH_PREFIXED 30 | ]; 31 | } 32 | -------------------------------------------------------------------------------- /Protos/SwiftProtobufPluginLibraryTests/pluginlib_descriptor_test2.proto: -------------------------------------------------------------------------------- 1 | // Protos/pluginlib_descriptor_test.proto - test proto 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See http://swift.org/LICENSE.txt for license information 9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | // ----------------------------------------------------------------------------- 12 | /// 13 | /// Test proto for Tests/SwiftProtobufPluginLibraryTests/Test_Descriptor.swift 14 | /// 15 | // ----------------------------------------------------------------------------- 16 | 17 | syntax = "proto3"; 18 | 19 | package swift_descriptor_test; 20 | 21 | message Proto3MessageForPresence { 22 | 23 | enum SubEnum { 24 | SUB_VALUE_0 = 0; 25 | SUB_VALUE_1 = 1; 26 | SUB_VALUE_2 = 2; 27 | } 28 | 29 | string str_field = 1; 30 | int32 int32_field = 2; 31 | SubEnum enum_field = 3; 32 | OtherMessage message_field = 4; 33 | 34 | optional string opt_str_field = 11; 35 | optional int32 opt_int32_field = 12; 36 | optional SubEnum opt_enum_field = 13; 37 | optional OtherMessage opt_message_field = 14; 38 | 39 | repeated string repeat_str_field = 21; 40 | repeated int32 repeat_int32_field = 22; 41 | repeated SubEnum repeat_enum_field = 23; 42 | repeated OtherMessage repeat_message_field = 24; 43 | 44 | oneof o { 45 | string oneof_str_field = 31; 46 | int32 oneof_int32_field = 32; 47 | SubEnum oneof_enum_field = 33; 48 | OtherMessage oneof_message_field = 34; 49 | } 50 | 51 | } 52 | 53 | message OtherMessage { 54 | string field = 1; 55 | } 56 | -------------------------------------------------------------------------------- /Protos/SwiftProtobufPluginLibraryTests/pluginlib_descriptor_test_import.proto: -------------------------------------------------------------------------------- 1 | // Protos/SwiftProtobufPluginLibraryTests/pluginlib_descriptor_test_import.proto - test proto 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2024 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See http://swift.org/LICENSE.txt for license information 9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | // ----------------------------------------------------------------------------- 12 | /// 13 | /// Test proto for Tests/SwiftProtobufPluginLibraryTests/Test_Descriptor.swift 14 | /// 15 | // ----------------------------------------------------------------------------- 16 | 17 | syntax = "proto2"; 18 | 19 | package swift_descriptor_test.import; 20 | 21 | message Version { 22 | optional int32 major = 1; 23 | optional int32 minor = 2; 24 | optional int32 patch = 3; 25 | optional string suffix = 4; 26 | } 27 | 28 | message ExtendableOne { 29 | 30 | message ExtendableTwo { 31 | extensions 1000 to max; 32 | } 33 | 34 | optional ExtendableTwo sub_msg_field = 1; 35 | 36 | extensions 1000 to max; 37 | } 38 | -------------------------------------------------------------------------------- /Protos/SwiftProtobufPluginLibraryTests/unittest_delimited_import.proto: -------------------------------------------------------------------------------- 1 | edition = "2023"; 2 | 3 | package editions_unittest; 4 | 5 | message MessageImport { 6 | int32 a = 1; 7 | int32 b = 2; 8 | } 9 | -------------------------------------------------------------------------------- /Protos/SwiftProtobufTests/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 swift_proto_testing; 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 | string text = 4; 42 | } 43 | -------------------------------------------------------------------------------- /Protos/SwiftProtobufTests/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 swift_proto_testing.import; 36 | 37 | message PublicImportMessage { 38 | optional int32 e = 1; 39 | } 40 | -------------------------------------------------------------------------------- /Protos/SwiftProtobufTests/unittest_mset_wire_format.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 | 39 | package swift_proto_testing.wire_format; 40 | 41 | // A message with message_set_wire_format. 42 | message TestMessageSet { 43 | option message_set_wire_format = true; 44 | 45 | extensions 4 to max; 46 | } 47 | -------------------------------------------------------------------------------- /Protos/SwiftProtobufTests/unittest_swift_deprecated_file.proto: -------------------------------------------------------------------------------- 1 | // Protos/unittest_swift_deprecated_file.proto - test proto 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See http://swift.org/LICENSE.txt for license information 9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | // ----------------------------------------------------------------------------- 12 | /// 13 | /// Test generation support of deprecated attributes. 14 | /// 15 | // ----------------------------------------------------------------------------- 16 | 17 | syntax = "proto2"; 18 | 19 | package swift_proto_testing.deprecated_file; 20 | 21 | // The source generated from this file needs to be inspect to confirm it has all 22 | // of the expected comments. See 23 | // https://github.com/apple/swift-protobuf/issues/151 for why things currently 24 | // don't generate annotations. If/when that is resolved, this file should be 25 | // compiled also to confirm everything works as intended. 26 | 27 | option deprecated = true; 28 | 29 | // Message comment 30 | message MyMsg { 31 | extensions 100 to max; 32 | 33 | optional string string_field = 1; 34 | } 35 | 36 | // These fields will all catch the deprecation from the file. 37 | extend MyMsg { 38 | // Extension field comment 39 | optional string string_ext_field = 101; 40 | optional int32 int_ext_field = 102; 41 | repeated fixed32 fixed_ext_field = 103; 42 | optional MyMsg msg_ext_field = 104; 43 | } 44 | 45 | message MsgScope { 46 | // These extension fields (scoped within a message) will all catch the deprecation from the file. 47 | extend MyMsg { 48 | // Another extension field comment 49 | optional string string_ext2_field = 201; 50 | optional int32 int_ext2_field = 202; 51 | repeated fixed32 fixed_ext2_field = 203; 52 | optional MyMsg msg_ext2_field = 204; 53 | } 54 | } 55 | 56 | enum MyEnum { 57 | MYENUM_ONE = 1; 58 | MYENUM_TWO = 2; 59 | MYENUM_THREE = 3; 60 | } 61 | -------------------------------------------------------------------------------- /Protos/SwiftProtobufTests/unittest_swift_enum_optional_default.proto: -------------------------------------------------------------------------------- 1 | // Protos/unittest_swift_enum_optional_default.proto - test proto 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See http://swift.org/LICENSE.txt for license information 9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | // ----------------------------------------------------------------------------- 12 | /// 13 | /// Test handling of enum fields with specified defaults 14 | /// 15 | // ----------------------------------------------------------------------------- 16 | 17 | syntax = "proto2"; 18 | 19 | package swift_proto_testing.extend; 20 | 21 | message EnumOptionalDefault { 22 | message NestedMessage { 23 | enum Enum { 24 | FOO = 0; 25 | } 26 | 27 | // The circular reference here forces the generator to 28 | // implement heap-backed storage. 29 | optional NestedMessage message = 1; 30 | 31 | optional Enum optional_enum = 17 [default = FOO]; 32 | } 33 | 34 | message NestedMessage2 { 35 | enum Enum { 36 | FOO = 0; 37 | } 38 | optional Enum optional_enum = 17 [default = FOO]; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Protos/SwiftProtobufTests/unittest_swift_extension2.proto: -------------------------------------------------------------------------------- 1 | // Protos/unittest_swift_extension2.proto - test proto 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See http://swift.org/LICENSE.txt for license information 9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | // ----------------------------------------------------------------------------- 12 | /// 13 | /// Test naming of extensions that differ only in proto package. This is a 14 | /// clone of unittest_swift_extension3.proto, but with a different proto package 15 | /// and different extension numbers. 16 | /// 17 | // ----------------------------------------------------------------------------- 18 | 19 | syntax = "proto2"; 20 | 21 | package swift_proto_testing.extend2; 22 | 23 | import "unittest_swift_extension.proto"; 24 | 25 | message MyMessage { 26 | extend swift_proto_testing.extend.Foo.Bar.Baz { 27 | optional string b = 210; 28 | optional group C = 211 { 29 | optional int64 c = 1210; 30 | } 31 | } 32 | } 33 | 34 | extend swift_proto_testing.extend.Foo.Bar.Baz { 35 | optional string b = 220; 36 | optional group C = 221 { 37 | optional int64 c = 1220; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Protos/SwiftProtobufTests/unittest_swift_extension3.proto: -------------------------------------------------------------------------------- 1 | // Protos/unittest_swift_extension3.proto - test proto 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See http://swift.org/LICENSE.txt for license information 9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | // ----------------------------------------------------------------------------- 12 | /// 13 | /// Test naming of extensions that differ only in proto package. This is a 14 | /// clone of unittest_swift_extension2.proto, but with a different proto package 15 | /// and different extension numbers. 16 | /// 17 | // ----------------------------------------------------------------------------- 18 | 19 | syntax = "proto2"; 20 | 21 | package swift_proto_testing.extend3; 22 | 23 | import "unittest_swift_extension.proto"; 24 | 25 | message MyMessage { 26 | extend swift_proto_testing.extend.Foo.Bar.Baz { 27 | optional string b = 310; 28 | optional group C = 311 { 29 | optional int64 c = 1310; 30 | } 31 | } 32 | } 33 | 34 | extend swift_proto_testing.extend.Foo.Bar.Baz { 35 | optional string b = 320; 36 | optional group C = 321 { 37 | optional int64 c = 1320; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Protos/SwiftProtobufTests/unittest_swift_extension4.proto: -------------------------------------------------------------------------------- 1 | // Protos/unittest_swift_extension4.proto - test proto 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See http://swift.org/LICENSE.txt for license information 9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | // ----------------------------------------------------------------------------- 12 | /// 13 | /// Test naming of extensions that differ only in proto package. This is a 14 | /// clone of unittest_swift_extension[23].proto, but with a different proto 15 | /// package, different extension numbers, and a Swift prefix option. 16 | /// 17 | // ----------------------------------------------------------------------------- 18 | 19 | syntax = "proto2"; 20 | 21 | package swift_proto_testing.extend4; 22 | 23 | option swift_prefix = "Ext4"; 24 | 25 | import "unittest_swift_extension.proto"; 26 | 27 | message MyMessage { 28 | extend swift_proto_testing.extend.Foo.Bar.Baz { 29 | optional string b = 410; 30 | optional group C = 411 { 31 | optional int64 c = 1410; 32 | } 33 | } 34 | } 35 | 36 | extend swift_proto_testing.extend.Foo.Bar.Baz { 37 | optional string b = 420; 38 | optional group C = 421 { 39 | optional int64 c = 1420; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Protos/SwiftProtobufTests/unittest_swift_json.proto: -------------------------------------------------------------------------------- 1 | // Protos/unittest_swift_json.proto 2 | // This source file is part of the Swift.org open source project 3 | // 4 | // Copyright (c) 2020 Apple Inc. and the Swift project authors 5 | // Licensed under Apache License v2.0 with Runtime Library Exception 6 | // 7 | // See http://swift.org/LICENSE.txt for license information 8 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 9 | 10 | syntax = "proto3"; 11 | 12 | package swift_proto_testing; 13 | 14 | import "google/protobuf/struct.proto"; 15 | 16 | message SwiftJSONTest { 17 | // This case was omitted from test_messages_proto3.proto 18 | repeated google.protobuf.NullValue repeated_null_value = 318; 19 | } 20 | -------------------------------------------------------------------------------- /Protos/SwiftProtobufTests/unittest_swift_naming_number_prefix.proto: -------------------------------------------------------------------------------- 1 | // Protos/unittest_swift_naming_number_prefix.proto - test proto 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2020 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See http://swift.org/LICENSE.txt for license information 9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | // ----------------------------------------------------------------------------- 12 | /// 13 | /// Test Swift reserved words used as enum or message names 14 | /// 15 | // ----------------------------------------------------------------------------- 16 | 17 | syntax = "proto2"; 18 | 19 | // A package that starts with an underscore and number so if the generator just 20 | // stripped the underscore, it would result in invalid Swift. 21 | package _4fun.swift_proto_testing.mumble; 22 | 23 | message MyMessage { 24 | optional int32 a = 1; 25 | } 26 | -------------------------------------------------------------------------------- /Protos/SwiftProtobufTests/unittest_swift_oneof_merging.proto: -------------------------------------------------------------------------------- 1 | // Protos/unittest_swift_oneof_merging.proto - test proto 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See http://swift.org/LICENSE.txt for license information 9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | // ----------------------------------------------------------------------------- 12 | /// 13 | /// This is based on unittest.proto's TestParsingMerge & RepeatedFieldsGenerator, 14 | /// but focused on oneofs to ensure the behaviors around merging/replaces on 15 | /// oneofs is correct. 16 | /// 17 | // ----------------------------------------------------------------------------- 18 | 19 | syntax = "proto2"; 20 | 21 | package swift_proto_testing.merging; 22 | 23 | message TestMessage { 24 | message NestedMessage { 25 | optional int32 a = 1; 26 | optional int32 b = 2; 27 | optional int32 c = 3; 28 | } 29 | 30 | oneof oneof_field { 31 | uint32 oneof_uint32 = 111; 32 | NestedMessage oneof_nested_message = 112; 33 | string oneof_string = 113; 34 | bytes oneof_bytes = 114; 35 | } 36 | } 37 | 38 | message TestParsingMerge { 39 | message RepeatedFieldsGenerator { 40 | repeated TestMessage field1 = 1; 41 | repeated TestMessage field2 = 2; 42 | } 43 | 44 | optional TestMessage optional_message = 1; 45 | repeated TestMessage repeated_message = 2; 46 | } 47 | -------------------------------------------------------------------------------- /Protos/SwiftProtobufTests/unittest_swift_reserved_ext.proto: -------------------------------------------------------------------------------- 1 | // Protos/unittest_swift_reserved_ext.proto - test proto 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See http://swift.org/LICENSE.txt for license information 9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | // ----------------------------------------------------------------------------- 12 | /// 13 | /// Test Swift reserved words used as enum or message names 14 | /// 15 | // ----------------------------------------------------------------------------- 16 | 17 | syntax = "proto2"; 18 | 19 | // No package or swift prefix to control naming on these. 20 | 21 | import "unittest_swift_reserved.proto"; 22 | 23 | extend swift_proto_testing.SwiftReservedTest.Type { 24 | // Will get _p added because it has no package/swift prefix to scope and 25 | // would otherwise be a problem when added to the message. 26 | optional bool debugDescription = 1000; 27 | 28 | // These will get _p added for the same reasoning. 29 | optional bool as = 1012; 30 | optional bool var = 1013; 31 | optional bool try = 1014; 32 | optional bool do = 1015; 33 | optional bool nil = 1016; 34 | } 35 | 36 | message SwiftReservedTestExt2 { 37 | extend swift_proto_testing.SwiftReservedTest.Type { 38 | optional bool hashValue = 1001; 39 | 40 | // Reserved words, since these end up in the "enum Extensions", they 41 | // can't just be get their names, and sanitation kicks. 42 | optional bool as = 1022; 43 | optional bool var = 1023; 44 | optional bool try = 1024; 45 | optional bool do = 1025; 46 | optional bool nil = 1026; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Protos/protoc-gen-swiftTests/plugin_descriptor_test.proto: -------------------------------------------------------------------------------- 1 | // Protos/pluginlib_descriptor_test.proto - test proto 2 | // 3 | // This source file is part of the Swift.org open source project 4 | // 5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors 6 | // Licensed under Apache License v2.0 with Runtime Library Exception 7 | // 8 | // See http://swift.org/LICENSE.txt for license information 9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 10 | // 11 | // ----------------------------------------------------------------------------- 12 | /// 13 | /// Test proto for Tests/SwiftProtobufPluginLibraryTests/Test_Descriptor.swift 14 | /// 15 | // ----------------------------------------------------------------------------- 16 | 17 | syntax = "proto2"; 18 | 19 | package swift_descriptor_test; 20 | 21 | // To check handling of extension ranges that are out of order. 22 | message MsgExtensionRangeOrdering { 23 | extensions 1, 3, 2, 4; 24 | extensions 7; 25 | reserved 8; 26 | extensions 9; 27 | 28 | extensions 100 to 110; 29 | reserved 121 to 125; 30 | extensions 126 to 130; 31 | extensions 111 to 120; 32 | } 33 | 34 | // To check handling of extension ranges that are out of order, have fields or 35 | // reserved things mix through them. 36 | message MsgExtensionRangeOrderingWithFields { 37 | extensions 1, 3, 2, 4; 38 | optional int32 field6 = 6; 39 | extensions 7; 40 | reserved 8; 41 | extensions 9; 42 | 43 | extensions 100 to 110; 44 | reserved 121 to 123; 45 | optional int32 field124 = 124; 46 | optional int32 field125 = 125; 47 | extensions 126 to 130; 48 | extensions 111 to 120; 49 | optional int32 field200 = 200; 50 | } 51 | 52 | // Intermixed ranges and fields so help ensure no merge issues 53 | message MsgExtensionRangeOrderingNoMerging { 54 | optional int32 field1 = 1; 55 | optional int32 field2 = 2; 56 | extensions 3 to 5; 57 | optional int32 field6 = 6; 58 | extensions 7 to 12; 59 | optional int32 field13 = 13; 60 | optional int32 field15 = 15; 61 | extensions 16 to 20; 62 | optional int32 field21 = 21; 63 | } 64 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/any_test.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | syntax = "proto3"; 9 | 10 | package proto2_unittest; 11 | 12 | import "google/protobuf/any.proto"; 13 | 14 | option java_outer_classname = "TestAnyProto"; 15 | 16 | message TestAny { 17 | int32 int32_value = 1; 18 | google.protobuf.Any any_value = 2; 19 | repeated google.protobuf.Any repeated_any_value = 3; 20 | string text = 4; 21 | } 22 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/late_loaded_option.proto: -------------------------------------------------------------------------------- 1 | edition = "2023"; 2 | 3 | package proto2_unittest; 4 | 5 | import "google/protobuf/descriptor.proto"; 6 | 7 | message LateLoadedOption { 8 | int32 value = 1; 9 | 10 | extend google.protobuf.MessageOptions { 11 | LateLoadedOption ext = 95126892; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/late_loaded_option_user.proto: -------------------------------------------------------------------------------- 1 | edition = "2023"; 2 | 3 | package proto2_unittest; 4 | 5 | import "google/protobuf/late_loaded_option.proto"; 6 | 7 | message LateLoadedOptionUser { 8 | option (proto2_unittest.LateLoadedOption.ext) = { 9 | value: 1 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/map_proto3_unittest.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | edition = "2023"; 9 | 10 | // Treat all fields as implicit present by default (proto3 behavior). 11 | option features.field_presence = IMPLICIT; 12 | 13 | // This file contains definitions that have different behavior in proto3. 14 | 15 | // We don't put this in a package within proto2 because we need to make sure 16 | // that the generated code doesn't depend on being in the proto2 namespace. 17 | // In map_test_util.h we do "using namespace unittest = proto2_unittest". 18 | package proto3_unittest; 19 | 20 | message TestProto3BytesMap { 21 | map map_bytes = 1; 22 | map map_string = 2; 23 | } 24 | 25 | message TestI32StrMap { 26 | map m_32_str = 1; 27 | } 28 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/only_one_enum_test.proto: -------------------------------------------------------------------------------- 1 | edition = "2023"; 2 | 3 | package proto2_unittest; 4 | 5 | option optimize_for = LITE_RUNTIME; 6 | 7 | // A file with only a single enum, without any use of it. 8 | // This is useful for testing enum specific codegen that is not directly related 9 | // to field codegen. 10 | 11 | enum OnlyOneEnum { 12 | ONLY_ONE_ENUM_DEFAULT = 0; 13 | ONLY_ONE_ENUM_VALID = 10; 14 | } 15 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_arena.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | edition = "2023"; 9 | 10 | package proto2_arena_unittest; 11 | 12 | // Use expanded encoding for repeated fields by default (proto2 behavior). 13 | option features.repeated_field_encoding = EXPANDED; 14 | option cc_enable_arenas = true; 15 | 16 | message NestedMessage { 17 | int32 d = 1; 18 | } 19 | 20 | message ArenaMessage { 21 | repeated NestedMessage repeated_nested_message = 1; 22 | } 23 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_delimited_import.proto: -------------------------------------------------------------------------------- 1 | edition = "2023"; 2 | 3 | package editions_unittest; 4 | 5 | option java_multiple_files = true; 6 | 7 | message MessageImport { 8 | int32 a = 1; 9 | int32 b = 2; 10 | } 11 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_drop_unknown_fields.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | edition = "2023"; 9 | 10 | package unittest_drop_unknown_fields; 11 | 12 | // Treat all fields as implicit present by default (proto3 behavior). 13 | option features.field_presence = IMPLICIT; 14 | option objc_class_prefix = "DropUnknowns"; 15 | option csharp_namespace = "Google.Protobuf.TestProtos"; 16 | 17 | message Foo { 18 | enum NestedEnum { 19 | FOO = 0; 20 | BAR = 1; 21 | BAZ = 2; 22 | } 23 | int32 int32_value = 1; 24 | NestedEnum enum_value = 2; 25 | } 26 | 27 | message FooWithExtraFields { 28 | enum NestedEnum { 29 | FOO = 0; 30 | BAR = 1; 31 | BAZ = 2; 32 | MOO = 3; 33 | } 34 | int32 int32_value = 1; 35 | NestedEnum enum_value = 2; 36 | int32 extra_int32_value = 3; 37 | } 38 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_embed_optimize_for.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | // Author: kenton@google.com (Kenton Varda) 9 | // Based on original Protocol Buffers design by 10 | // Sanjay Ghemawat, Jeff Dean, and others. 11 | // 12 | // A proto file which imports a proto file that uses optimize_for = CODE_SIZE. 13 | 14 | syntax = "proto2"; 15 | 16 | package proto2_unittest; 17 | 18 | import "google/protobuf/unittest_optimize_for.proto"; 19 | 20 | // We optimize for speed here, but we are importing a proto that is optimized 21 | // for code size. 22 | option optimize_for = SPEED; 23 | 24 | message TestEmbedOptimizedForSize { 25 | // Test that embedding a message which has optimize_for = CODE_SIZE into 26 | // one optimized for speed works. 27 | optional TestOptimizedForSize optional_message = 1; 28 | repeated TestOptimizedForSize repeated_message = 2; 29 | } 30 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_empty.proto: -------------------------------------------------------------------------------- 1 | // NOLINT(no_package_specified): Test proto with no package 2 | 3 | // Protocol Buffers - Google's data interchange format 4 | // Copyright 2008 Google Inc. All rights reserved. 5 | // 6 | // Use of this source code is governed by a BSD-style 7 | // license that can be found in the LICENSE file or at 8 | // https://developers.google.com/open-source/licenses/bsd 9 | // 10 | // Author: kenton@google.com (Kenton Varda) 11 | // Based on original Protocol Buffers design by 12 | // Sanjay Ghemawat, Jeff Dean, and others. 13 | // 14 | // This file intentionally left blank. (At one point this wouldn't compile 15 | // correctly.) 16 | 17 | syntax = "proto2"; 18 | 19 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_extension_set.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | // Author: kenton@google.com (Kenton Varda) 9 | // Based on original Protocol Buffers design by 10 | // Sanjay Ghemawat, Jeff Dean, and others. 11 | // 12 | // This file contains messages for testing extensions. 13 | 14 | syntax = "proto2"; 15 | 16 | package proto2_unittest; 17 | 18 | option optimize_for = SPEED; 19 | option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 20 | 21 | // A message with message_set_wire_format. 22 | message TestExtensionSet { 23 | extensions 4 to max; 24 | } 25 | 26 | message TestExtensionSetContainer { 27 | optional TestExtensionSet extension = 1; 28 | } 29 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_import.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | // Author: kenton@google.com (Kenton Varda) 9 | // Based on original Protocol Buffers design by 10 | // Sanjay Ghemawat, Jeff Dean, and others. 11 | // 12 | // A proto file which is imported by unittest.proto to test importing. 13 | 14 | syntax = "proto2"; 15 | 16 | // We don't put this in a package within proto2 because we need to make sure 17 | // that the generated code doesn't depend on being in the proto2 namespace. 18 | // In test_util.h we do 19 | // "using namespace unittest_import = proto2_unittest_import". 20 | package proto2_unittest_import; 21 | 22 | option optimize_for = SPEED; 23 | option cc_enable_arenas = true; 24 | 25 | // Exercise the java_package option. 26 | option java_package = "com.google.protobuf.test"; 27 | 28 | // Do not set a java_outer_classname here to verify that Proto2 works without 29 | // one. 30 | 31 | // Test public import 32 | import public "google/protobuf/unittest_import_public.proto"; 33 | 34 | message ImportMessage { 35 | optional int32 d = 1; 36 | } 37 | 38 | enum ImportEnum { 39 | IMPORT_FOO = 7; 40 | IMPORT_BAR = 8; 41 | IMPORT_BAZ = 9; 42 | } 43 | 44 | // To use an enum in a map, it must has the first value as 0. 45 | enum ImportEnumForMap { 46 | UNKNOWN = 0; 47 | FOO = 1; 48 | BAR = 2; 49 | } 50 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_import_lite.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | // Author: kenton@google.com (Kenton Varda) 9 | // 10 | // This is like unittest_import.proto but with optimize_for = LITE_RUNTIME. 11 | 12 | edition = "2023"; 13 | 14 | package proto2_unittest_import; 15 | 16 | import public "google/protobuf/unittest_import_public_lite.proto"; 17 | 18 | option optimize_for = LITE_RUNTIME; 19 | option java_package = "com.google.protobuf"; 20 | 21 | message ImportMessageLite { 22 | int32 d = 1; 23 | } 24 | 25 | enum ImportEnumLite { 26 | option features.enum_type = CLOSED; 27 | 28 | IMPORT_LITE_FOO = 7; 29 | IMPORT_LITE_BAR = 8; 30 | IMPORT_LITE_BAZ = 9; 31 | } 32 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_import_public.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | // Author: liujisi@google.com (Pherl Liu) 9 | 10 | syntax = "proto2"; 11 | 12 | package proto2_unittest_import; 13 | 14 | option java_package = "com.google.protobuf.test"; 15 | 16 | message PublicImportMessage { 17 | optional int32 e = 1; 18 | } 19 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_import_public_lite.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | // Author: liujisi@google.com (Pherl Liu) 9 | 10 | edition = "2023"; 11 | 12 | package proto2_unittest_import; 13 | 14 | option optimize_for = LITE_RUNTIME; 15 | option java_package = "com.google.protobuf"; 16 | 17 | message PublicImportMessageLite { 18 | int32 e = 1; 19 | } 20 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_invalid_features.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2023 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | syntax = "proto2"; 9 | 10 | package pb; 11 | 12 | import "google/protobuf/descriptor.proto"; 13 | 14 | extend google.protobuf.FeatureSet { 15 | optional TestInvalidFeatures test_invalid = 9996; 16 | } 17 | 18 | message TestInvalidFeatures { 19 | repeated int32 repeated_feature = 1 [ 20 | retention = RETENTION_RUNTIME, 21 | targets = TARGET_TYPE_FIELD, 22 | edition_defaults = { edition: EDITION_2023, value: "3" } 23 | ]; 24 | } 25 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_lazy_dependencies.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | // Author: trafacz@google.com (Todd Rafacz) 9 | // Based on original Protocol Buffers design by 10 | // Sanjay Ghemawat, Jeff Dean, and others. 11 | // 12 | // A proto file we will use for unit testing. 13 | 14 | edition = "2023"; 15 | 16 | import "google/protobuf/unittest_lazy_dependencies_custom_option.proto"; 17 | 18 | // Some generic_services option(s) added automatically. 19 | // See: http://go/proto2-generic-services-default 20 | option cc_generic_services = true; // auto-added 21 | option java_generic_services = true; // auto-added 22 | option py_generic_services = true; // auto-added 23 | option cc_enable_arenas = true; 24 | 25 | // We don't put this in a package within proto2 because we need to make sure 26 | // that the generated code doesn't depend on being in the proto2 namespace. 27 | // In test_util.h we do "using namespace unittest = proto2_unittest". 28 | package proto2_unittest.lazy_imports; 29 | 30 | // Protos optimized for SPEED use a strict superset of the generated code 31 | // of equivalent ones optimized for CODE_SIZE, so we should optimize all our 32 | // tests for speed unless explicitly testing code size optimization. 33 | option optimize_for = SPEED; 34 | 35 | option java_outer_classname = "UnittestLazyImportsProto"; 36 | 37 | // The following are used to test that the proto file 38 | // with the definition of the following field types is 39 | // not built when this proto file is built. Then test 40 | // that calling message_type() etc will build the correct 41 | // descriptor lazily and return it. 42 | 43 | message ImportedMessage { 44 | LazyMessage lazy_message = 1; 45 | } 46 | 47 | message MessageCustomOption {} 48 | 49 | message MessageCustomOption2 { 50 | option (lazy_enum_option) = LAZY_ENUM_0; 51 | } 52 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_lazy_dependencies_custom_option.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | // Author: trafacz@google.com (Todd Rafacz) 9 | // Based on original Protocol Buffers design by 10 | // Sanjay Ghemawat, Jeff Dean, and others. 11 | // 12 | // A proto file we will use for unit testing. 13 | 14 | edition = "2023"; 15 | 16 | import "google/protobuf/descriptor.proto"; 17 | import "google/protobuf/unittest_lazy_dependencies_enum.proto"; 18 | 19 | // Some generic_services option(s) added automatically. 20 | // See: http://go/proto2-generic-services-default 21 | option cc_generic_services = true; // auto-added 22 | option java_generic_services = true; // auto-added 23 | option py_generic_services = true; // auto-added 24 | option cc_enable_arenas = true; 25 | 26 | // We don't put this in a package within proto2 because we need to make sure 27 | // that the generated code doesn't depend on being in the proto2 namespace. 28 | // In test_util.h we do "using namespace unittest = proto2_unittest". 29 | package proto2_unittest.lazy_imports; 30 | 31 | // Protos optimized for SPEED use a strict superset of the generated code 32 | // of equivalent ones optimized for CODE_SIZE, so we should optimize all our 33 | // tests for speed unless explicitly testing code size optimization. 34 | option optimize_for = SPEED; 35 | 36 | option java_outer_classname = "UnittestLazyImportsCustomOptionProto"; 37 | 38 | message LazyMessage { 39 | int32 a = 1; 40 | } 41 | 42 | extend google.protobuf.MessageOptions { 43 | LazyEnum lazy_enum_option = 138596335 [default = LAZY_ENUM_1]; 44 | } 45 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_lazy_dependencies_enum.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | // Author: trafacz@google.com (Todd Rafacz) 9 | // Based on original Protocol Buffers design by 10 | // Sanjay Ghemawat, Jeff Dean, and others. 11 | // 12 | // A proto file we will use for unit testing. 13 | 14 | edition = "2023"; 15 | 16 | // Treat all enums as closed by default (proto2 behavior). 17 | option features.enum_type = CLOSED; 18 | 19 | // Some generic_services option(s) added automatically. 20 | // See: http://go/proto2-generic-services-default 21 | option cc_generic_services = true; // auto-added 22 | option java_generic_services = true; // auto-added 23 | option py_generic_services = true; // auto-added 24 | option cc_enable_arenas = true; 25 | 26 | // We don't put this in a package within proto2 because we need to make sure 27 | // that the generated code doesn't depend on being in the proto2 namespace. 28 | // In test_util.h we do "using namespace unittest = proto2_unittest". 29 | package proto2_unittest.lazy_imports; 30 | 31 | // Protos optimized for SPEED use a strict superset of the generated code 32 | // of equivalent ones optimized for CODE_SIZE, so we should optimize all our 33 | // tests for speed unless explicitly testing code size optimization. 34 | option optimize_for = SPEED; 35 | 36 | option java_outer_classname = "UnittestLazyImportsEnumProto"; 37 | 38 | enum LazyEnum { 39 | LAZY_ENUM_0 = 0; 40 | LAZY_ENUM_1 = 1; 41 | } 42 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_legacy_features.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | // Test that features with legacy descriptor helpers get properly converted. 9 | 10 | edition = "2023"; 11 | 12 | package legacy_features_unittest; 13 | 14 | message TestEditionsMessage { 15 | int32 required_field = 1 [features.field_presence = LEGACY_REQUIRED]; 16 | TestEditionsMessage delimited_field = 2 17 | [features.message_encoding = DELIMITED]; 18 | } 19 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_lite_imports_nonlite.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | // Author: kenton@google.com (Kenton Varda) 9 | // 10 | // Tests that a "lite" message can import a regular message. 11 | 12 | syntax = "proto2"; 13 | 14 | package proto2_unittest; 15 | 16 | import "google/protobuf/unittest.proto"; 17 | 18 | option optimize_for = LITE_RUNTIME; 19 | 20 | message TestLiteImportsNonlite { 21 | optional TestAllTypes message = 1; 22 | 23 | // Verifies that transitive required fields generates valid code. 24 | optional TestRequired message_with_required = 2; 25 | } 26 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_mset_wire_format.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | // Author: kenton@google.com (Kenton Varda) 9 | // Based on original Protocol Buffers design by 10 | // Sanjay Ghemawat, Jeff Dean, and others. 11 | // 12 | // This file contains messages for testing message_set_wire_format. 13 | 14 | syntax = "proto2"; 15 | 16 | package proto2_wireformat_unittest; 17 | 18 | option cc_enable_arenas = true; 19 | option optimize_for = SPEED; 20 | option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 21 | 22 | // A message with message_set_wire_format. 23 | message TestMessageSet { 24 | option message_set_wire_format = true; 25 | 26 | extensions 4 to 529999999; 27 | 28 | extensions 530000000 to max 29 | [declaration = { 30 | number: 1952731290, 31 | full_name: ".proto2_unittest_v1api.TestMessageSetExtension3.message_set_extension", 32 | type: ".proto2_unittest_v1api.TestMessageSetExtension3" 33 | }]; 34 | } 35 | 36 | message TestMessageSetWireFormatContainer { 37 | optional TestMessageSet message_set = 1; 38 | } 39 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_no_generic_services.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | // Author: kenton@google.com (Kenton Varda) 9 | 10 | syntax = "proto2"; 11 | 12 | package proto2_unittest.no_generic_services_test; 13 | 14 | 15 | // *_generic_services are false by default. 16 | 17 | message TestMessage { 18 | optional int32 a = 1; 19 | extensions 1000 to max; 20 | } 21 | 22 | enum TestEnum { 23 | FOO = 1; 24 | } 25 | 26 | extend TestMessage { 27 | optional int32 test_extension = 1000; 28 | } 29 | 30 | service TestService { 31 | rpc Foo(TestMessage) returns (TestMessage); 32 | } 33 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_optimize_for.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | // Author: kenton@google.com (Kenton Varda) 9 | // Based on original Protocol Buffers design by 10 | // Sanjay Ghemawat, Jeff Dean, and others. 11 | // 12 | // A proto file which uses optimize_for = CODE_SIZE. 13 | 14 | syntax = "proto2"; 15 | 16 | package proto2_unittest; 17 | 18 | import "google/protobuf/unittest.proto"; 19 | 20 | option optimize_for = CODE_SIZE; 21 | 22 | message TestOptimizedForSize { 23 | optional int32 i = 1; 24 | optional ForeignMessage msg = 19; 25 | 26 | extensions 1000 to max; 27 | 28 | extend TestOptimizedForSize { 29 | optional int32 test_extension = 1234; 30 | optional TestRequiredOptimizedForSize test_extension2 = 1235; 31 | } 32 | 33 | oneof foo { 34 | int32 integer_field = 2; 35 | string string_field = 3; 36 | } 37 | } 38 | 39 | message TestRequiredOptimizedForSize { 40 | required int32 x = 1; 41 | } 42 | 43 | message TestOptionalOptimizedForSize { 44 | optional TestRequiredOptimizedForSize o = 1; 45 | } 46 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_preserve_unknown_enum.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | edition = "2023"; 9 | 10 | package proto3_preserve_unknown_enum_unittest; 11 | 12 | // Treat all fields as implicit present by default (proto3 behavior). 13 | option features.field_presence = IMPLICIT; 14 | option objc_class_prefix = "UnknownEnums"; 15 | option csharp_namespace = "Google.Protobuf.TestProtos"; 16 | 17 | enum MyEnum { 18 | FOO = 0; 19 | BAR = 1; 20 | BAZ = 2; 21 | } 22 | 23 | enum MyEnumPlusExtra { 24 | E_FOO = 0; 25 | E_BAR = 1; 26 | E_BAZ = 2; 27 | E_EXTRA = 3; 28 | } 29 | 30 | message MyMessage { 31 | MyEnum e = 1; 32 | repeated MyEnum repeated_e = 2; 33 | repeated MyEnum repeated_packed_e = 3; 34 | repeated MyEnumPlusExtra repeated_packed_unexpected_e = 4; // not packed 35 | oneof o { 36 | MyEnum oneof_e_1 = 5; 37 | MyEnum oneof_e_2 = 6; 38 | } 39 | } 40 | 41 | message MyMessagePlusExtra { 42 | MyEnumPlusExtra e = 1; 43 | repeated MyEnumPlusExtra repeated_e = 2; 44 | repeated MyEnumPlusExtra repeated_packed_e = 3; 45 | repeated MyEnumPlusExtra repeated_packed_unexpected_e = 4; 46 | oneof o { 47 | MyEnumPlusExtra oneof_e_1 = 5; 48 | MyEnumPlusExtra oneof_e_2 = 6; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_preserve_unknown_enum2.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | edition = "2023"; 9 | 10 | package proto2_preserve_unknown_enum_unittest; 11 | 12 | // Treat all enums as closed and use expanded encoding for repeated fields by 13 | // default (proto2 behavior). 14 | option features.enum_type = CLOSED; 15 | option features.repeated_field_encoding = EXPANDED; 16 | 17 | enum MyEnum { 18 | FOO = 0; 19 | BAR = 1; 20 | BAZ = 2; 21 | } 22 | 23 | message MyMessage { 24 | MyEnum e = 1; 25 | repeated MyEnum repeated_e = 2; 26 | repeated MyEnum repeated_packed_e = 3 27 | [features.repeated_field_encoding = PACKED]; 28 | repeated MyEnum repeated_packed_unexpected_e = 4; // not packed 29 | oneof o { 30 | MyEnum oneof_e_1 = 5; 31 | MyEnum oneof_e_2 = 6; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_proto3_extensions.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package protobuf_unittest; 4 | 5 | import "google/protobuf/descriptor.proto"; 6 | 7 | option java_outer_classname = "UnittestProto3Extensions"; 8 | 9 | // For testing proto3 extension behaviors. 10 | message Proto3FileExtensions { 11 | extend google.protobuf.FileOptions { 12 | int32 singular_int = 1001; 13 | repeated int32 repeated_int = 1002; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_string_type.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file or at 6 | // https://developers.google.com/open-source/licenses/bsd 7 | 8 | edition = "2023"; 9 | 10 | package proto2_unittest; 11 | 12 | import "google/protobuf/cpp_features.proto"; 13 | 14 | message EntryProto { 15 | bytes value = 3 [features.(pb.cpp).string_type = CORD]; 16 | } 17 | -------------------------------------------------------------------------------- /Protos/upstream/google/protobuf/unittest_string_view.proto: -------------------------------------------------------------------------------- 1 | edition = "2023"; 2 | 3 | package proto2_unittest; 4 | 5 | import "google/protobuf/cpp_features.proto"; 6 | 7 | option java_multiple_files = true; 8 | option optimize_for = SPEED; 9 | option features.(pb.cpp).string_type = VIEW; 10 | 11 | // NEXT_TAG = 6; 12 | message TestStringView { 13 | string singular_string = 1; 14 | bytes singular_bytes = 2; 15 | string implicit_presence = 5 [features.field_presence = IMPLICIT]; 16 | 17 | repeated string repeated_string = 3; 18 | repeated bytes repeated_bytes = 4; 19 | } 20 | 21 | message TestStringViewExtension { 22 | extensions 1 to max; 23 | } 24 | 25 | extend TestStringViewExtension { 26 | string singular_string_view_extension = 1; 27 | bytes singular_bytes_view_extension = 2; 28 | 29 | repeated string repeated_string_view_extension = 3; 30 | repeated bytes repeated_bytes_view_extension = 4; 31 | } 32 | -------------------------------------------------------------------------------- /Reference/CompileTests/InternalImportsByDefault/ServiceOnly.pb.swift: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. 2 | // swift-format-ignore-file 3 | // swiftlint:disable all 4 | // 5 | // Generated by the Swift generator plugin for the protocol buffer compiler. 6 | // Source: ServiceOnly.proto 7 | // 8 | // For information on using the generated types, please see the documentation: 9 | // https://github.com/apple/swift-protobuf/ 10 | 11 | // This file contained no messages, enums, or extensions. 12 | -------------------------------------------------------------------------------- /Reference/CompileTests/MultiModule/Sources/ReExportAOnly/reexport_a_only.pb.swift: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. 2 | // swift-format-ignore-file 3 | // swiftlint:disable all 4 | // 5 | // Generated by the Swift generator plugin for the protocol buffer compiler. 6 | // Source: Sources/ReExportAOnly/reexport_a_only.proto 7 | // 8 | // For information on using the generated types, please see the documentation: 9 | // https://github.com/apple/swift-protobuf/ 10 | 11 | // Use of 'import public' causes re-exports: 12 | @_exported import enum ModuleA.E 13 | @_exported import let ModuleA.Extensions_ext_str 14 | @_exported import struct ModuleA.A 15 | 16 | // This file contained no messages, enums, or extensions. 17 | -------------------------------------------------------------------------------- /Reference/upstream/google/protobuf/only_one_enum_test.pb.swift: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. 2 | // swift-format-ignore-file 3 | // swiftlint:disable all 4 | // 5 | // Generated by the Swift generator plugin for the protocol buffer compiler. 6 | // Source: google/protobuf/only_one_enum_test.proto 7 | // 8 | // For information on using the generated types, please see the documentation: 9 | // https://github.com/apple/swift-protobuf/ 10 | 11 | import SwiftProtobuf 12 | 13 | // If the compiler emits an error on this type, it is because this file 14 | // was generated by a version of the `protoc` Swift plug-in that is 15 | // incompatible with the version of SwiftProtobuf to which you are linking. 16 | // Please ensure that you are building against the same version of the API 17 | // that was used to generate this file. 18 | fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { 19 | struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} 20 | typealias Version = _2 21 | } 22 | 23 | enum Proto2Unittest_OnlyOneEnum: SwiftProtobuf.Enum, Swift.CaseIterable { 24 | typealias RawValue = Int 25 | case `default` // = 0 26 | case valid // = 10 27 | case UNRECOGNIZED(Int) 28 | 29 | init() { 30 | self = .default 31 | } 32 | 33 | init?(rawValue: Int) { 34 | switch rawValue { 35 | case 0: self = .default 36 | case 10: self = .valid 37 | default: self = .UNRECOGNIZED(rawValue) 38 | } 39 | } 40 | 41 | var rawValue: Int { 42 | switch self { 43 | case .default: return 0 44 | case .valid: return 10 45 | case .UNRECOGNIZED(let i): return i 46 | } 47 | } 48 | 49 | // The compiler won't synthesize support with the UNRECOGNIZED case. 50 | static let allCases: [Proto2Unittest_OnlyOneEnum] = [ 51 | .default, 52 | .valid, 53 | ] 54 | 55 | } 56 | 57 | // MARK: - Code below here is support for the SwiftProtobuf runtime. 58 | 59 | extension Proto2Unittest_OnlyOneEnum: SwiftProtobuf._ProtoNameProviding { 60 | static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ 61 | 0: .same(proto: "ONLY_ONE_ENUM_DEFAULT"), 62 | 10: .same(proto: "ONLY_ONE_ENUM_VALID"), 63 | ] 64 | } 65 | -------------------------------------------------------------------------------- /Reference/upstream/google/protobuf/unittest_empty.pb.swift: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. 2 | // swift-format-ignore-file 3 | // swiftlint:disable all 4 | // 5 | // Generated by the Swift generator plugin for the protocol buffer compiler. 6 | // Source: google/protobuf/unittest_empty.proto 7 | // 8 | // For information on using the generated types, please see the documentation: 9 | // https://github.com/apple/swift-protobuf/ 10 | 11 | // NOLINT(no_package_specified): Test proto with no package 12 | 13 | // Protocol Buffers - Google's data interchange format 14 | // Copyright 2008 Google Inc. All rights reserved. 15 | // 16 | // Use of this source code is governed by a BSD-style 17 | // license that can be found in the LICENSE file or at 18 | // https://developers.google.com/open-source/licenses/bsd 19 | // 20 | // Author: kenton@google.com (Kenton Varda) 21 | // Based on original Protocol Buffers design by 22 | // Sanjay Ghemawat, Jeff Dean, and others. 23 | // 24 | // This file intentionally left blank. (At one point this wouldn't compile 25 | // correctly.) 26 | 27 | // This file contained no messages, enums, or extensions. 28 | -------------------------------------------------------------------------------- /Reference/upstream/google/protobuf/unittest_lazy_dependencies_enum.pb.swift: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. 2 | // swift-format-ignore-file 3 | // swiftlint:disable all 4 | // 5 | // Generated by the Swift generator plugin for the protocol buffer compiler. 6 | // Source: google/protobuf/unittest_lazy_dependencies_enum.proto 7 | // 8 | // For information on using the generated types, please see the documentation: 9 | // https://github.com/apple/swift-protobuf/ 10 | 11 | // Protocol Buffers - Google's data interchange format 12 | // Copyright 2008 Google Inc. All rights reserved. 13 | // 14 | // Use of this source code is governed by a BSD-style 15 | // license that can be found in the LICENSE file or at 16 | // https://developers.google.com/open-source/licenses/bsd 17 | 18 | // Author: trafacz@google.com (Todd Rafacz) 19 | // Based on original Protocol Buffers design by 20 | // Sanjay Ghemawat, Jeff Dean, and others. 21 | // 22 | // A proto file we will use for unit testing. 23 | 24 | import SwiftProtobuf 25 | 26 | // If the compiler emits an error on this type, it is because this file 27 | // was generated by a version of the `protoc` Swift plug-in that is 28 | // incompatible with the version of SwiftProtobuf to which you are linking. 29 | // Please ensure that you are building against the same version of the API 30 | // that was used to generate this file. 31 | fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { 32 | struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} 33 | typealias Version = _2 34 | } 35 | 36 | enum Proto2Unittest_LazyImports_LazyEnum: Int, SwiftProtobuf.Enum, Swift.CaseIterable { 37 | case lazyEnum0 = 0 38 | case lazyEnum1 = 1 39 | 40 | init() { 41 | self = .lazyEnum0 42 | } 43 | 44 | } 45 | 46 | // MARK: - Code below here is support for the SwiftProtobuf runtime. 47 | 48 | extension Proto2Unittest_LazyImports_LazyEnum: SwiftProtobuf._ProtoNameProviding { 49 | static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ 50 | 0: .same(proto: "LAZY_ENUM_0"), 51 | 1: .same(proto: "LAZY_ENUM_1"), 52 | ] 53 | } 54 | -------------------------------------------------------------------------------- /Sources/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(SwiftProtobuf) 2 | add_subdirectory(SwiftProtobufPluginLibrary) 3 | add_subdirectory(protoc-gen-swift) 4 | -------------------------------------------------------------------------------- /Sources/Conformance/Docs.docc/index.md: -------------------------------------------------------------------------------- 1 | # Conformance 2 | 3 | Test program for use with Google's Protobuf Conformance suite. 4 | 5 | -------------------------------------------------------------------------------- /Sources/Conformance/failure_list_swift.txt: -------------------------------------------------------------------------------- 1 | # Nothing failing. 2 | -------------------------------------------------------------------------------- /Sources/Conformance/text_format_failure_list_swift.txt: -------------------------------------------------------------------------------- 1 | # No known failures. 2 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/AnyUnpackError.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/AnyUnpackError.swift - Any Unpacking Errors 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Errors that can be throw when unpacking a Google_Protobuf_Any. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | /// Describes errors that can occur when unpacking an `Google_Protobuf_Any` 16 | /// message. 17 | /// 18 | /// `Google_Protobuf_Any` messages can be decoded from protobuf binary, text 19 | /// format, or JSON. The contents are not parsed immediately; the raw data is 20 | /// held in the `Google_Protobuf_Any` message until you `unpack()` it into a 21 | /// message. At this time, any error can occur that might have occurred from a 22 | /// regular decoding operation. There are also other errors that can occur due 23 | /// to problems with the `Any` value's structure. 24 | public enum AnyUnpackError: Error { 25 | /// The `type_url` field in the `Google_Protobuf_Any` message did not match 26 | /// the message type provided to the `unpack()` method. 27 | case typeMismatch 28 | 29 | /// Well-known types being decoded from JSON must have only two fields: the 30 | /// `@type` field and a `value` field containing the specialized JSON coding 31 | /// of the well-known type. 32 | case malformedWellKnownTypeJSON 33 | 34 | /// The `Google_Protobuf_Any` message was malformed in some other way not 35 | /// covered by the other error cases. 36 | case malformedAnyField 37 | } 38 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/BinaryDecodingError.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/BinaryDecodingError.swift - Protobuf binary decoding errors 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Protobuf binary format decoding errors 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | /// Describes errors that can occur when decoding a message from binary format. 16 | public enum BinaryDecodingError: Error { 17 | /// Extraneous data remained after decoding should have been complete. 18 | case trailingGarbage 19 | 20 | /// The decoder unexpectedly reached the end of the data before it was 21 | /// expected. 22 | case truncated 23 | 24 | /// A string field was not encoded as valid UTF-8. 25 | case invalidUTF8 26 | 27 | /// The binary data was malformed in some way, such as an invalid wire format 28 | /// or field tag. 29 | case malformedProtobuf 30 | 31 | /// The definition of the message or one of its nested messages has required 32 | /// fields but the binary data did not include values for them. You must pass 33 | /// `partial: true` during decoding if you wish to explicitly ignore missing 34 | /// required fields. 35 | case missingRequiredFields 36 | 37 | /// An internal error happened while decoding. If this is ever encountered, 38 | /// please file an issue with SwiftProtobuf with as much details as possible 39 | /// for what happened (proto definitions, bytes being decoded (if possible)). 40 | case internalExtensionError 41 | 42 | /// Reached the nesting limit for messages within messages while decoding. 43 | case messageDepthLimit 44 | } 45 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/BinaryDecodingOptions.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/BinaryDecodingOptions.swift - Binary decoding options 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Binary decoding options 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | /// Options for binary decoding. 16 | public struct BinaryDecodingOptions: Sendable { 17 | /// The maximum nesting of message with messages. The default is 100. 18 | /// 19 | /// To prevent corrupt or malicious messages from causing stack overflows, 20 | /// this controls how deep messages can be nested within other messages 21 | /// while parsing. 22 | public var messageDepthLimit: Int = 100 23 | 24 | /// Discard unknown fields while parsing. The default is false, so parsering 25 | /// does not discard unknown fields. 26 | /// 27 | /// The Protobuf binary format allows unknown fields to be still parsed 28 | /// so the schema can be expanded without requiring all readers to be updated. 29 | /// This works in part by having any unknown fields preserved so they can 30 | /// be relayed on without loss. For a while the proto3 syntax definition 31 | /// called for unknown fields to be dropped, but that lead to problems in 32 | /// some case. The default is to follow the spec and keep them, but setting 33 | /// this option to `true` allows a developer to strip them during a parse 34 | /// in case they have a specific need to drop the unknown fields from the 35 | /// object graph being created. 36 | public var discardUnknownFields: Bool = false 37 | 38 | public init() {} 39 | } 40 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/BinaryEncodingError.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/BinaryEncodingError.swift - Error constants 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Enum constants that identify the particular error. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | /// Describes errors that can occur when decoding a message from binary format. 16 | public enum BinaryEncodingError: Error, Hashable { 17 | /// An unexpected failure when deserializing a `Google_Protobuf_Any`. 18 | case anyTranscodeFailure 19 | /// The definition of the message or one of its nested messages has required 20 | /// fields but the message being encoded did not include values for them. You 21 | /// must pass `partial: true` during encoding if you wish to explicitly ignore 22 | /// missing required fields. 23 | case missingRequiredFields 24 | } 25 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/BinaryEncodingOptions.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/BinaryEncodingOptions.swift - Binary encoding options 2 | // 3 | // Copyright (c) 2014 - 2023 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Binary encoding options 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | /// Options for binary encoding. 16 | public struct BinaryEncodingOptions: Sendable { 17 | /// Whether to use deterministic ordering when serializing. 18 | /// 19 | /// Note that the deterministic serialization is NOT canonical across languages. 20 | /// It is NOT guaranteed to remain stable over time. It is unstable across 21 | /// different builds with schema changes due to unknown fields. Users who need 22 | /// canonical serialization (e.g., persistent storage in a canonical form, 23 | /// fingerprinting, etc.) should define their own canonicalization specification 24 | /// and implement their own serializer rather than relying on this API. 25 | /// 26 | /// If deterministic serialization is requested, map entries will be sorted 27 | /// by keys in lexicographical order. This is an implementation detail 28 | /// and subject to change. 29 | public var useDeterministicOrdering: Bool = false 30 | 31 | public init() {} 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/CustomJSONCodable.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/CustomJSONCodable.swift - Custom JSON support for WKTs 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Custom protocol for the WKTs to support their custom JSON encodings. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | /// Allows WKTs to provide their custom JSON encodings. 16 | internal protocol _CustomJSONCodable { 17 | func encodedJSONString(options: JSONEncodingOptions) throws -> String 18 | mutating func decodeJSON(from: inout JSONDecoder) throws 19 | 20 | /// Called when the JSON `null` literal is encountered in a position where 21 | /// a message of the conforming type is expected. The message type can then 22 | /// handle the `null` value differently, if needed; for example, 23 | /// `Google_Protobuf_Value` returns a special instance whose `kind` is set to 24 | /// `.nullValue(.nullValue)`. 25 | /// 26 | /// The default behavior is to return `nil`, which indicates that `null` 27 | /// should be treated as the absence of a message. 28 | static func decodedFromJSONNull() throws -> Self? 29 | } 30 | 31 | extension _CustomJSONCodable { 32 | internal static func decodedFromJSONNull() -> Self? { 33 | // Return nil by default. Concrete types can provide custom logic. 34 | nil 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/Docs.docc/index.md: -------------------------------------------------------------------------------- 1 | # ``SwiftProtobuf`` 2 | 3 | Support library for Swift code generated by protoc-gen-swift. 4 | 5 | ## Getting Started 6 | 7 | .... 8 | 9 | ## Topics 10 | 11 | ### Stuff 12 | 13 | - 14 | 15 | - ``protoc-gen-swift`` 16 | - ``Sometopic`` 17 | - ``API Overview`` 18 | - ``Message`` 19 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/ExtensionMap.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/ExtensionMap.swift - Extension support 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// A set of extensions that can be passed into deserializers 12 | /// to provide details of the particular extensions that should 13 | /// be recognized. 14 | /// 15 | // ----------------------------------------------------------------------------- 16 | 17 | /// A collection of extension objects. 18 | /// 19 | /// An `ExtensionMap` is used during decoding to look up 20 | /// extension objects corresponding to the serialized data. 21 | /// 22 | /// This is a protocol so that developers can build their own 23 | /// extension handling if they need something more complex than the 24 | /// standard `SimpleExtensionMap` implementation. 25 | @preconcurrency 26 | public protocol ExtensionMap: Sendable { 27 | /// Returns the extension object describing an extension or nil 28 | subscript(messageType: any Message.Type, fieldNumber: Int) -> (any AnyMessageExtension)? { get } 29 | 30 | /// Returns the field number for a message with a specific field name 31 | /// 32 | /// The field name here matches the format used by the protobuf 33 | /// Text serialization: it typically looks like 34 | /// `package.message.field_name`, where `package` is the package 35 | /// for the proto file and `message` is the name of the message in 36 | /// which the extension was defined. (This is different from the 37 | /// message that is being extended!) 38 | func fieldNumberForProto(messageType: any Message.Type, protoFieldName: String) -> Int? 39 | } 40 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/Google_Protobuf_NullValue+Extensions.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/Google_Protobuf_NullValue+Extensions.swift - NullValue extensions 2 | // 3 | // Copyright (c) 2014 - 2020 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// NullValue is a well-known message type that can be used to parse or encode 12 | /// JSON Null values. 13 | /// 14 | // ----------------------------------------------------------------------------- 15 | 16 | extension Google_Protobuf_NullValue: _CustomJSONCodable { 17 | internal func encodedJSONString(options: JSONEncodingOptions) throws -> String { 18 | "null" 19 | } 20 | internal mutating func decodeJSON(from decoder: inout JSONDecoder) throws { 21 | if decoder.scanner.skipOptionalNull() { 22 | return 23 | } 24 | } 25 | static func decodedFromJSONNull() -> Google_Protobuf_NullValue? { 26 | .nullValue 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/JSONDecodingOptions.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/JSONDecodingOptions.swift - JSON decoding options 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// JSON decoding options 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | /// Options for JSONDecoding. 16 | public struct JSONDecodingOptions: Sendable { 17 | /// The maximum nesting of message with messages. The default is 100. 18 | /// 19 | /// To prevent corrupt or malicious messages from causing stack overflows, 20 | /// this controls how deep messages can be nested within other messages 21 | /// while parsing. 22 | public var messageDepthLimit: Int = 100 23 | 24 | /// If unknown fields in the JSON should be ignored. If they aren't 25 | /// ignored, an error will be raised if one is encountered. This also 26 | /// causes unknown enum values (especially string values) to be silently 27 | /// ignored. 28 | public var ignoreUnknownFields: Bool = false 29 | 30 | public init() {} 31 | } 32 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/JSONEncodingError.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/JSONEncodingError.swift - Error constants 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Enum constants that identify the particular error. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | public enum JSONEncodingError: Error, Hashable { 16 | /// Any fields that were decoded from binary format cannot be 17 | /// re-encoded into JSON unless the object they hold is a 18 | /// well-known type or a type registered with via 19 | /// Google_Protobuf_Any.register() 20 | case anyTranscodeFailure 21 | /// Timestamp values can only be JSON encoded if they hold a value 22 | /// between 0001-01-01Z00:00:00 and 9999-12-31Z23:59:59. 23 | case timestampRange 24 | /// Duration values can only be JSON encoded if they hold a value 25 | /// less than +/- 100 years. 26 | case durationRange 27 | /// Field masks get edited when converting between JSON and protobuf 28 | case fieldMaskConversion 29 | /// Field names were not compiled into the binary 30 | case missingFieldNames 31 | /// Instances of `Google_Protobuf_Value` can only be encoded if they have a 32 | /// valid `kind` (that is, they represent a null value, number, boolean, 33 | /// string, struct, or list). 34 | case missingValue 35 | /// google.protobuf.Value cannot encode double values for infinity or nan, 36 | /// because they would be parsed as a string. 37 | case valueNumberNotFinite 38 | } 39 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/JSONEncodingOptions.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/JSONEncodingOptions.swift - JSON encoding options 2 | // 3 | // Copyright (c) 2014 - 2018 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// JSON encoding options 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | /// Options for JSONEncoding. 16 | public struct JSONEncodingOptions: Sendable { 17 | 18 | /// Always prints int64s values as numbers. 19 | /// By default, they are printed as strings as per proto3 JSON mapping rules. 20 | /// NB: When used as Map keys, int64s will be printed as strings as expected. 21 | public var alwaysPrintInt64sAsNumbers: Bool = false 22 | 23 | /// Always print enums as ints. By default they are printed as strings. 24 | public var alwaysPrintEnumsAsInts: Bool = false 25 | 26 | /// Whether to preserve proto field names. 27 | /// By default they are converted to JSON(lowerCamelCase) names. 28 | public var preserveProtoFieldNames: Bool = false 29 | 30 | /// Whether to use deterministic ordering when serializing. 31 | /// 32 | /// Note that the deterministic serialization is NOT canonical across languages. 33 | /// It is NOT guaranteed to remain stable over time. It is unstable across 34 | /// different builds with schema changes due to unknown fields. Users who need 35 | /// canonical serialization (e.g., persistent storage in a canonical form, 36 | /// fingerprinting, etc.) should define their own canonicalization specification 37 | /// and implement their own serializer rather than relying on this API. 38 | /// 39 | /// If deterministic serialization is requested, map entries will be sorted 40 | /// by keys in lexicographical order. This is an implementation detail 41 | /// and subject to change. 42 | public var useDeterministicOrdering: Bool = false 43 | 44 | public init() {} 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/MathUtils.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/MathUtils.swift - Generally useful mathematical functions 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Generally useful mathematical and arithmetic functions. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | import Foundation 16 | 17 | /// Remainder in standard modular arithmetic (modulo). This coincides with (%) 18 | /// when a > 0. 19 | /// 20 | /// - Parameters: 21 | /// - a: The dividend. Can be positive, 0 or negative. 22 | /// - b: The divisor. This must be positive, and is an error if 0 or negative. 23 | /// - Returns: The unique value r such that 0 <= r < b and b * q + r = a for some q. 24 | internal func mod(_ a: T, _ b: T) -> T { 25 | assert(b > 0) 26 | let r = a % b 27 | return r >= 0 ? r : r + b 28 | } 29 | 30 | /// Quotient in standard modular arithmetic (Euclidean division). This coincides 31 | /// with (/) when a > 0. 32 | /// 33 | /// - Parameters: 34 | /// - a: The dividend. Can be positive, 0 or negative. 35 | /// - b: The divisor. This must be positive, and is an error if 0 or negative. 36 | /// - Returns: The unique value q such that for some 0 <= r < b, b * q + r = a. 37 | internal func div(_ a: T, _ b: T) -> T { 38 | assert(b > 0) 39 | return a >= 0 ? a / b : (a + 1) / b - 1 40 | } 41 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/Message+AnyAdditions.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/Message+AnyAdditions.swift - Any-related Message extensions 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Extends the `Message` type with `Google_Protobuf_Any`-specific behavior. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | extension Message { 16 | /// Initialize this message from the provided `google.protobuf.Any` 17 | /// well-known type. 18 | /// 19 | /// This corresponds to the `unpack` method in the Google C++ API. 20 | /// 21 | /// If the Any object was decoded from Protobuf Binary or JSON 22 | /// format, then the enclosed field data was stored and is not 23 | /// fully decoded until you unpack the Any object into a message. 24 | /// As such, this method will typically need to perform a full 25 | /// deserialization of the enclosed data and can fail for any 26 | /// reason that deserialization can fail. 27 | /// 28 | /// See `Google_Protobuf_Any.unpackTo()` for more discussion. 29 | /// 30 | /// - Parameter unpackingAny: the message to decode. 31 | /// - Parameter extensions: An `ExtensionMap` used to look up and decode any 32 | /// extensions in this message or messages nested within this message's 33 | /// fields. 34 | /// - Parameter options: The BinaryDecodingOptions to use. 35 | /// - Throws: an instance of ``AnyUnpackError``, ``JSONDecodingError``, or 36 | /// ``BinaryDecodingError`` on failure. 37 | public init( 38 | unpackingAny: Google_Protobuf_Any, 39 | extensions: (any ExtensionMap)? = nil, 40 | options: BinaryDecodingOptions = BinaryDecodingOptions() 41 | ) throws { 42 | self.init() 43 | try unpackingAny._storage.unpackTo(target: &self, extensions: extensions, options: options) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/MessageExtension.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/MessageExtension.swift - Extension support 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// A 'Message Extension' is an immutable class object that describes 12 | /// a particular extension field, including string and number 13 | /// identifiers, serialization details, and the identity of the 14 | /// message that is being extended. 15 | /// 16 | // ----------------------------------------------------------------------------- 17 | 18 | /// Type-erased MessageExtension field implementation. 19 | @preconcurrency 20 | public protocol AnyMessageExtension: Sendable { 21 | var fieldNumber: Int { get } 22 | var fieldName: String { get } 23 | var messageType: any Message.Type { get } 24 | func _protobuf_newField(decoder: inout D) throws -> (any AnyExtensionField)? 25 | } 26 | 27 | /// A "Message Extension" relates a particular extension field to 28 | /// a particular message. The generic constraints allow 29 | /// compile-time compatibility checks. 30 | public final class MessageExtension: AnyMessageExtension { 31 | public let fieldNumber: Int 32 | public let fieldName: String 33 | public let messageType: any Message.Type 34 | public init(_protobuf_fieldNumber: Int, fieldName: String) { 35 | self.fieldNumber = _protobuf_fieldNumber 36 | self.fieldName = fieldName 37 | self.messageType = MessageType.self 38 | } 39 | public func _protobuf_newField(decoder: inout D) throws -> (any AnyExtensionField)? { 40 | try FieldType(protobufExtension: self, decoder: &decoder) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/PrivacyInfo.xcprivacy: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSPrivacyTracking 6 | 7 | NSPrivacyAccessedAPITypes 8 | 9 | NSPrivacyCollectedDataTypes 10 | 11 | NSPrivacyTrackingDomains 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/ProtoNameProviding.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/ProtoNameProviding.swift - Support for accessing proto names 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | 11 | /// SwiftProtobuf Internal: Common support looking up field names. 12 | /// 13 | /// Messages conform to this protocol to provide the proto/text and JSON field 14 | /// names for their fields. This allows these names to be pulled out into 15 | /// extensions in separate files so that users can omit them in release builds 16 | /// (reducing bloat and minimizing leaks of field names). 17 | public protocol _ProtoNameProviding { 18 | 19 | /// The mapping between field numbers and proto/JSON field names defined in 20 | /// the conforming message type. 21 | static var _protobuf_nameMap: _NameMap { get } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/ProtobufMap.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/ProtobufMap.swift - Map<> support 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Generic type representing proto map<> fields. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | import Foundation 16 | 17 | /// SwiftProtobuf Internal: Support for Encoding/Decoding. 18 | public struct _ProtobufMap { 19 | public typealias Key = KeyType.BaseType 20 | public typealias Value = ValueType.BaseType 21 | public typealias BaseType = [Key: Value] 22 | } 23 | 24 | /// SwiftProtobuf Internal: Support for Encoding/Decoding. 25 | public struct _ProtobufMessageMap { 26 | public typealias Key = KeyType.BaseType 27 | public typealias Value = ValueType 28 | public typealias BaseType = [Key: Value] 29 | } 30 | 31 | /// SwiftProtobuf Internal: Support for Encoding/Decoding. 32 | public struct _ProtobufEnumMap { 33 | public typealias Key = KeyType.BaseType 34 | public typealias Value = ValueType 35 | public typealias BaseType = [Key: Value] 36 | } 37 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/TextFormatDecodingError.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/TextFormatDecodingError.swift - Protobuf text format decoding errors 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Protobuf text format decoding errors 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | public enum TextFormatDecodingError: Error { 16 | /// Text data could not be parsed 17 | case malformedText 18 | /// A number could not be parsed 19 | case malformedNumber 20 | /// Extraneous data remained after decoding should have been complete 21 | case trailingGarbage 22 | /// The data stopped before we expected 23 | case truncated 24 | /// A string was not valid UTF8 25 | case invalidUTF8 26 | /// The data being parsed does not match the type specified in the proto file 27 | case schemaMismatch 28 | /// Field names were not compiled into the binary 29 | case missingFieldNames 30 | /// A field identifier (name or number) was not found on the message 31 | case unknownField 32 | /// The enum value was not recognized 33 | case unrecognizedEnumValue 34 | /// Text format rejects conflicting values for the same oneof field 35 | case conflictingOneOf 36 | /// An internal error happened while decoding. If this is ever encountered, 37 | /// please file an issue with SwiftProtobuf with as much details as possible 38 | /// for what happened (proto definitions, bytes being decoded (if possible)). 39 | case internalExtensionError 40 | /// Reached the nesting limit for messages within messages while decoding. 41 | case messageDepthLimit 42 | } 43 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/TextFormatDecodingOptions.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/TextFormatDecodingOptions.swift - Text format decoding options 2 | // 3 | // Copyright (c) 2014 - 2021 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Text format decoding options 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | /// Options for TextFormatDecoding. 16 | public struct TextFormatDecodingOptions: Sendable { 17 | /// The maximum nesting of message with messages. The default is 100. 18 | /// 19 | /// To prevent corrupt or malicious messages from causing stack overflows, 20 | /// this controls how deep messages can be nested within other messages 21 | /// while parsing. 22 | public var messageDepthLimit: Int = 100 23 | 24 | /// If unknown fields in the TextFormat should be ignored. If they aren't 25 | /// ignored, an error will be raised if one is encountered. 26 | /// 27 | /// Note: This is a lossy option, enabling it means part of the TextFormat 28 | /// is silently skipped. 29 | public var ignoreUnknownFields: Bool = false 30 | 31 | /// If unknown extension fields in the TextFormat should be ignored. If they 32 | /// aren't ignored, an error will be raised if one is encountered. 33 | /// 34 | /// Note: This is a lossy option, enabling it means part of the TextFormat 35 | /// is silently skipped. 36 | public var ignoreUnknownExtensionFields: Bool = false 37 | 38 | public init() {} 39 | } 40 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/TextFormatEncodingOptions.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/TextFormatEncodingOptions.swift - Text format encoding options 2 | // 3 | // Copyright (c) 2014 - 2019 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Text format encoding options 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | /// Options for TextFormatEncoding. 16 | public struct TextFormatEncodingOptions: Sendable { 17 | 18 | /// Default: Do print unknown fields using numeric notation 19 | public var printUnknownFields: Bool = true 20 | 21 | public init() {} 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/UnknownStorage.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/UnknownStorage.swift - Handling unknown fields 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Proto2 binary coding requires storing and recoding of unknown fields. 12 | /// This simple support class handles that requirement. A property of this type 13 | /// is compiled into every proto2 message. 14 | /// 15 | // ----------------------------------------------------------------------------- 16 | 17 | import Foundation 18 | 19 | /// Contains any unknown fields in a decoded message; that is, fields that were 20 | /// sent on the wire but were not recognized by the generated message 21 | /// implementation or were valid field numbers but with mismatching wire 22 | /// formats (for example, a field encoded as a varint when a fixed32 integer 23 | /// was expected). 24 | public struct UnknownStorage: Equatable, Sendable { 25 | 26 | /// The raw protocol buffer binary-encoded bytes that represent the unknown 27 | /// fields of a decoded message. 28 | public private(set) var data = Data() 29 | 30 | public init() {} 31 | 32 | internal mutating func append(protobufData: Data) { 33 | data.append(protobufData) 34 | } 35 | 36 | public func traverse(visitor: inout V) throws { 37 | if !data.isEmpty { 38 | try visitor.visitUnknown(bytes: data) 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/UnsafeRawPointer+Shims.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/UnsafeRawPointer+Shims.swift - Shims for UnsafeRawPointer and friends 2 | // 3 | // Copyright (c) 2019 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Shims for UnsafeRawPointer and friends. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | extension UnsafeRawPointer { 16 | /// A shim subscript for UnsafeRawPointer aiming to maintain code consistency. 17 | /// 18 | /// We can remove this shim when we rewrite the code to use buffer pointers. 19 | internal subscript(_ offset: Int) -> UInt8 { 20 | get { 21 | self.load(fromByteOffset: offset, as: UInt8.self) 22 | } 23 | } 24 | } 25 | 26 | extension UnsafeMutableRawPointer { 27 | /// A shim subscript for UnsafeMutableRawPointer aiming to maintain code consistency. 28 | /// 29 | /// We can remove this shim when we rewrite the code to use buffer pointers. 30 | internal subscript(_ offset: Int) -> UInt8 { 31 | get { 32 | self.load(fromByteOffset: offset, as: UInt8.self) 33 | } 34 | set { 35 | self.storeBytes(of: newValue, toByteOffset: offset, as: UInt8.self) 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Sources/SwiftProtobuf/Version.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobuf/Version.swift - Runtime Version info 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// A interface for exposing the version of the runtime. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | import Foundation 16 | 17 | // Expose version information about the library. 18 | public struct Version { 19 | /// Major version. 20 | public static let major = 1 21 | /// Minor version. 22 | public static let minor = 30 23 | /// Revision number. 24 | public static let revision = 0 25 | 26 | /// String form of the version number. 27 | public static let versionString = "\(major).\(minor).\(revision)" 28 | } 29 | -------------------------------------------------------------------------------- /Sources/SwiftProtobufPluginLibrary/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(SwiftProtobufPluginLibrary 2 | Array+Extensions.swift 3 | CodePrinter.swift 4 | Descriptor+Extensions.swift 5 | Descriptor.swift 6 | FieldNumbers.swift 7 | Google_Protobuf_Compiler_CodeGeneratorResponse+Extensions.swift 8 | Google_Protobuf_SourceCodeInfo+Extensions.swift 9 | NamingUtils.swift 10 | plugin.pb.swift 11 | ProtoFileToModuleMappings.swift 12 | ProvidesLocationPath.swift 13 | ProvidesSourceCodeLocation.swift 14 | SwiftLanguage.swift 15 | SwiftProtobufInfo.swift 16 | SwiftProtobufNamer.swift 17 | swift_protobuf_module_mappings.pb.swift 18 | UnicodeScalar+Extensions.swift) 19 | target_link_libraries(SwiftProtobufPluginLibrary PUBLIC 20 | SwiftProtobuf) 21 | 22 | 23 | install(TARGETS SwiftProtobufPluginLibrary 24 | ARCHIVE DESTINATION lib/swift$<$>:_static>/$ 25 | LIBRARY DESTINATION lib/swift$<$>:_static>/$ 26 | RUNTIME DESTINATION bin) 27 | get_swift_host_arch(swift_arch) 28 | install(FILES 29 | $/SwiftProtobufPluginLibrary.swiftdoc 30 | $/SwiftProtobufPluginLibrary.swiftmodule 31 | DESTINATION lib/swift$<$>:_static>/$/${swift_arch}) 32 | set_property(GLOBAL APPEND PROPERTY Protobuf_EXPORTS SwiftProtobufPluginLibrary) 33 | -------------------------------------------------------------------------------- /Sources/SwiftProtobufPluginLibrary/CodeGeneratorParameter.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobufPluginLibrary/CodeGeneratorParameter.swift 2 | // 3 | // Copyright (c) 2014 - 2023 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// This provides the basic interface for a CodeGeneratorParameter. This is 12 | /// passed to the `CodeGenerator` to get any command line options. 13 | /// 14 | // ----------------------------------------------------------------------------- 15 | 16 | import Foundation 17 | 18 | /// The the generator specific parameter that was passed to the protocol 19 | /// compiler invocation. The protocol buffer compiler supports providing 20 | /// parameters via the `--[LANG]_out` or `--[LANG]_opt` command line flags. 21 | /// The compiler will relay those through as a _parameter_ string. 22 | public protocol CodeGeneratorParameter { 23 | /// The raw value from the compiler as a single string, if multiple values 24 | /// were passed, they are joined into a single string. See `parsedPairs` as 25 | /// that is likely a better option for consuming the parameters. 26 | var parameter: String { get } 27 | 28 | /// The protocol buffer compiler will combine multiple `--[LANG]_opt` 29 | /// directives into a "single" parameter by joining them with commas. This 30 | /// vends the parameter split back back out into the individual arguments: 31 | /// i.e., 32 | /// "foo=bar,baz,mumble=blah" 33 | /// becomes: 34 | /// [ 35 | /// (key: "foo", value: "bar"), 36 | /// (key: "baz", value: ""), 37 | /// (key: "mumble", value: "blah") 38 | /// ] 39 | var parsedPairs: [(key: String, value: String)] { get } 40 | } 41 | -------------------------------------------------------------------------------- /Sources/SwiftProtobufPluginLibrary/Docs.docc/index.md: -------------------------------------------------------------------------------- 1 | # ``SwiftProtobufPluginLibrary`` 2 | 3 | A reusable framework for building `protoc` plugins in Swift. 4 | 5 | ## Overview 6 | 7 | The `protoc-gen-swift` program is run by `protoc` to generate Swift code 8 | from the parsed proto data. 9 | This library encapsulates many of the common elements needed to build 10 | such programs. 11 | It's separated out here so that other people can reuse it. 12 | 13 | -------------------------------------------------------------------------------- /Sources/SwiftProtobufPluginLibrary/FieldNumbers.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobufPluginLibrary/FieldNumbers.swift - Proto Field numbers 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Field numbers needed by SwiftProtobufPluginLibrary since they currently aren't generated. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | import Foundation 16 | import SwiftProtobuf 17 | 18 | extension Google_Protobuf_FileDescriptorProto { 19 | struct FieldNumbers { 20 | static let messageType: Int = 4 21 | static let enumType: Int = 5 22 | static let service: Int = 6 23 | static let `extension`: Int = 7 24 | } 25 | } 26 | 27 | extension Google_Protobuf_DescriptorProto { 28 | struct FieldNumbers { 29 | static let field: Int = 2 30 | static let nestedType: Int = 3 31 | static let enumType: Int = 4 32 | static let extensionRange: Int = 4 33 | static let `extension`: Int = 6 34 | static let oneofDecl: Int = 8 35 | } 36 | } 37 | 38 | extension Google_Protobuf_EnumDescriptorProto { 39 | struct FieldNumbers { 40 | static let value: Int = 2 41 | } 42 | } 43 | 44 | extension Google_Protobuf_ServiceDescriptorProto { 45 | struct FieldNumbers { 46 | static let method: Int = 2 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Sources/SwiftProtobufPluginLibrary/GeneratorOutputs.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobufPluginLibrary/GeneratorOutputs.swift 2 | // 3 | // Copyright (c) 2014 - 2023 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// This provides the basic interface for providing the generation outputs. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | import Foundation 16 | 17 | /// Abstract interface for receiving generation outputs. 18 | public protocol GeneratorOutputs { 19 | /// Add the a file with the given `name` and `contents` to the outputs. 20 | /// 21 | /// - Parameters: 22 | /// - fileName: The name of the file. 23 | /// - contents: The body of the file. 24 | /// 25 | /// - Throws May throw errors for duplicate file names or any other problem. 26 | /// Generally `CodeGenerator`s do *not* need to catch these, and instead 27 | /// they are ripple all the way out to the code calling the 28 | /// `CodeGenerator`. 29 | func add(fileName: String, contents: String) throws 30 | 31 | // TODO: Consider adding apis to stream things like C++ protobuf does? 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftProtobufPluginLibrary/Google_Protobuf_Compiler_CodeGeneratorResponse+Extensions.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobufPluginLibrary/Google_Protobuf_Compiler_CodeGeneratorResponse+Extensions.swift - CodeGeneratorResponse extensions 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Extensions to `CodeGeneratorResponse` provide some simple helpers. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | extension Google_Protobuf_Compiler_CodeGeneratorResponse { 16 | /// Helper to make a response with an error. 17 | public init(error: String) { 18 | self.init() 19 | self.error = error 20 | } 21 | 22 | /// Helper to make a response with a set of files 23 | @available(*, deprecated, message: "Please move your plugin to the CodeGenerator interface") 24 | public init(files: [Google_Protobuf_Compiler_CodeGeneratorResponse.File]) { 25 | self.init(files: files, supportedFeatures: []) 26 | } 27 | 28 | /// Helper to make a response with a set of files and supported features. 29 | @available(*, deprecated, message: "Please move your plugin to the CodeGenerator interface") 30 | public init( 31 | files: [Google_Protobuf_Compiler_CodeGeneratorResponse.File], 32 | supportedFeatures: [Google_Protobuf_Compiler_CodeGeneratorResponse.Feature] = [] 33 | ) { 34 | self.init() 35 | self.file = files 36 | self.supportedFeatures = supportedFeatures.reduce(0) { $0 | UInt64($1.rawValue) } 37 | } 38 | } 39 | 40 | extension Google_Protobuf_Compiler_CodeGeneratorResponse.File { 41 | /// Helper to make a Response.File with specific content. 42 | public init(name: String, content: String) { 43 | self.init() 44 | self.name = name 45 | self.content = content 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Sources/SwiftProtobufPluginLibrary/Google_Protobuf_Edition+Extensions.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobufPluginLibrary/Google_Protobuf_Edition+Extensions.swift - Google_Protobuf_Edition extensions 2 | // 3 | // Copyright (c) 2014 - 2024 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Extensions to `Google_Protobuf_Edition` provide some simple helpers. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | import Foundation 16 | import SwiftProtobuf 17 | 18 | /// The spec for editions calls out them being ordered and comparable. 19 | /// https://github.com/protocolbuffers/protobuf/blob/main/docs/design/editions/edition-naming.md 20 | #if compiler(>=6) 21 | extension Google_Protobuf_Edition: Comparable { 22 | public static func < (lhs: Google_Protobuf_Edition, rhs: Google_Protobuf_Edition) -> Bool { 23 | lhs.rawValue < rhs.rawValue 24 | } 25 | } 26 | #else 27 | extension Google_Protobuf_Edition: Comparable { 28 | public static func < (lhs: Google_Protobuf_Edition, rhs: Google_Protobuf_Edition) -> Bool { 29 | lhs.rawValue < rhs.rawValue 30 | } 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /Sources/SwiftProtobufPluginLibrary/PluginLibEditionDefaults.swift: -------------------------------------------------------------------------------- 1 | // See Makefile how this is generated. 2 | // swift-format-ignore-file 3 | import Foundation 4 | let bundledFeatureSetDefaultBytes: [UInt8] = [ 5 | 0x0a, 0x17, 0x18, 0x84, 0x07, 0x22, 0x00, 0x2a, 0x10, 0x08, 0x01, 0x10, 6 | 0x02, 0x18, 0x02, 0x20, 0x03, 0x28, 0x01, 0x30, 0x02, 0x38, 0x02, 0x40, 7 | 0x01, 0x0a, 0x17, 0x18, 0xe7, 0x07, 0x22, 0x00, 0x2a, 0x10, 0x08, 0x02, 8 | 0x10, 0x01, 0x18, 0x01, 0x20, 0x02, 0x28, 0x01, 0x30, 0x01, 0x38, 0x02, 9 | 0x40, 0x01, 0x0a, 0x17, 0x18, 0xe8, 0x07, 0x22, 0x0c, 0x08, 0x01, 0x10, 10 | 0x01, 0x18, 0x01, 0x20, 0x02, 0x28, 0x01, 0x30, 0x01, 0x2a, 0x04, 0x38, 11 | 0x02, 0x40, 0x01, 0x20, 0xe6, 0x07, 0x28, 0xe8, 0x07 12 | ] 13 | -------------------------------------------------------------------------------- /Sources/SwiftProtobufPluginLibrary/PrivacyInfo.xcprivacy: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSPrivacyTracking 6 | 7 | NSPrivacyAccessedAPITypes 8 | 9 | NSPrivacyCollectedDataTypes 10 | 11 | NSPrivacyTrackingDomains 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Sources/SwiftProtobufPluginLibrary/ProtoCompilerContext.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobufPluginLibrary/ProtoCompilerContext.swift 2 | // 3 | // Copyright (c) 2014 - 2023 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// This provides some basic interface about the protocol buffer compiler 12 | /// being used to generate. 13 | /// 14 | // ----------------------------------------------------------------------------- 15 | 16 | import Foundation 17 | 18 | /// Abstact interface to get information about the protocol buffer compiler 19 | /// being used for generation. 20 | public protocol ProtoCompilerContext { 21 | /// The version of the protocol buffer compiler (if it was provided in the 22 | /// generation request). 23 | var version: Google_Protobuf_Compiler_Version? { get } 24 | } 25 | -------------------------------------------------------------------------------- /Sources/SwiftProtobufPluginLibrary/ProvidesLocationPath.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobufPluginLibrary/ProvidesLocationPath.swift - Proto Field numbers 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | 11 | import Foundation 12 | 13 | /// Protocol that all the Descriptors conform to for original .proto file 14 | /// location lookup. 15 | public protocol ProvidesLocationPath { 16 | /// Updates `path` to the source location of the complete extent of 17 | /// the object conforming to this protocol. This is a replacement for 18 | /// `GetSourceLocation()` in the C++ Descriptor apis. 19 | func getLocationPath(path: inout IndexPath) 20 | /// Returns the File this conforming object is in. 21 | var file: FileDescriptor! { get } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SwiftProtobufPluginLibrary/ProvidesSourceCodeLocation.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobufPluginLibrary/ProvidesSourceCodeLocation.swift - SourceCodeInfo.Location provider 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | 11 | import Foundation 12 | import SwiftProtobuf 13 | 14 | /// Protocol that all the Descriptors conform to for original .proto file 15 | /// location lookup. 16 | public protocol ProvidesSourceCodeLocation { 17 | /// Returns the Location of a given object (Descriptor). 18 | var sourceCodeInfoLocation: Google_Protobuf_SourceCodeInfo.Location? { get } 19 | } 20 | 21 | /// Default implementation for things that support ProvidesLocationPath. 22 | extension ProvidesSourceCodeLocation where Self: ProvidesLocationPath { 23 | public var sourceCodeInfoLocation: Google_Protobuf_SourceCodeInfo.Location? { 24 | var path = IndexPath() 25 | getLocationPath(path: &path) 26 | return file.sourceCodeInfoLocation(path: path) 27 | } 28 | } 29 | 30 | extension ProvidesSourceCodeLocation { 31 | /// Helper to get a source comments as a string. 32 | public func protoSourceComments( 33 | commentPrefix: String = "///", 34 | leadingDetachedPrefix: String? = nil 35 | ) -> String { 36 | guard let loc = sourceCodeInfoLocation else { return String() } 37 | return loc.asSourceComment( 38 | commentPrefix: commentPrefix, 39 | leadingDetachedPrefix: leadingDetachedPrefix 40 | ) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Sources/SwiftProtobufPluginLibrary/StandardErrorOutputStream.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobufPluginLibrary/StandardErrorOutputStream.swift 2 | // 3 | // Copyright (c) 2014 - 2023 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | 10 | import Foundation 11 | 12 | class StandardErrorOutputStream: TextOutputStream { 13 | func write(_ string: String) { 14 | if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) { 15 | try! FileHandle.standardError.write(contentsOf: Data(string.utf8)) 16 | } else { 17 | FileHandle.standardError.write(Data(string.utf8)) 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Sources/SwiftProtobufPluginLibrary/StringUtils.swift: -------------------------------------------------------------------------------- 1 | // Sources/SwiftProtobufPluginLibrary/StringUtils.swift - String processing utilities 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | 11 | import Foundation 12 | 13 | @inlinable 14 | func trimWhitespace(_ s: String) -> String { 15 | s.trimmingCharacters(in: .whitespacesAndNewlines) 16 | } 17 | 18 | @inlinable 19 | func trimWhitespace(_ s: String.SubSequence) -> String { 20 | s.trimmingCharacters(in: .whitespacesAndNewlines) 21 | } 22 | -------------------------------------------------------------------------------- /Sources/SwiftProtobufTestHelpers/Descriptor+TestHelpers.swift: -------------------------------------------------------------------------------- 1 | // Sources/protoc-gen-swift/Descriptor+TestHelpers.swift - Additions to Descriptors 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | 11 | import SwiftProtobuf 12 | 13 | extension Google_Protobuf_FileDescriptorProto { 14 | public init(name: String, dependencies: [String] = [], publicDependencies: [Int32] = [], package: String = "") { 15 | for idx in publicDependencies { precondition(Int(idx) <= dependencies.count) } 16 | self.init() 17 | self.name = name 18 | self.dependency = dependencies 19 | self.publicDependency = publicDependencies 20 | self.package = package 21 | } 22 | public init(textFormatStrings: [String]) throws { 23 | let s = textFormatStrings.joined(separator: "\n") + "\n" 24 | try self.init(textFormatString: s) 25 | } 26 | } 27 | 28 | extension Google_Protobuf_FileDescriptorSet { 29 | public init(files: [Google_Protobuf_FileDescriptorProto]) { 30 | self.init() 31 | self.file = files 32 | } 33 | public init(file: Google_Protobuf_FileDescriptorProto) { 34 | self.init() 35 | self.file = [file] 36 | } 37 | } 38 | 39 | extension Google_Protobuf_EnumValueDescriptorProto { 40 | public init(name: String, number: Int32) { 41 | self.init() 42 | self.name = name 43 | self.number = number 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/protoc-gen-swift/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(protoc-gen-swift 2 | CommandLine+Extensions.swift 3 | Descriptor+Extensions.swift 4 | EnumGenerator.swift 5 | ExtensionSetGenerator.swift 6 | FieldGenerator.swift 7 | FileGenerator.swift 8 | FileIo.swift 9 | GenerationError.swift 10 | GeneratorOptions.swift 11 | Google_Protobuf_FileDescriptorProto+Extensions.swift 12 | main.swift 13 | MessageFieldGenerator.swift 14 | MessageGenerator.swift 15 | MessageStorageClassGenerator.swift 16 | MessageStorageDecision.swift 17 | OneofGenerator.swift 18 | Range+Extensions.swift 19 | StringUtils.swift 20 | Version.swift) 21 | target_link_libraries(protoc-gen-swift PRIVATE 22 | SwiftProtobufPluginLibrary 23 | SwiftProtobuf) 24 | 25 | 26 | install(TARGETS protoc-gen-swift 27 | DESTINATION bin) 28 | set_property(GLOBAL APPEND PROPERTY Protobuf_EXPORTS protoc-gen-swift) 29 | -------------------------------------------------------------------------------- /Sources/protoc-gen-swift/CommandLine+Extensions.swift: -------------------------------------------------------------------------------- 1 | // Sources/protoc-gen-swift/CommandLine+Extensions - Additions to CommandLine 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | 11 | import Foundation 12 | 13 | extension CommandLine { 14 | 15 | static var programName: String { 16 | // Get the command-line arguments passed to this process in a non mutable 17 | // form. Idea from https://github.com/swiftlang/swift/issues/66213 18 | let safeArgs: [String] = 19 | UnsafeBufferPointer(start: unsafeArgv, count: Int(argc)).compactMap { 20 | String(validatingUTF8: $0!) 21 | } 22 | 23 | guard let base = safeArgs.first else { 24 | return "protoc-gen-swift" 25 | } 26 | // Strip it down to just the leaf if it was a path. 27 | let parts = splitPath(pathname: base) 28 | return parts.base + parts.suffix 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Sources/protoc-gen-swift/FileIo.swift: -------------------------------------------------------------------------------- 1 | // Sources/protoc-gen-swift/FileIo.swift - File I/O utilities 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Some basic utilities to handle writing to Stderr, Stdout, and reading/writing 12 | /// blocks of data from/to a file on disk. 13 | /// 14 | // ----------------------------------------------------------------------------- 15 | import Foundation 16 | 17 | class Stderr { 18 | static func print(_ s: String) { 19 | let out = "\(CommandLine.programName): \(s)\n" 20 | if let data = out.data(using: .utf8) { 21 | FileHandle.standardError.write(data) 22 | } 23 | } 24 | } 25 | 26 | func readFileData(filename: String) throws -> Data { 27 | let url = URL(fileURLWithPath: filename) 28 | return try Data(contentsOf: url) 29 | } 30 | -------------------------------------------------------------------------------- /Sources/protoc-gen-swift/GenerationError.swift: -------------------------------------------------------------------------------- 1 | // Sources/protoc-gen-swift/GenerationError.swift - Generation errors 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | 11 | enum GenerationError: Error, CustomStringConvertible { 12 | /// Raised when parsing the parameter string and found an unknown key. 13 | case unknownParameter(name: String) 14 | /// Raised when a parameter was given an invalid value. 15 | case invalidParameterValue(name: String, value: String) 16 | /// Raised to wrap another error but provide a context message. 17 | case wrappedError(message: String, error: any Error) 18 | /// Raised with an specific message 19 | case message(message: String) 20 | 21 | var description: String { 22 | switch self { 23 | case .unknownParameter(let name): 24 | return "Unknown generation parameter '\(name)'" 25 | case .invalidParameterValue(let name, let value): 26 | return "Unknown value for generation parameter '\(name)': '\(value)'" 27 | case .wrappedError(let message, let error): 28 | return "\(message): \(error)" 29 | case .message(let message): 30 | return message 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/protoc-gen-swift/Google_Protobuf_FileDescriptorProto+Extensions.swift: -------------------------------------------------------------------------------- 1 | // Sources/protoc-gen-swift/Google_Protobuf_FileDescriptorProto+Extensions.swift - Descriptor extensions 2 | // 3 | // Copyright (c) 2014 - 2017 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Extensions to `FileDescriptorProto` that provide Swift-generation-specific 12 | /// functionality. 13 | /// 14 | // ----------------------------------------------------------------------------- 15 | 16 | import SwiftProtobuf 17 | import SwiftProtobufPluginLibrary 18 | 19 | extension Google_Protobuf_FileDescriptorProto { 20 | // Field numbers used to collect .proto file comments. 21 | struct FieldNumbers { 22 | static let syntax: Int = 12 23 | static let edition: Int = 14 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Sources/protoc-gen-swift/ProvidesDeprecationComment+Extensions.swift: -------------------------------------------------------------------------------- 1 | // Sources/protoc-gen-swift/ProvidesSourceCodeLocation+Extensions.swift 2 | // 3 | // Copyright (c) 2014 - 2024 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | 11 | import Foundation 12 | import SwiftProtobufPluginLibrary 13 | 14 | extension ProvidesSourceCodeLocation { 15 | func protoSourceComments( 16 | generatorOptions: GeneratorOptions, 17 | commentPrefix: String = "///", 18 | leadingDetachedPrefix: String? = nil 19 | ) -> String { 20 | if generatorOptions.experimentalStripNonfunctionalCodegen { 21 | // Comments are inherently non-functional, and may change subtly on 22 | // transformations. 23 | return String() 24 | } 25 | return protoSourceComments( 26 | commentPrefix: commentPrefix, 27 | leadingDetachedPrefix: leadingDetachedPrefix 28 | ) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Sources/protoc-gen-swift/ProvidesSourceCodeLocation+Extensions.swift: -------------------------------------------------------------------------------- 1 | // Sources/protoc-gen-swift/ProvidesDeprecationComment+Extensions.swift 2 | // 3 | // Copyright (c) 2014 - 2024 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | 11 | import Foundation 12 | import SwiftProtobufPluginLibrary 13 | 14 | extension ProvidesDeprecationComment where Self: ProvidesSourceCodeLocation { 15 | func protoSourceCommentsWithDeprecation( 16 | generatorOptions: GeneratorOptions, 17 | commentPrefix: String = "///", 18 | leadingDetachedPrefix: String? = nil 19 | ) -> String { 20 | if generatorOptions.experimentalStripNonfunctionalCodegen { 21 | // Comments are inherently non-functional, and may change subtly on 22 | // transformations. 23 | return deprecationComment(commentPrefix: commentPrefix) 24 | } 25 | 26 | return protoSourceCommentsWithDeprecation( 27 | commentPrefix: commentPrefix, 28 | leadingDetachedPrefix: leadingDetachedPrefix 29 | ) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/protoc-gen-swift/Version.swift: -------------------------------------------------------------------------------- 1 | // Sources/protoc-gen-swift/Version.swift - Protoc plugin version info 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// A simple static object that provides information about the plugin. 12 | /// 13 | // ---------------------------------------------------------------------------- 14 | 15 | import SwiftProtobuf 16 | 17 | struct Version { 18 | // The "compatibility version" of the runtime library, which must be 19 | // incremented every time a breaking change (either behavioral or 20 | // API-changing) is introduced. 21 | // 22 | // We guarantee that generated protos that contain this version token will 23 | // be compatible with the runtime library containing the matching token. 24 | // Therefore, this number (and the corresponding one in the runtime 25 | // library) should not be updated for *every* version of Swift Protobuf, 26 | // but only for those that introduce breaking changes (either behavioral 27 | // or API-changing). 28 | static let compatibilityVersion = 2 29 | 30 | static let copyright = "Copyright (C) 2014-2017 Apple Inc. and the project authors" 31 | } 32 | -------------------------------------------------------------------------------- /SwiftProtobuf.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'SwiftProtobuf' 3 | s.version = '1.30.0' 4 | s.license = { :type => 'Apache 2.0', :file => 'LICENSE.txt' } 5 | s.summary = 'Swift Protobuf Runtime Library' 6 | s.homepage = 'https://github.com/apple/swift-protobuf' 7 | s.author = 'Apple Inc.' 8 | s.source = { :git => 'https://github.com/apple/swift-protobuf.git', :tag => s.version } 9 | 10 | s.requires_arc = true 11 | s.ios.deployment_target = '11.0' 12 | s.osx.deployment_target = '10.13' 13 | s.tvos.deployment_target = '11.0' 14 | s.watchos.deployment_target = '4.0' 15 | s.visionos.deployment_target = "1.0" 16 | 17 | s.cocoapods_version = '>= 1.13.0' 18 | 19 | s.source_files = 'Sources/SwiftProtobuf/**/*.swift' 20 | s.resource_bundle = {'SwiftProtobuf' => ['Sources/SwiftProtobuf/PrivacyInfo.xcprivacy']} 21 | 22 | s.swift_versions = ['5.0'] 23 | end 24 | -------------------------------------------------------------------------------- /Tests/SwiftProtobufPluginLibraryTests/PluginLibTestingEditionDefaults.swift: -------------------------------------------------------------------------------- 1 | // See Makefile how this is generated. 2 | // swift-format-ignore-file 3 | import Foundation 4 | let testFeatureSetDefaultBytes: [UInt8] = [ 5 | 0x0a, 0x29, 0x18, 0x84, 0x07, 0x22, 0x04, 0xfa, 0xf0, 0x04, 0x00, 0x2a, 6 | 0x1e, 0x08, 0x01, 0x10, 0x02, 0x18, 0x02, 0x20, 0x03, 0x28, 0x01, 0x30, 7 | 0x02, 0x38, 0x02, 0x40, 0x01, 0xfa, 0xf0, 0x04, 0x0a, 0x08, 0x01, 0x10, 8 | 0x01, 0x18, 0x01, 0x20, 0x01, 0x28, 0x01, 0x0a, 0x29, 0x18, 0xe7, 0x07, 9 | 0x22, 0x04, 0xfa, 0xf0, 0x04, 0x00, 0x2a, 0x1e, 0x08, 0x02, 0x10, 0x01, 10 | 0x18, 0x01, 0x20, 0x02, 0x28, 0x01, 0x30, 0x01, 0x38, 0x02, 0x40, 0x01, 11 | 0xfa, 0xf0, 0x04, 0x0a, 0x08, 0x01, 0x10, 0x01, 0x18, 0x01, 0x20, 0x01, 12 | 0x28, 0x01, 0x0a, 0x29, 0x18, 0xe8, 0x07, 0x22, 0x1a, 0x08, 0x01, 0x10, 13 | 0x01, 0x18, 0x01, 0x20, 0x02, 0x28, 0x01, 0x30, 0x01, 0xfa, 0xf0, 0x04, 14 | 0x0a, 0x08, 0x01, 0x10, 0x01, 0x18, 0x01, 0x20, 0x01, 0x28, 0x01, 0x2a, 15 | 0x08, 0x38, 0x02, 0x40, 0x01, 0xfa, 0xf0, 0x04, 0x00, 0x20, 0xe6, 0x07, 16 | 0x28, 0xe8, 0x07 17 | ] 18 | -------------------------------------------------------------------------------- /Tests/SwiftProtobufTests/Data+TestHelpers.swift: -------------------------------------------------------------------------------- 1 | // Tests/SwiftProtobufTests/TestHelpers.swift - Test helpers 2 | // 3 | // Copyright (c) 2014 - 2019 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | 11 | import Foundation 12 | 13 | @testable import SwiftProtobuf 14 | 15 | /// Helpers for building up wire encoding in tests. 16 | extension Data { 17 | mutating func appendStartField(fieldNumber: Int, wireFormat: WireFormat) { 18 | appendStartField(tag: FieldTag(fieldNumber: fieldNumber, wireFormat: wireFormat)) 19 | } 20 | 21 | mutating func appendStartField(tag: FieldTag) { 22 | appendVarInt(value: UInt64(tag.rawValue)) 23 | } 24 | 25 | mutating func appendVarInt(value: UInt64) { 26 | var v = value 27 | while v > 127 { 28 | append(UInt8(v & 0x7f | 0x80)) 29 | v >>= 7 30 | } 31 | append(UInt8(v)) 32 | } 33 | 34 | mutating func appendVarInt(value: Int64) { 35 | appendVarInt(value: UInt64(bitPattern: value)) 36 | } 37 | 38 | mutating func appendVarInt(value: Int) { 39 | appendVarInt(value: Int64(value)) 40 | } 41 | 42 | mutating func appendVarInt(value: Int32) { 43 | appendVarInt(value: Int64(value)) 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Tests/SwiftProtobufTests/Test_Api.swift: -------------------------------------------------------------------------------- 1 | // Tests/SwiftProtobufTests/Test_Api.swift - Exercise API type 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Since API is purely compiled (there is no hand-coding 12 | /// in it) this is a fairly thin test just to ensure that the proto 13 | /// does get into the runtime. 14 | /// 15 | // ----------------------------------------------------------------------------- 16 | 17 | import Foundation 18 | import SwiftProtobuf 19 | import XCTest 20 | 21 | final class Test_Api: XCTestCase, PBTestHelpers { 22 | typealias MessageTestType = Google_Protobuf_Api 23 | 24 | func testExists() { 25 | assertEncode([10, 7, 97, 112, 105, 78, 97, 109, 101, 34, 1, 49]) { (o: inout MessageTestType) in 26 | o.name = "apiName" 27 | o.version = "1" 28 | } 29 | } 30 | 31 | func testInitializer() throws { 32 | var m = MessageTestType() 33 | m.name = "apiName" 34 | var method = Google_Protobuf_Method() 35 | method.name = "method1" 36 | m.methods = [method] 37 | var option = Google_Protobuf_Option() 38 | option.name = "option1" 39 | option.value = try Google_Protobuf_Any(message: Google_Protobuf_StringValue("value1")) 40 | m.options = [option] 41 | m.version = "1.0.0" 42 | m.syntax = .proto3 43 | 44 | XCTAssertEqual( 45 | try m.jsonString(), 46 | "{\"name\":\"apiName\",\"methods\":[{\"name\":\"method1\"}],\"options\":[{\"name\":\"option1\",\"value\":{\"@type\":\"type.googleapis.com/google.protobuf.StringValue\",\"value\":\"value1\"}}],\"version\":\"1.0.0\",\"syntax\":\"SYNTAX_PROTO3\"}" 47 | ) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Tests/SwiftProtobufTests/Test_Empty.swift: -------------------------------------------------------------------------------- 1 | // Tests/SwiftProtobufTests/Test_Empty.swift - Verify well-known empty message 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Since Empty is purely compiled (there is no hand-coding 12 | /// in it) this is a fairly thin test just to ensure that the proto 13 | /// does get into the runtime. 14 | /// 15 | // ----------------------------------------------------------------------------- 16 | 17 | import Foundation 18 | import SwiftProtobuf 19 | import XCTest 20 | 21 | final class Test_Empty: XCTestCase, PBTestHelpers { 22 | typealias MessageTestType = Google_Protobuf_Empty 23 | 24 | func testExists() throws { 25 | let e = Google_Protobuf_Empty() 26 | XCTAssertEqual([UInt8](), try e.serializedBytes()) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tests/SwiftProtobufTests/Test_FieldOrdering.swift: -------------------------------------------------------------------------------- 1 | // Tests/SwiftProtobufTests/Test_FieldOrdering.swift - Check ordering of binary fields 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Verify that binary protobuf serialization correctly emits fields 12 | /// in order by field number. This is especially interesting when there 13 | /// are extensions and/or unknown fields involved. 14 | /// 15 | /// Proper ordering is recommended but not critical for writers since all 16 | /// readers are required to accept fields out of order. 17 | /// 18 | // ----------------------------------------------------------------------------- 19 | 20 | import Foundation 21 | import XCTest 22 | 23 | final class Test_FieldOrdering: XCTestCase { 24 | typealias MessageTestType = SwiftProtoTesting_Order_TestFieldOrderings 25 | 26 | func test_FieldOrdering() throws { 27 | var m = MessageTestType() 28 | m.myString = "abc" 29 | m.myInt = 1 30 | m.myFloat = 1.0 31 | var nest = MessageTestType.NestedMessage() 32 | nest.oo = 1 33 | nest.bb = 2 34 | m.optionalNestedMessage = nest 35 | m.SwiftProtoTesting_Order_myExtensionInt = 12 36 | m.SwiftProtoTesting_Order_myExtensionString = "def" 37 | m.oneofInt32 = 7 38 | 39 | let encoded1: [UInt8] = try m.serializedBytes() 40 | XCTAssertEqual( 41 | [ 42 | 8, 1, 40, 12, 80, 7, 90, 3, 97, 98, 99, 146, 3, 3, 100, 101, 102, 173, 6, 0, 0, 128, 63, 194, 12, 4, 8, 43 | 2, 16, 1, 44 | ], 45 | encoded1 46 | ) 47 | 48 | m.oneofInt64 = 8 49 | let encoded2: [UInt8] = try m.serializedBytes() 50 | XCTAssertEqual( 51 | [ 52 | 8, 1, 40, 12, 90, 3, 97, 98, 99, 146, 3, 3, 100, 101, 102, 224, 3, 8, 173, 6, 0, 0, 128, 63, 194, 12, 4, 53 | 8, 2, 16, 1, 54 | ], 55 | encoded2 56 | ) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Tests/SwiftProtobufTests/Test_JSON_Group.swift: -------------------------------------------------------------------------------- 1 | // Tests/SwiftProtobufTests/Test_JSON_Group.swift - Exercise JSON coding for groups 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Google has not specified a JSON coding for groups. The C++ implementation 12 | /// fails when decoding a JSON string that contains a group, so we verify that 13 | /// we do the same for consistency. 14 | /// 15 | // ----------------------------------------------------------------------------- 16 | 17 | import Foundation 18 | import XCTest 19 | 20 | final class Test_JSON_Group: XCTestCase, PBTestHelpers { 21 | typealias MessageTestType = SwiftProtoTesting_TestAllTypes 22 | 23 | func testOptionalGroup() { 24 | assertJSONEncode("{\"optionalgroup\":{\"a\":3}}") { (o: inout MessageTestType) in 25 | o.optionalGroup.a = 3 26 | } 27 | } 28 | 29 | func testRepeatedGroup() { 30 | assertJSONEncode("{\"repeatedgroup\":[{\"a\":1},{\"a\":2}]}") { (o: inout MessageTestType) in 31 | let one = SwiftProtoTesting_TestAllTypes.RepeatedGroup.with { 32 | $0.a = 1 33 | } 34 | let two = SwiftProtoTesting_TestAllTypes.RepeatedGroup.with { 35 | $0.a = 2 36 | } 37 | o.repeatedGroup = [one, two] 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Tests/SwiftProtobufTests/Test_Merge.swift: -------------------------------------------------------------------------------- 1 | // Tests/SwiftProtobufTests/Test_Merge.swift - Verify merging messages 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | 11 | import Foundation 12 | import SwiftProtobuf 13 | import XCTest 14 | 15 | final class Test_Merge: XCTestCase, PBTestHelpers { 16 | typealias MessageTestType = SwiftProtoTesting_Proto3_TestAllTypes 17 | 18 | func testMergeSimple() throws { 19 | var m1 = SwiftProtoTesting_Proto3_TestAllTypes() 20 | m1.optionalInt32 = 100 21 | 22 | var m2 = SwiftProtoTesting_Proto3_TestAllTypes() 23 | m2.optionalInt64 = 1000 24 | 25 | do { 26 | try m1.merge(serializedBytes: m2.serializedBytes() as [UInt8]) 27 | XCTAssertEqual(m1.optionalInt32, 100) 28 | XCTAssertEqual(m1.optionalInt64, 1000) 29 | } catch let e { 30 | XCTFail("Merge should not have thrown, but it did: \(e)") 31 | } 32 | } 33 | 34 | func testMergePreservesValueSemantics() throws { 35 | var original = SwiftProtoTesting_Proto3_TestAllTypes() 36 | original.optionalInt32 = 100 37 | let copied = original 38 | 39 | var toMerge = SwiftProtoTesting_Proto3_TestAllTypes() 40 | toMerge.optionalInt64 = 1000 41 | 42 | do { 43 | try original.merge(serializedBytes: toMerge.serializedBytes() as [UInt8]) 44 | 45 | // The original should have the value from the merged message... 46 | XCTAssertEqual(original.optionalInt32, 100) 47 | XCTAssertEqual(original.optionalInt64, 1000) 48 | // ...but the older copy should not be affected. 49 | XCTAssertEqual(copied.optionalInt32, 100) 50 | XCTAssertEqual(copied.optionalInt64, 0) 51 | } catch let e { 52 | XCTFail("Merge should not have thrown, but it did: \(e)") 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Tests/SwiftProtobufTests/Test_ReallyLargeTagNumber.swift: -------------------------------------------------------------------------------- 1 | // Tests/SwiftProtobufTests/Test_ReallyLargeTagNumber.swift - Exercise extreme tag values 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Check that a message with the largest possible tag number encodes correctly. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | import Foundation 16 | import XCTest 17 | 18 | final class Test_ReallyLargeTagNumber: XCTestCase { 19 | 20 | func test_ReallyLargeTagNumber() { 21 | var m = SwiftProtoTesting_TestReallyLargeTagNumber() 22 | m.a = 1 23 | m.bb = 2 24 | 25 | do { 26 | let encoded: [UInt8] = try m.serializedBytes() 27 | XCTAssertEqual(encoded, [8, 1, 248, 255, 255, 255, 7, 2]) 28 | 29 | do { 30 | let decoded = try SwiftProtoTesting_TestReallyLargeTagNumber(serializedBytes: encoded) 31 | XCTAssertEqual(2, decoded.bb) 32 | XCTAssertEqual(1, decoded.a) 33 | XCTAssertEqual(m, decoded) 34 | } catch { 35 | XCTFail("Decode should not fail") 36 | } 37 | } catch let e { 38 | XCTFail("Could not encode \(m): Got error \(e)") 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Tests/SwiftProtobufTests/Test_RecursiveMap.swift: -------------------------------------------------------------------------------- 1 | // Tests/SwiftProtobufTests/Test_RecursiveMap.swift - Test maps within maps 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// Verify the behavior of maps whose values are other maps. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | import Foundation 16 | import XCTest 17 | 18 | final class Test_RecursiveMap: XCTestCase { 19 | func test_RecursiveMap() throws { 20 | let inner = SwiftProtoTesting_TestRecursiveMapMessage() 21 | var mid = SwiftProtoTesting_TestRecursiveMapMessage() 22 | mid.a = ["1": inner] 23 | var outer = SwiftProtoTesting_TestRecursiveMapMessage() 24 | outer.a = ["2": mid] 25 | 26 | do { 27 | let encoded: [UInt8] = try outer.serializedBytes() 28 | XCTAssertEqual(encoded, [10, 12, 10, 1, 50, 18, 7, 10, 5, 10, 1, 49, 18, 0]) 29 | 30 | let decodedOuter = try SwiftProtoTesting_TestRecursiveMapMessage(serializedBytes: encoded) 31 | if let decodedMid = decodedOuter.a["2"] { 32 | if let decodedInner = decodedMid.a["1"] { 33 | XCTAssertEqual(decodedOuter.a.count, 1) 34 | XCTAssertEqual(decodedMid.a.count, 1) 35 | XCTAssertEqual(decodedInner.a.count, 0) 36 | } else { 37 | XCTFail() 38 | } 39 | } else { 40 | XCTFail() 41 | } 42 | } catch let e { 43 | XCTFail("Failed with error \(e)") 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Tests/SwiftProtobufTests/Test_Type.swift: -------------------------------------------------------------------------------- 1 | // Tests/SwiftProtobufTests/Test_Type.swift - Exercise well-known "Type" message 2 | // 3 | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors 4 | // Licensed under Apache License v2.0 with Runtime Library Exception 5 | // 6 | // See LICENSE.txt for license information: 7 | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt 8 | // 9 | // ----------------------------------------------------------------------------- 10 | /// 11 | /// The well-known Type message is a simplified description of a proto schema. 12 | /// 13 | // ----------------------------------------------------------------------------- 14 | 15 | import Foundation 16 | import SwiftProtobuf 17 | import XCTest 18 | 19 | // Since Type is purely compiled (there is no hand-coding 20 | // in it) this is a fairly thin test just to ensure that the proto 21 | // does get into the runtime: 22 | 23 | final class Test_Type: XCTestCase, PBTestHelpers { 24 | typealias MessageTestType = Google_Protobuf_Type 25 | 26 | func testExists() { 27 | assertEncode([ 28 | 18, 13, 8, 1, 16, 3, 24, 1, 34, 3, 102, 111, 111, 64, 1, 29 | 18, 9, 8, 8, 24, 2, 34, 3, 98, 97, 114, 30 | ]) { (o: inout MessageTestType) in 31 | var field1 = Google_Protobuf_Field() 32 | field1.kind = .typeDouble 33 | field1.cardinality = .repeated 34 | field1.number = 1 35 | field1.name = "foo" 36 | field1.packed = true 37 | 38 | var field2 = Google_Protobuf_Field() 39 | field2.kind = .typeBool 40 | field2.number = 2 41 | field2.name = "bar" 42 | 43 | o.fields = [field1, field2] 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /cmake/modules/SwiftSupport.cmake: -------------------------------------------------------------------------------- 1 | 2 | # Returns the current architecture name in a variable 3 | # 4 | # Usage: 5 | # get_swift_host_arch(result_var_name) 6 | # 7 | # If the current architecture is supported by Swift, sets ${result_var_name} 8 | # with the sanitized host architecture name derived from CMAKE_SYSTEM_PROCESSOR. 9 | function(get_swift_host_arch result_var_name) 10 | if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") 11 | set("${result_var_name}" "x86_64" PARENT_SCOPE) 12 | elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64") 13 | set("${result_var_name}" "aarch64" PARENT_SCOPE) 14 | elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64") 15 | set("${result_var_name}" "powerpc64" PARENT_SCOPE) 16 | elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le") 17 | set("${result_var_name}" "powerpc64le" PARENT_SCOPE) 18 | elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x") 19 | set("${result_var_name}" "s390x" PARENT_SCOPE) 20 | elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l") 21 | set("${result_var_name}" "armv6" PARENT_SCOPE) 22 | elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l") 23 | set("${result_var_name}" "armv7" PARENT_SCOPE) 24 | elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a") 25 | set("${result_var_name}" "armv7" PARENT_SCOPE) 26 | elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64") 27 | set("${result_var_name}" "x86_64" PARENT_SCOPE) 28 | elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64") 29 | set("${result_var_name}" "itanium" PARENT_SCOPE) 30 | elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86") 31 | set("${result_var_name}" "i686" PARENT_SCOPE) 32 | elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686") 33 | set("${result_var_name}" "i686" PARENT_SCOPE) 34 | else() 35 | message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}") 36 | endif() 37 | endfunction() 38 | --------------------------------------------------------------------------------