├── bin ├── hermit.hcl ├── .make-4.4.pkg ├── go ├── gofmt ├── make ├── .go-1.22.0.pkg ├── .protoc-29.2.pkg ├── protoc ├── .golangci-lint-1.56.2.pkg ├── golangci-lint ├── README.hermit.md ├── activate-hermit ├── hermit └── go-main-stubs ├── testdata ├── conformance │ ├── pb │ │ ├── unittest_empty.pb │ │ ├── any.pb │ │ ├── api.pb │ │ ├── type.pb │ │ ├── empty.pb │ │ ├── struct.pb │ │ ├── any_test.pb │ │ ├── duration.pb │ │ ├── timestamp.pb │ │ ├── unittest.pb │ │ ├── wrappers.pb │ │ ├── conformance.pb │ │ ├── descriptor.pb │ │ ├── field_mask.pb │ │ ├── map_unittest.pb │ │ ├── source_context.pb │ │ ├── unittest_arena.pb │ │ ├── unittest_lite.pb │ │ ├── unittest_mset.pb │ │ ├── map_lite_unittest.pb │ │ ├── unittest_import.pb │ │ ├── unittest_proto3.pb │ │ ├── map_proto2_unittest.pb │ │ ├── test_messages_proto2.pb │ │ ├── test_messages_proto3.pb │ │ ├── unittest_import_lite.pb │ │ ├── unittest_optimize_for.pb │ │ ├── unittest_proto3_arena.pb │ │ ├── unittest_proto3_lite.pb │ │ ├── unittest_custom_options.pb │ │ ├── unittest_proto3_optional.pb │ │ ├── unittest_embed_optimize_for.pb │ │ ├── unittest_lazy_dependencies.pb │ │ ├── unittest_mset_wire_format.pb │ │ ├── unittest_no_field_presence.pb │ │ ├── unittest_proto3_arena_lite.pb │ │ ├── unittest_well_known_types.pb │ │ ├── unittest_drop_unknown_fields.pb │ │ ├── unittest_enormous_descriptor.pb │ │ ├── unittest_lite_imports_nonlite.pb │ │ ├── unittest_no_generic_services.pb │ │ ├── unittest_lazy_dependencies_enum.pb │ │ ├── unittest_preserve_unknown_enum.pb │ │ ├── unittest_preserve_unknown_enum2.pb │ │ ├── unittest_import_public.pb │ │ ├── unittest_lazy_dependencies_custom_option.pb │ │ └── unittest_import_public_lite.pb │ ├── unittest_import_public.proto │ ├── unittest_arena.proto │ ├── google │ │ └── protobuf │ │ │ ├── unittest_import_public.proto │ │ │ ├── unittest_arena.proto │ │ │ ├── unittest_empty.proto │ │ │ ├── unittest_import_public_lite.proto │ │ │ ├── any_test.proto │ │ │ ├── unittest_preserve_unknown_enum2.proto │ │ │ ├── unittest_lite_imports_nonlite.proto │ │ │ ├── unittest_no_generic_services.proto │ │ │ ├── unittest_import_lite.proto │ │ │ ├── unittest_drop_unknown_fields.proto │ │ │ ├── source_context.proto │ │ │ ├── empty.proto │ │ │ ├── unittest_embed_optimize_for.proto │ │ │ ├── unittest_mset_wire_format.proto │ │ │ ├── unittest_optimize_for.proto │ │ │ ├── unittest_preserve_unknown_enum.proto │ │ │ ├── unittest_import.proto │ │ │ ├── unittest_lazy_dependencies_enum.proto │ │ │ ├── unittest_lazy_dependencies_custom_option.proto │ │ │ ├── unittest_lazy_dependencies.proto │ │ │ ├── map_proto2_unittest.proto │ │ │ ├── struct.proto │ │ │ ├── unittest_mset.proto │ │ │ └── unittest_proto3_optional.proto │ ├── unittest_empty.proto │ ├── unittest_import_public_lite.proto │ ├── any_test.proto │ ├── unittest_preserve_unknown_enum2.proto │ ├── unittest_lite_imports_nonlite.proto │ ├── unittest_no_generic_services.proto │ ├── unittest_import_lite.proto │ ├── unittest_drop_unknown_fields.proto │ ├── source_context.proto │ ├── empty.proto │ ├── unittest_embed_optimize_for.proto │ ├── unittest_mset_wire_format.proto │ ├── unittest_optimize_for.proto │ ├── unittest_preserve_unknown_enum.proto │ ├── unittest_import.proto │ ├── unittest_lazy_dependencies_enum.proto │ ├── unittest_lazy_dependencies_custom_option.proto │ ├── unittest_lazy_dependencies.proto │ ├── map_proto2_unittest.proto │ ├── struct.proto │ ├── unittest_mset.proto │ └── unittest_proto3_optional.proto ├── reserved_fields.proto ├── structural_option.proto ├── comments.proto └── patches │ └── no_message_sets.patch ├── compiler ├── testdata │ ├── pb │ │ ├── 01_proto2_pkg.pb │ │ ├── regtest.pb │ │ ├── 16_proto2_options.pb │ │ ├── 01_proto3_pkg.pb │ │ ├── 09_proto2_enum.pb │ │ ├── 09_proto3_enum.pb │ │ ├── 13_proto2_oneof.pb │ │ ├── 13_proto3_oneof.pb │ │ ├── 14_proto2_group.pb │ │ ├── 15_proto2_map.pb │ │ ├── 15_proto3_map.pb │ │ ├── 00_proto2_simple.pb │ │ ├── 00_proto3_simple.pb │ │ ├── 03_proto2_nested.pb │ │ ├── 03_proto3_nested.pb │ │ ├── 05_proto2_import.pb │ │ ├── 05_proto3_import.pb │ │ ├── 08_proto2_service.pb │ │ ├── 08_proto3_service.pb │ │ ├── 16_proto3_options.pb │ │ ├── 10_proto2_reserved.pb │ │ ├── 10_proto3_reserved.pb │ │ ├── 17_proto2_custom_options.pb │ │ ├── 18_a_proto2_aggregate_opt.pb │ │ ├── 18_b_proto2_aggregate_opt.pb │ │ ├── 04_proto2_nested_recursive.pb │ │ ├── 04_proto3_nested_recursive.pb │ │ ├── 06_proto2_import_transitive.pb │ │ ├── 06_proto3_import_transitive.pb │ │ ├── 07_proto2_import_transitive.pb │ │ ├── 07_proto3_import_transitive.pb │ │ ├── 11_proto2_reserved_extension.pb │ │ ├── 12_proto2_extension_no_include.pb │ │ ├── 12_proto3_extension_no_include.pb │ │ ├── 19_proto2_non_custom_options.pb │ │ ├── 19_proto3_non_custom_options.pb │ │ ├── 18_proto2_aggregate_opt_no_include.pb │ │ ├── 20_proto2_options_with_extensions.pb │ │ ├── 06_proto2_import_transitive_no_include.pb │ │ └── 06_proto3_import_transitive_no_include.pb │ ├── 01_proto2_pkg.proto │ ├── 01_proto3_pkg.proto │ ├── 10_proto2_reserved.proto │ ├── 10_proto3_reserved.proto │ ├── 18_b_proto2_aggregate_opt.proto │ ├── 11_proto2_reserved_extension.proto │ ├── 06_proto2_import_transitive.proto │ ├── 06_proto3_import_transitive.proto │ ├── 07_proto2_import_transitive.proto │ ├── 07_proto3_import_transitive.proto │ ├── 06_proto2_import_transitive_no_include.proto │ ├── 06_proto3_import_transitive_no_include.proto │ ├── 05_proto2_import.proto │ ├── 05_proto3_import.proto │ ├── 16_proto2_options.proto │ ├── 16_proto3_options.proto │ ├── 15_proto3_map.proto │ ├── 15_proto2_map.proto │ ├── 18_a_proto2_aggregate_opt.proto │ ├── 03_proto2_nested.proto │ ├── 03_proto3_nested.proto │ ├── 13_proto2_oneof.proto │ ├── 13_proto3_oneof.proto │ ├── 12_proto3_extension_no_include.proto │ ├── 20_proto2_options_with_extensions.proto │ ├── 18_proto2_aggregate_opt_no_include.proto │ ├── 00_proto2_simple.proto │ ├── 00_proto3_simple.proto │ ├── 08_proto3_service.proto │ ├── 08_proto2_service.proto │ ├── 04_proto2_nested_recursive.proto │ ├── 04_proto3_nested_recursive.proto │ ├── 17_proto2_custom_options.proto │ ├── 09_proto2_enum.proto │ ├── 09_proto3_enum.proto │ ├── google │ │ └── api │ │ │ └── annotations.proto │ ├── regtest.proto │ ├── 12_proto2_extension_no_include.proto │ ├── 19_proto3_non_custom_options.proto │ ├── 14_proto2_group.proto │ └── 19_proto2_non_custom_options.proto ├── compiler_test.go └── registry.go ├── .github └── workflows │ └── ci.yml ├── renovate.json5 ├── parser ├── conformance_test.go ├── unquote_test.go └── unquote.go ├── cmd └── dumppb │ └── main.go ├── README.md ├── go.mod ├── main.go ├── main_test.go ├── .golangci.yml └── Makefile /bin/hermit.hcl: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bin/.make-4.4.pkg: -------------------------------------------------------------------------------- 1 | hermit -------------------------------------------------------------------------------- /bin/go: -------------------------------------------------------------------------------- 1 | .go-1.22.0.pkg -------------------------------------------------------------------------------- /bin/gofmt: -------------------------------------------------------------------------------- 1 | .go-1.22.0.pkg -------------------------------------------------------------------------------- /bin/make: -------------------------------------------------------------------------------- 1 | .make-4.4.pkg -------------------------------------------------------------------------------- /bin/.go-1.22.0.pkg: -------------------------------------------------------------------------------- 1 | hermit -------------------------------------------------------------------------------- /bin/.protoc-29.2.pkg: -------------------------------------------------------------------------------- 1 | hermit -------------------------------------------------------------------------------- /bin/protoc: -------------------------------------------------------------------------------- 1 | .protoc-29.2.pkg -------------------------------------------------------------------------------- /bin/.golangci-lint-1.56.2.pkg: -------------------------------------------------------------------------------- 1 | hermit -------------------------------------------------------------------------------- /bin/golangci-lint: -------------------------------------------------------------------------------- 1 | .golangci-lint-1.56.2.pkg -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_empty.pb: -------------------------------------------------------------------------------- 1 | 2 |  3 | unittest_empty.proto -------------------------------------------------------------------------------- /compiler/testdata/pb/01_proto2_pkg.pb: -------------------------------------------------------------------------------- 1 | 2 | . 3 | 01_proto2_pkg.protopkg" 4 | M3 5 | s ( Rs -------------------------------------------------------------------------------- /compiler/testdata/pb/regtest.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/regtest.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/any.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/any.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/api.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/api.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/type.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/type.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/16_proto2_options.pb: -------------------------------------------------------------------------------- 1 | 2 | @ 3 | 16_proto2_options.protopkg" 4 | User 5 | id (Rid:8 -------------------------------------------------------------------------------- /testdata/conformance/pb/empty.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/empty.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/struct.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/struct.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/any_test.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/any_test.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/duration.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/duration.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/timestamp.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/timestamp.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/wrappers.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/wrappers.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/01_proto3_pkg.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/01_proto3_pkg.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/09_proto2_enum.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/09_proto2_enum.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/09_proto3_enum.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/09_proto3_enum.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/13_proto2_oneof.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/13_proto2_oneof.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/13_proto3_oneof.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/13_proto3_oneof.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/14_proto2_group.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/14_proto2_group.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/15_proto2_map.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/15_proto2_map.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/15_proto3_map.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/15_proto3_map.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/conformance.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/conformance.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/descriptor.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/descriptor.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/field_mask.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/field_mask.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/map_unittest.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/map_unittest.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/00_proto2_simple.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/00_proto2_simple.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/00_proto3_simple.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/00_proto3_simple.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/03_proto2_nested.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/03_proto2_nested.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/03_proto3_nested.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/03_proto3_nested.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/05_proto2_import.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/05_proto2_import.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/05_proto3_import.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/05_proto3_import.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/08_proto2_service.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/08_proto2_service.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/08_proto3_service.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/08_proto3_service.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/16_proto3_options.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/16_proto3_options.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/source_context.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/source_context.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_arena.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_arena.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_lite.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_lite.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_mset.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_mset.pb -------------------------------------------------------------------------------- /compiler/testdata/01_proto2_pkg.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package pkg; 3 | 4 | message M3 { 5 | optional string s = 1; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /compiler/testdata/01_proto3_pkg.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package pkg; 3 | 4 | message M3 { 5 | optional string s = 1; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /compiler/testdata/pb/10_proto2_reserved.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/10_proto2_reserved.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/10_proto3_reserved.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/10_proto3_reserved.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/map_lite_unittest.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/map_lite_unittest.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_import.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_import.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_proto3.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_proto3.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/map_proto2_unittest.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/map_proto2_unittest.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/17_proto2_custom_options.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/17_proto2_custom_options.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/18_a_proto2_aggregate_opt.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/18_a_proto2_aggregate_opt.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/18_b_proto2_aggregate_opt.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/18_b_proto2_aggregate_opt.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/test_messages_proto2.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/test_messages_proto2.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/test_messages_proto3.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/test_messages_proto3.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_import_lite.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_import_lite.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_optimize_for.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_optimize_for.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_proto3_arena.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_proto3_arena.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_proto3_lite.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_proto3_lite.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/04_proto2_nested_recursive.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/04_proto2_nested_recursive.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/04_proto3_nested_recursive.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/04_proto3_nested_recursive.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/06_proto2_import_transitive.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/06_proto2_import_transitive.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/06_proto3_import_transitive.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/06_proto3_import_transitive.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/07_proto2_import_transitive.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/07_proto2_import_transitive.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/07_proto3_import_transitive.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/07_proto3_import_transitive.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_custom_options.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_custom_options.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_proto3_optional.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_proto3_optional.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/11_proto2_reserved_extension.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/11_proto2_reserved_extension.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/12_proto2_extension_no_include.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/12_proto2_extension_no_include.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/12_proto3_extension_no_include.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/12_proto3_extension_no_include.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/19_proto2_non_custom_options.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/19_proto2_non_custom_options.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/19_proto3_non_custom_options.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/19_proto3_non_custom_options.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_embed_optimize_for.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_embed_optimize_for.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_lazy_dependencies.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_lazy_dependencies.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_mset_wire_format.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_mset_wire_format.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_no_field_presence.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_no_field_presence.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_proto3_arena_lite.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_proto3_arena_lite.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_well_known_types.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_well_known_types.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_drop_unknown_fields.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_drop_unknown_fields.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_enormous_descriptor.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_enormous_descriptor.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_lite_imports_nonlite.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_lite_imports_nonlite.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_no_generic_services.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_no_generic_services.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/18_proto2_aggregate_opt_no_include.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/18_proto2_aggregate_opt_no_include.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/20_proto2_options_with_extensions.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/20_proto2_options_with_extensions.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_lazy_dependencies_enum.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_lazy_dependencies_enum.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_preserve_unknown_enum.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_preserve_unknown_enum.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_preserve_unknown_enum2.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_preserve_unknown_enum2.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/06_proto2_import_transitive_no_include.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/06_proto2_import_transitive_no_include.pb -------------------------------------------------------------------------------- /compiler/testdata/pb/06_proto3_import_transitive_no_include.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/compiler/testdata/pb/06_proto3_import_transitive_no_include.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_import_public.pb: -------------------------------------------------------------------------------- 1 | 2 | y 3 | unittest_import_public.protoprotobuf_unittest_import"# 4 | PublicImportMessage 5 | e (ReB 6 | com.google.protobuf.test -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_lazy_dependencies_custom_option.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alecthomas/protobuf/HEAD/testdata/conformance/pb/unittest_lazy_dependencies_custom_option.pb -------------------------------------------------------------------------------- /testdata/conformance/pb/unittest_import_public_lite.pb: -------------------------------------------------------------------------------- 1 | 2 |  3 | !unittest_import_public_lite.protoprotobuf_unittest_import"' 4 | PublicImportMessageLite 5 | e (ReB 6 | com.google.protobufH -------------------------------------------------------------------------------- /compiler/testdata/10_proto2_reserved.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package pkg; 3 | 4 | message M { 5 | reserved 2, 15, 9 to 11; 6 | reserved "m", "mm"; 7 | optional string s = 1; 8 | reserved "one", "two"; 9 | reserved 25 to max; 10 | } 11 | -------------------------------------------------------------------------------- /compiler/testdata/10_proto3_reserved.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package pkg; 3 | 4 | message M { 5 | reserved 2, 15, 9 to 11; 6 | reserved "m", "mm"; 7 | optional string s = 1; 8 | reserved "one", "two"; 9 | reserved 25 to max; 10 | } 11 | -------------------------------------------------------------------------------- /compiler/testdata/18_b_proto2_aggregate_opt.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import "18_a_proto2_aggregate_opt.proto"; 4 | 5 | package pkg; 6 | 7 | message User { 8 | option (.pkg.opt1) = {s1: "1" s2: "2"}; 9 | optional int64 num = 1; 10 | } 11 | -------------------------------------------------------------------------------- /compiler/testdata/11_proto2_reserved_extension.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package pkg; 3 | 4 | message M { 5 | extensions 100 to 199; 6 | optional string s = 1; 7 | extensions 200 to 299; 8 | extensions 350 to max; 9 | extensions 310; 10 | } 11 | -------------------------------------------------------------------------------- /testdata/reserved_fields.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package test.pkg; 3 | 4 | message ReservedTest { 5 | reserved 'foo'; 6 | reserved 1; 7 | reserved "bar"; 8 | reserved 2, 15, 9 to 11, 54, 67 to 100; 9 | reserved "foobar1", "foobar2"; 10 | } 11 | -------------------------------------------------------------------------------- /compiler/testdata/06_proto2_import_transitive.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package pkg2; 3 | 4 | import "05_proto2_import.proto"; 5 | import "01_proto2_pkg.proto"; 6 | 7 | message M6 { 8 | optional pkg.M3 m3 = 3; 9 | optional pkg2.M5 m5 = 5; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /compiler/testdata/06_proto3_import_transitive.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package pkg2; 3 | 4 | import "05_proto3_import.proto"; 5 | import "01_proto3_pkg.proto"; 6 | 7 | message M6 { 8 | optional pkg.M3 m3 = 3; 9 | optional pkg2.M5 m5 = 5; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /compiler/testdata/07_proto2_import_transitive.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package pkg2; 3 | 4 | import "01_proto2_pkg.proto"; 5 | import "05_proto2_import.proto"; 6 | 7 | message M6 { 8 | optional pkg.M3 m3 = 3; 9 | optional pkg2.M5 m5 = 5; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /compiler/testdata/07_proto3_import_transitive.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package pkg2; 3 | 4 | import "01_proto3_pkg.proto"; 5 | import "05_proto3_import.proto"; 6 | 7 | message M6 { 8 | optional pkg.M3 m3 = 3; 9 | optional pkg2.M5 m5 = 5; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /compiler/testdata/06_proto2_import_transitive_no_include.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package pkg2; 3 | 4 | import "05_proto2_import.proto"; 5 | import "01_proto2_pkg.proto"; 6 | 7 | message M6 { 8 | optional pkg.M3 m3 = 3; 9 | optional pkg2.M5 m5 = 5; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /compiler/testdata/06_proto3_import_transitive_no_include.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package pkg2; 3 | 4 | import "05_proto3_import.proto"; 5 | import "01_proto3_pkg.proto"; 6 | 7 | message M6 { 8 | optional pkg.M3 m3 = 3; 9 | optional pkg2.M5 m5 = 5; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /bin/README.hermit.md: -------------------------------------------------------------------------------- 1 | # Hermit environment 2 | 3 | This is a [Hermit](https://github.com/cashapp/hermit) bin directory. 4 | 5 | The symlinks in this directory are managed by Hermit and will automatically 6 | download and install Hermit itself as well as packages. These packages are 7 | local to this environment. 8 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - master 5 | pull_request: 6 | name: CI 7 | jobs: 8 | ci: 9 | name: CI 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v4 13 | - run: ./bin/hermit env --raw >> $GITHUB_ENV 14 | - run: make ci 15 | -------------------------------------------------------------------------------- /compiler/testdata/05_proto2_import.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package pkg2; 3 | 4 | import "00_proto2_simple.proto"; 5 | import public "01_proto2_pkg.proto"; 6 | 7 | message M5 { 8 | optional M1 m1 = 1; 9 | optional .M2 m2 = 2; 10 | optional pkg.M3 m3 = 3; 11 | optional .pkg.M3 m4 = 4; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /compiler/testdata/05_proto3_import.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package pkg2; 3 | 4 | import "00_proto3_simple.proto"; 5 | import public "01_proto3_pkg.proto"; 6 | 7 | message M5 { 8 | optional M1 m1 = 1; 9 | optional .M2 m2 = 2; 10 | optional pkg.M3 m3 = 3; 11 | optional .pkg.M3 m4 = 4; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /compiler/testdata/16_proto2_options.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package pkg; 4 | 5 | message User { 6 | option deprecated = true; 7 | option message_set_wire_format = false; 8 | option no_standard_descriptor_accessor = true; 9 | option map_entry = false; 10 | 11 | optional int64 id = 1; 12 | } 13 | -------------------------------------------------------------------------------- /compiler/testdata/16_proto3_options.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package pkg; 4 | 5 | message User { 6 | option deprecated = true; 7 | option message_set_wire_format = false; 8 | option no_standard_descriptor_accessor = true; 9 | option map_entry = false; 10 | 11 | optional int64 id = 1; 12 | } 13 | -------------------------------------------------------------------------------- /renovate.json5: -------------------------------------------------------------------------------- 1 | { 2 | $schema: "https://docs.renovatebot.com/renovate-schema.json", 3 | extends: [ 4 | "config:recommended", 5 | ":semanticCommits", 6 | ":semanticCommitTypeAll(chore)", 7 | ":semanticCommitScope(deps)", 8 | "group:allNonMajor", 9 | "schedule:earlyMondays", // Run once a week. 10 | ], 11 | } 12 | -------------------------------------------------------------------------------- /compiler/testdata/15_proto3_map.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message M { 4 | message Nest1 { 5 | optional string egg = 1; 6 | } 7 | map a_map = 1; 8 | message Nest2 { 9 | optional string egg = 1; 10 | } 11 | map a_map2 = 2; 12 | Nest3 nest3 = 3; 13 | message Nest3 { 14 | optional string egg = 1; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /compiler/testdata/15_proto2_map.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message M { 4 | message Nest1 { 5 | optional string egg = 1; 6 | } 7 | map a_map = 1; 8 | message Nest2 { 9 | optional string egg = 1; 10 | } 11 | map a_map2 = 2; 12 | optional Nest3 nest3 = 3; 13 | message Nest3 { 14 | optional string egg = 1; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /compiler/testdata/18_a_proto2_aggregate_opt.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import "google/protobuf/descriptor.proto"; 4 | 5 | package pkg; 6 | 7 | // Options extension ranges for private extensions 50000-99999 8 | message Opt { 9 | optional string s1 = 1; 10 | optional string s2 = 2; 11 | } 12 | 13 | extend google.protobuf.MessageOptions { 14 | optional Opt opt1 = 50001; 15 | } 16 | -------------------------------------------------------------------------------- /compiler/testdata/03_proto2_nested.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package org.proj.pkg; 4 | 5 | message Nest { 6 | message Egg { 7 | optional string chick = 1; 8 | } 9 | optional .org.proj.pkg.Nest.Egg egg1 = 1; 10 | optional org.proj.pkg.Nest.Egg egg2 = 2; 11 | optional proj.pkg.Nest.Egg egg3 = 3; 12 | optional pkg.Nest.Egg egg4 = 4; 13 | optional Nest.Egg egg5 = 5; 14 | optional Egg egg6 = 6; 15 | } 16 | -------------------------------------------------------------------------------- /compiler/testdata/03_proto3_nested.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package org.proj.pkg; 4 | 5 | message Nest { 6 | message Egg { 7 | optional string chick = 1; 8 | } 9 | optional .org.proj.pkg.Nest.Egg egg1 = 1; 10 | optional org.proj.pkg.Nest.Egg egg2 = 2; 11 | optional proj.pkg.Nest.Egg egg3 = 3; 12 | optional pkg.Nest.Egg egg4 = 4; 13 | optional Nest.Egg egg5 = 5; 14 | optional Egg egg6 = 6; 15 | } 16 | -------------------------------------------------------------------------------- /compiler/testdata/13_proto2_oneof.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package pkg; 3 | 4 | message M1 { 5 | optional int32 i = 1; 6 | } 7 | 8 | message M2 { 9 | optional string s1 = 1; 10 | oneof oneof1 { 11 | M1 m1 = 2; 12 | int32 i = 3; 13 | string s2 = 4; 14 | } 15 | optional string s3 = 5; 16 | oneof oneof2 { 17 | M1 m21 = 6; 18 | int32 i2 = 7; 19 | string s22 = 8; 20 | } 21 | optional string s4 = 9; 22 | } 23 | -------------------------------------------------------------------------------- /parser/conformance_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "os" 5 | "path/filepath" 6 | "testing" 7 | 8 | "github.com/stretchr/testify/require" 9 | ) 10 | 11 | func TestConformance(t *testing.T) { 12 | files, err := filepath.Glob("../testdata/conformance/*.proto") 13 | require.NoError(t, err) 14 | for _, file := range files { 15 | t.Run(file, func(t *testing.T) { 16 | r, err := os.Open(file) 17 | require.NoError(t, err) 18 | _, err = Parse(file, r) 19 | require.NoError(t, err) 20 | }) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /compiler/testdata/13_proto3_oneof.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package pkg; 3 | 4 | message M1 { 5 | optional int32 i = 1; 6 | } 7 | 8 | message M2 { 9 | optional string s1 = 1; 10 | string s12 = 2; 11 | oneof oneof1 { 12 | M1 m1 = 3; 13 | int32 i = 4; 14 | string s2 = 5; 15 | } 16 | optional string s3 = 6; 17 | string s32 = 7; 18 | oneof oneof2 { 19 | M1 m21 = 8; 20 | int32 i2 = 9; 21 | string s22 = 10; 22 | } 23 | string s41 = 11; 24 | optional string s4 = 12; 25 | string s42 = 13; 26 | } 27 | -------------------------------------------------------------------------------- /compiler/testdata/12_proto3_extension_no_include.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/descriptor.proto"; 4 | 5 | enum Color { 6 | UNKNOWN = 0; 7 | RED = 1; 8 | GREEN = 2; 9 | BLUE = 3; 10 | } 11 | 12 | extend google.protobuf.MethodOptions { 13 | string opt1 = 72295728; 14 | optional string opt2 = 72295729; 15 | repeated string opt3 = 72295730; 16 | Color opt4 = 72295731; 17 | } 18 | 19 | message ColorMessage { 20 | Color color = 1; 21 | extend google.protobuf.MethodOptions { 22 | optional ColorMessage c = 72295740; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /testdata/structural_option.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package test.pkg; 3 | 4 | import "google/protobuf/descriptor.proto"; 5 | 6 | option (test.pkg.structural_option) = { 7 | [test.pkg.e]: ["foo", "foo2"] 8 | inner { inner: [{s: "foobar"}, {s: "foobar2"}] } 9 | inner { s: "bar2" } 10 | inner { } 11 | }; 12 | 13 | message Test { 14 | repeated string s = 1; 15 | repeated Test inner = 4; 16 | extensions 100 to 199; 17 | } 18 | 19 | extend google.protobuf.FileOptions { 20 | optional Test structural_option = 33000; 21 | } 22 | 23 | extend Test { 24 | repeated string e = 109; 25 | } -------------------------------------------------------------------------------- /compiler/testdata/20_proto2_options_with_extensions.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package org.proj.pkg; 4 | 5 | import "google/protobuf/descriptor.proto"; 6 | 7 | message OrgOptions { 8 | optional bool private = 1; 9 | 10 | extensions 1000 to max; 11 | } 12 | 13 | extend OrgOptions { 14 | optional bool super_private = 1000; 15 | } 16 | 17 | extend google.protobuf.FieldOptions { 18 | optional OrgOptions org = 7654321; 19 | } 20 | 21 | message Foo { 22 | optional string name = 1 [(org) = {private: true}]; 23 | optional string gender = 2 [(org) = {[pkg.super_private]: true}]; 24 | } 25 | -------------------------------------------------------------------------------- /compiler/testdata/18_proto2_aggregate_opt_no_include.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import "google/protobuf/descriptor.proto"; 4 | 5 | package pkg; 6 | 7 | // Options extension ranges for private extensions 50000-99999 8 | message Opt { 9 | optional string s1 = 1; 10 | optional string s2 = 2; 11 | } 12 | 13 | extend google.protobuf.MessageOptions { 14 | optional Opt opt1 = 50001; 15 | } 16 | 17 | message User { 18 | // this is a fully qualified name. We will need to infer 19 | // it for e.g. option(opt1) 20 | option (.pkg.opt1) = {s1: "1" s2: "2"}; 21 | optional int64 num = 1; 22 | } 23 | -------------------------------------------------------------------------------- /bin/activate-hermit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This file must be used with "source bin/activate-hermit" from bash or zsh. 3 | # You cannot run it directly 4 | 5 | if [ "${BASH_SOURCE-}" = "$0" ]; then 6 | echo "You must source this script: \$ source $0" >&2 7 | exit 33 8 | fi 9 | 10 | BIN_DIR="$(dirname "${BASH_SOURCE[0]:-${(%):-%x}}")" 11 | if "${BIN_DIR}/hermit" noop > /dev/null; then 12 | eval "$("${BIN_DIR}/hermit" activate "${BIN_DIR}/..")" 13 | 14 | if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ]; then 15 | hash -r 2>/dev/null 16 | fi 17 | 18 | echo "Hermit environment $("${HERMIT_ENV}"/bin/hermit env HERMIT_ENV) activated" 19 | fi 20 | -------------------------------------------------------------------------------- /cmd/dumppb/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | 8 | "google.golang.org/protobuf/encoding/protojson" 9 | "google.golang.org/protobuf/proto" 10 | pb "google.golang.org/protobuf/types/descriptorpb" 11 | ) 12 | 13 | func main() { 14 | pbBytes, err := os.ReadFile(os.Args[1]) 15 | if err != nil { 16 | log.Fatal(err) 17 | } 18 | fds := &pb.FileDescriptorSet{} 19 | if err := proto.Unmarshal(pbBytes, fds); err != nil { 20 | log.Fatal(err) 21 | } 22 | 23 | m := protojson.MarshalOptions{Multiline: true, AllowPartial: true} 24 | b, err := m.Marshal(fds) 25 | if err != nil { 26 | log.Fatal(err) 27 | } 28 | fmt.Println(string(b)) 29 | } 30 | -------------------------------------------------------------------------------- /compiler/testdata/00_proto2_simple.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message M1 { 4 | optional double a_double = 1; 5 | optional float a_float = 2; 6 | optional int32 a_int32 = 3; 7 | optional int64 a_int64 = 4; 8 | optional uint32 a_uint32 = 5; 9 | optional uint64 a_uint64 = 6; 10 | optional sint32 a_sint32 = 7; 11 | optional sint64 a_sint64 = 8; 12 | optional fixed32 a_fixed32 = 9; 13 | optional fixed64 a_fixed64 = 10; 14 | optional sfixed32 a_sfixed32 = 11; 15 | optional sfixed64 a_sfixed64 = 12; 16 | optional bool a_bool = 13; 17 | optional string a_string = 14; 18 | optional bytes a_bytes = 15; 19 | } 20 | 21 | message M2 { 22 | optional string s = 1; 23 | optional int32 i = 2; 24 | } 25 | -------------------------------------------------------------------------------- /compiler/testdata/00_proto3_simple.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message M1 { 4 | optional double a_double = 1; 5 | optional float a_float = 2; 6 | optional int32 a_int32 = 3; 7 | optional int64 a_int64 = 4; 8 | optional uint32 a_uint32 = 5; 9 | optional uint64 a_uint64 = 6; 10 | optional sint32 a_sint32 = 7; 11 | optional sint64 a_sint64 = 8; 12 | optional fixed32 a_fixed32 = 9; 13 | optional fixed64 a_fixed64 = 10; 14 | optional sfixed32 a_sfixed32 = 11; 15 | optional sfixed64 a_sfixed64 = 12; 16 | optional bool a_bool = 13; 17 | optional string a_string = 14; 18 | optional bytes a_bytes = 15; 19 | } 20 | 21 | message M2 { 22 | optional string s = 1; 23 | optional int32 i = 2; 24 | } 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A Protobuf IDL Parser for Go 2 | 3 | This package contains a cleanroom Protobuf IDL source parser for Go using [Participle](https://github.com/alecthomas/participle). 4 | 5 | This was extracted from an example within Participle. 6 | 7 | ## Tests 8 | 9 | Conformance tests are pulled from protoc and can be run with `go test ./...`. 10 | You can re-sync the upstream tests by running `make -C testdata`. 11 | 12 | Compiler tests are end to end tests comparing generated FileDesciptors 13 | against protoc generated FileDescriptors. The protoc generated 14 | FileDescriptors are located in `compiler/testdata/pb/*.pb` and 15 | source files in `compiler/testdata/*.proto`. Protoc FileDescriptors can be 16 | regenerated with `make -C compiler` 17 | -------------------------------------------------------------------------------- /compiler/testdata/08_proto3_service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package pkg; 3 | 4 | import "01_proto3_pkg.proto"; 5 | import "05_proto3_import.proto"; 6 | 7 | message Request { 8 | optional pkg.M3 m3 = 3; 9 | pkg2.M5 m5 = 5; 10 | } 11 | 12 | service Greeter { 13 | rpc Hello (Request) returns (pkg2.M5) { 14 | // no options here, but an empty option block 15 | }; 16 | rpc HelloClientStream (stream .pkg.M3) returns (.pkg.HelloResponse); 17 | rpc HelloServerStream (HelloRequest) returns (stream HelloResponse); 18 | rpc HelloBiDiStream (stream HelloRequest) returns (stream HelloResponse); 19 | } 20 | 21 | message HelloRequest { 22 | string first_name = 1; 23 | } 24 | 25 | message HelloResponse { 26 | optional string greeting = 1; 27 | } 28 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/alecthomas/protobuf 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/alecthomas/kong v0.8.1 7 | github.com/alecthomas/participle/v2 v2.1.1 8 | github.com/alecthomas/repr v0.4.0 9 | github.com/google/go-cmp v0.6.0 10 | github.com/stretchr/testify v1.8.4 11 | google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c 12 | google.golang.org/genproto/googleapis/api v0.0.0-20240213162025-012b6fc9bca9 13 | google.golang.org/protobuf v1.32.0 14 | ) 15 | 16 | require ( 17 | github.com/davecgh/go-spew v1.1.1 // indirect 18 | github.com/pkg/errors v0.9.1 // indirect 19 | github.com/pmezard/go-difflib v1.0.0 // indirect 20 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect 21 | gopkg.in/yaml.v3 v3.0.1 // indirect 22 | ) 23 | -------------------------------------------------------------------------------- /compiler/testdata/08_proto2_service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package pkg; 3 | 4 | import "01_proto2_pkg.proto"; 5 | import "05_proto2_import.proto"; 6 | 7 | message Request { 8 | optional pkg.M3 m3 = 3; 9 | optional pkg2.M5 m5 = 5; 10 | } 11 | 12 | service Greeter { 13 | rpc Hello (Request) returns (pkg2.M5) { 14 | // no options here, but an empty option block 15 | }; 16 | rpc HelloClientStream (stream .pkg.M3) returns (.pkg.HelloResponse); 17 | rpc HelloServerStream (HelloRequest) returns (stream HelloResponse); 18 | rpc HelloBiDiStream (stream HelloRequest) returns (stream HelloResponse); 19 | } 20 | 21 | message HelloRequest { 22 | optional string first_name = 1; 23 | } 24 | 25 | message HelloResponse { 26 | optional string greeting = 1; 27 | } 28 | -------------------------------------------------------------------------------- /compiler/testdata/04_proto2_nested_recursive.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message M { 4 | message Nest { 5 | message Egg { 6 | optional string chick = 1; 7 | } 8 | } 9 | optional M.Nest.Egg egg1 = 1; 10 | optional .M.Nest.Egg egg2 = 2; 11 | optional Nest.Egg egg3 = 3; 12 | optional M.Nest nest1 = 4; 13 | optional .M.Nest nest2 = 5; 14 | optional Nest nest3 = 6; 15 | optional M2.Inner inner1 = 7; 16 | optional .M2.Inner inner2 = 8; 17 | } 18 | 19 | message M2 { 20 | message Inner { 21 | optional string s = 1; 22 | } 23 | repeated M.Nest nest = 1; 24 | repeated .M.Nest.Egg egg = 2; 25 | } 26 | 27 | message LinkedList { 28 | optional LinkedList next = 1; 29 | } 30 | 31 | message LinkedList2 { 32 | optional .LinkedList2 next = 1; 33 | } 34 | -------------------------------------------------------------------------------- /compiler/testdata/04_proto3_nested_recursive.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message M { 4 | message Nest { 5 | message Egg { 6 | optional string chick = 1; 7 | } 8 | } 9 | optional M.Nest.Egg egg1 = 1; 10 | optional .M.Nest.Egg egg2 = 2; 11 | optional Nest.Egg egg3 = 3; 12 | optional M.Nest nest1 = 4; 13 | optional .M.Nest nest2 = 5; 14 | optional Nest nest3 = 6; 15 | optional M2.Inner inner1 = 7; 16 | optional .M2.Inner inner2 = 8; 17 | } 18 | 19 | message M2 { 20 | message Inner { 21 | optional string s = 1; 22 | } 23 | repeated M.Nest nest = 1; 24 | repeated .M.Nest.Egg egg = 2; 25 | } 26 | 27 | message LinkedList { 28 | optional LinkedList next = 1; 29 | } 30 | 31 | message LinkedList2 { 32 | optional .LinkedList2 next = 1; 33 | } 34 | -------------------------------------------------------------------------------- /parser/unquote_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/alecthomas/participle/v2/lexer" 7 | "github.com/stretchr/testify/require" 8 | ) 9 | 10 | func TestUnquote(t *testing.T) { 11 | tests := []struct { 12 | input string 13 | expected string 14 | }{ 15 | {`"\n\027"`, "\n\027"}, 16 | {`"\?"`, "\x3f"}, 17 | {`'\n\027'`, `\n\027`}, 18 | {`"\n\x17"`, "\n\027"}, 19 | {`"hello\0world"`, "hello\000world"}, 20 | {`"hello\x0world"`, "hello\000world"}, 21 | {`"\0001"`, "\0001"}, 22 | {`"\x001"`, "\x001"}, 23 | {`"\341\210\264"`, "ሴ"}, 24 | } 25 | for _, test := range tests { 26 | actual, err := unquote(lexer.Token{Value: test.input}) 27 | require.NoError(t, err) 28 | require.Equal(t, test.expected, actual.Value) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /bin/hermit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -eo pipefail 4 | 5 | if [ -z "${HERMIT_STATE_DIR}" ]; then 6 | case "$(uname -s)" in 7 | Darwin) 8 | export HERMIT_STATE_DIR="${HOME}/Library/Caches/hermit" 9 | ;; 10 | Linux) 11 | export HERMIT_STATE_DIR="${XDG_CACHE_HOME:-${HOME}/.cache}/hermit" 12 | ;; 13 | esac 14 | fi 15 | 16 | export HERMIT_DIST_URL="${HERMIT_DIST_URL:-https://github.com/cashapp/hermit/releases/download/stable}" 17 | HERMIT_CHANNEL="$(basename "${HERMIT_DIST_URL}")" 18 | export HERMIT_CHANNEL 19 | export HERMIT_EXE=${HERMIT_EXE:-${HERMIT_STATE_DIR}/pkg/hermit@${HERMIT_CHANNEL}/hermit} 20 | 21 | if [ ! -x "${HERMIT_EXE}" ]; then 22 | echo "Bootstrapping ${HERMIT_EXE} from ${HERMIT_DIST_URL}" 1>&2 23 | curl -fsSL "${HERMIT_DIST_URL}/install.sh" | /bin/bash 1>&2 24 | fi 25 | 26 | exec "${HERMIT_EXE}" --level=fatal exec "$0" -- "$@" 27 | -------------------------------------------------------------------------------- /compiler/testdata/17_proto2_custom_options.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import "google/protobuf/descriptor.proto"; 4 | 5 | package pkg; 6 | 7 | // Options extension ranges for private extensions 50000-99999 8 | 9 | message Opt { 10 | optional string s1 = 1; 11 | optional string s2 = 2; 12 | optional string s3 = 3; 13 | optional string s4 = 4; 14 | } 15 | 16 | extend google.protobuf.MessageOptions { 17 | optional Opt opt1 = 50001; 18 | optional string opt2 = 50002; 19 | optional string opt3 = 50003; 20 | optional string opt4 = 50004; 21 | } 22 | 23 | message User { 24 | option (.pkg.opt1).s1 = "opt1-s1"; 25 | option (pkg.opt1).s2 = "opt1-s2"; 26 | option (opt1).s3 = "opt1-s3"; 27 | option (.pkg.opt2) = "opt2"; 28 | option (pkg.opt3) = "opt3"; 29 | option (opt4) = "opt4"; 30 | option deprecated = true; 31 | optional int64 num = 1; 32 | } 33 | -------------------------------------------------------------------------------- /compiler/testdata/09_proto2_enum.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package pkg; 3 | 4 | enum Color { 5 | UNKNOWN = 0; 6 | reserved 2, 15, 9 to 11, 40 to max; 7 | reserved "GREEN", "BLACK"; 8 | reserved "RED"; 9 | BLUE = 12; 10 | reserved 3; 11 | } 12 | 13 | message Nest { 14 | message Egg { 15 | enum EggKind { 16 | EGG_KIND_UNKNOWN = 0; 17 | EGG_KIND_CHICK = 1; 18 | EGG_KIND_DUCKLING = 2; 19 | } 20 | optional EggKind kind1 = 1; 21 | optional Egg.EggKind kind2 = 2; 22 | optional Nest.Egg.EggKind kind3 = 3; 23 | optional pkg.Nest.Egg.EggKind kind4 = 4; 24 | optional .pkg.Nest.Egg.EggKind kind5 = 5; 25 | } 26 | optional Egg.EggKind kind2 = 2; 27 | optional Nest.Egg.EggKind kind3 = 3; 28 | optional pkg.Nest.Egg.EggKind kind4 = 4; 29 | optional .pkg.Nest.Egg.EggKind kind5 = 5; 30 | } 31 | 32 | 33 | message Farm { 34 | optional Color color1 = 1; 35 | optional pkg.Color color2 = 2; 36 | optional .pkg.Color color3 = 3; 37 | optional Nest.Egg.EggKind egg_kind = 4; 38 | optional pkg.Nest.Egg.EggKind egg_kind2 = 5; 39 | optional .pkg.Nest.Egg.EggKind egg_kind3 = 6; 40 | } 41 | -------------------------------------------------------------------------------- /compiler/testdata/09_proto3_enum.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package pkg; 3 | 4 | enum Color { 5 | UNKNOWN = 0; 6 | reserved 2, 15, 9 to 11, 40 to max; 7 | reserved "GREEN", "BLACK"; 8 | reserved "RED"; 9 | BLUE = 12; 10 | reserved 3; 11 | } 12 | 13 | message Nest { 14 | message Egg { 15 | enum EggKind { 16 | EGG_KIND_UNKNOWN = 0; 17 | EGG_KIND_CHICK = 1; 18 | EGG_KIND_DUCKLING = 2; 19 | } 20 | optional EggKind kind1 = 1; 21 | optional Egg.EggKind kind2 = 2; 22 | optional Nest.Egg.EggKind kind3 = 3; 23 | optional pkg.Nest.Egg.EggKind kind4 = 4; 24 | optional .pkg.Nest.Egg.EggKind kind5 = 5; 25 | } 26 | optional Egg.EggKind kind2 = 2; 27 | optional Nest.Egg.EggKind kind3 = 3; 28 | optional pkg.Nest.Egg.EggKind kind4 = 4; 29 | optional .pkg.Nest.Egg.EggKind kind5 = 5; 30 | } 31 | 32 | 33 | message Farm { 34 | optional Color color1 = 1; 35 | optional pkg.Color color2 = 2; 36 | optional .pkg.Color color3 = 3; 37 | optional Nest.Egg.EggKind egg_kind = 4; 38 | optional pkg.Nest.Egg.EggKind egg_kind2 = 5; 39 | optional .pkg.Nest.Egg.EggKind egg_kind3 = 6; 40 | } 41 | -------------------------------------------------------------------------------- /compiler/testdata/google/api/annotations.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | import "google/api/http.proto"; 20 | import "google/protobuf/descriptor.proto"; 21 | 22 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; 23 | option java_multiple_files = true; 24 | option java_outer_classname = "AnnotationsProto"; 25 | option java_package = "com.google.api"; 26 | option objc_class_prefix = "GAPI"; 27 | 28 | extend google.protobuf.MethodOptions { 29 | // See `HttpRule`. 30 | HttpRule http = 72295728; 31 | } 32 | -------------------------------------------------------------------------------- /testdata/comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | // Test 1 4 | /** 5 | Test 2 6 | */ 7 | message Test { 8 | repeated /* Comment */ string s = /* Comment */ 1; 9 | optional /* Comment */ string other /* Comment */ = 2 [ 10 | // We are about to comment 11 | default = "a" // Commenting on default 12 | ]; 13 | } 14 | 15 | message /* Comment */ Empty { 16 | // Empty message 17 | } 18 | 19 | option /* Comment */ (foo) = { 20 | // Comment before field 21 | f1: "foo" 22 | /* multi-line 23 | * comment 24 | */ 25 | f2: "bar" 26 | // trailing comment 27 | } 28 | 29 | service /* Comment */ Service { 30 | rpc /* Comment */ Test /* Comment */ (Test) /* Comment */ returns /* Comment */ (Test) /* Comment */ ; 31 | // Comment within a Service 32 | rpc Test2 (Test) returns (Test) { 33 | // Comment within a Method 34 | option (foo) = true; 35 | // Another comment within a Method 36 | } 37 | // Another comment within a Service 38 | } 39 | 40 | enum /* Comment */ TestEnum { 41 | // Pre comment 42 | UNSET = 0; 43 | // Middle comment 44 | TEST = 1; 45 | // Comment one 46 | // Comment two 47 | // Comment three 48 | } 49 | 50 | // This file ends with a comment -------------------------------------------------------------------------------- /bin/go-main-stubs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # 4 | # This script generates stub scripts for every Go "main" package in this 5 | # repository. These stubs execute the corresponding main package via "go run". 6 | # 7 | 8 | set -euo pipefail 9 | 10 | usage() { 11 | echo "$(basename $0) [-c] -- create or clean Go main stub scripts" 12 | exit 1 13 | } 14 | 15 | bindir="$(dirname $0)" 16 | root="$(dirname "${bindir}")" 17 | 18 | clean() { 19 | grep -l "^# go-main-stubs stub script" "${bindir}"/* | grep -v bin/go-main-stubs | xargs rm || true 20 | } 21 | 22 | while getopts ":hc" arg; do 23 | case $arg in 24 | c) 25 | echo "Cleaning old stubs" 26 | clean 27 | exit 0 28 | ;; 29 | h | *) 30 | usage 31 | exit 0 32 | ;; 33 | esac 34 | done 35 | 36 | clean 37 | 38 | echo "Creating Go main stubs in ${bindir}" 39 | 40 | echo -n . 41 | 42 | for main in $(cd "${root}" && go list -f '{{if eq "main" .Name}}{{.ImportPath}}{{end}}' ./...); do 43 | stub_script="${bindir}/$(basename $main)" 44 | cat << EOF > ${stub_script} 45 | #!/bin/bash 46 | # go-main-stubs stub script 47 | exec "\$(dirname \$0)/go" run $main "\$@" 48 | EOF 49 | chmod +x "${stub_script}" 50 | echo -n . 51 | done 52 | echo 53 | -------------------------------------------------------------------------------- /compiler/testdata/regtest.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package regtest; 4 | 5 | import "google/api/annotations.proto"; 6 | import "google/protobuf/descriptor.proto"; 7 | 8 | // A base message to be extended 9 | message BaseMessage { 10 | optional string bf1 = 1; 11 | extensions 1000 to max; 12 | } 13 | 14 | // A simple top-level extension 15 | extend BaseMessage { 16 | optional string ef1 = 1000; 17 | } 18 | 19 | // A message scope for more extensions 20 | message ExtensionMessage { 21 | optional string emf1 = 1; 22 | 23 | // An extension scoped within a message 24 | extend BaseMessage { 25 | optional ExtensionMessage ef2 = 1001; 26 | }; 27 | 28 | message NestedExtension { 29 | optional string nef1 = 1; 30 | 31 | // An extension scoped within a nested message 32 | extend BaseMessage { 33 | optional string ef3 = 1002; 34 | }; 35 | }; 36 | } 37 | 38 | // Extend a message outside this package 39 | extend google.protobuf.MethodOptions { 40 | optional BaseMessage base = 56789; 41 | }; 42 | 43 | message Empty {} 44 | 45 | // A dummy service so that annotations.proto is not reported as unused 46 | service Dummy { 47 | rpc Dummy(Empty) returns (Empty) { 48 | option (google.api.http) = { body:"*" }; 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /compiler/testdata/12_proto2_extension_no_include.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package pkg; 3 | 4 | import "google/protobuf/descriptor.proto"; 5 | 6 | enum Color { 7 | UNKNOWN = 0; 8 | RED = 1; 9 | GREEN = 2; 10 | BLUE = 3; 11 | } 12 | 13 | message M { 14 | optional group MyGroup1 = 2 { 15 | optional string s2 = 1; 16 | optional string s3 = 2; 17 | } 18 | optional string s = 1; 19 | extensions 10 to 25; 20 | optional string s2 = 30; 21 | } 22 | 23 | extend M { 24 | optional string s3 = 10; 25 | repeated string s5 = 15; 26 | optional Color color = 11; 27 | optional group MyGroup = 16 { 28 | optional string s2 = 1; 29 | optional string s3 = 2; 30 | } 31 | } 32 | 33 | extend pkg.M { 34 | optional string t1 = 19; 35 | } 36 | 37 | extend .pkg.M { 38 | optional string t2 = 20; 39 | } 40 | 41 | extend google.protobuf.MethodOptions { 42 | optional string opt1 = 72295728; 43 | optional string opt2 = 72295729; 44 | repeated string opt3 = 72295730; 45 | optional Color opt4 = 72295731; 46 | optional group MyGroup2 = 72295732 { 47 | optional string s2 = 1; 48 | optional string s3 = 2; 49 | optional group Group3 = 3 { 50 | repeated int32 i = 1; 51 | } 52 | } 53 | } 54 | 55 | message ColorMessage { 56 | optional Color color = 1; 57 | extend google.protobuf.MethodOptions { 58 | optional ColorMessage c = 72295740; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/alecthomas/kong" 8 | "github.com/alecthomas/protobuf/compiler" 9 | "google.golang.org/protobuf/proto" 10 | ) 11 | 12 | var ( 13 | // version vars set by goreleaser 14 | version = "tip" 15 | commit = "HEAD" 16 | date = "now" 17 | 18 | description = ` 19 | protobuf creates FileDescriptorSet files (.pb) from Proto source files (.proto). 20 | ` 21 | cli struct { 22 | CompileConfig 23 | Version kong.VersionFlag `help:"Show version."` 24 | } 25 | ) 26 | 27 | type CompileConfig struct { 28 | ProtoPath []string `short:"I" help:"Search paths for proto imports."` 29 | DescriptorSetOut string `short:"o" required:"" help:"FileDescriptorSet output file"` 30 | IncludeImports bool `help:"Include all dependencies of the input files so that the set is self-contained."` 31 | Files []string `arg:"" help:"Import proto files"` 32 | } 33 | 34 | func main() { 35 | kctx := kong.Parse(&cli, 36 | kong.Description(description), 37 | kong.Vars{"version": fmt.Sprintf("%s (%s on %s)", version, commit, date)}, 38 | ) 39 | kctx.FatalIfErrorf(kctx.Run()) 40 | } 41 | 42 | func (c *CompileConfig) Run() error { 43 | fds, err := compiler.Compile(c.Files, c.ProtoPath, c.IncludeImports) 44 | if err != nil { 45 | return err 46 | } 47 | b, err := proto.Marshal(fds) 48 | if err != nil { 49 | return err 50 | } 51 | f, err := os.Create(c.DescriptorSetOut) 52 | if err != nil { 53 | return err 54 | } 55 | _, err = f.Write(b) 56 | return err 57 | } 58 | 59 | func (c *CompileConfig) AfterApply() error { 60 | if len(c.Files) == 0 { 61 | return fmt.Errorf(`missing .proto input file(s)`) 62 | } 63 | return nil 64 | } 65 | -------------------------------------------------------------------------------- /compiler/testdata/19_proto3_non_custom_options.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package pkg; 4 | 5 | import "google/protobuf/descriptor.proto"; 6 | 7 | option java_package = "java_package"; 8 | option java_outer_classname = "java_outer_classname"; 9 | option go_package = "go_package"; 10 | option objc_class_prefix = "PKG"; 11 | option csharp_namespace = "csharp_namespace"; 12 | option swift_prefix = "swift_prefix"; 13 | option php_class_prefix = "php_class_prefix"; 14 | option php_namespace = "php_namespace"; 15 | option php_metadata_namespace = "php_metadata_namespace"; 16 | option ruby_package = "ruby_package"; 17 | 18 | option java_multiple_files = true; 19 | option java_generate_equals_and_hash = true; 20 | option java_string_check_utf8 = false; 21 | option cc_generic_services = true; 22 | option java_generic_services = false; 23 | option py_generic_services = true; 24 | option php_generic_services = false; 25 | option deprecated = true; 26 | option cc_enable_arenas = true; 27 | option optimize_for = CODE_SIZE; 28 | 29 | message M { 30 | message Sub { 31 | optional int64 sub = 1; 32 | } 33 | optional string f1 = 1 [ ctype = CORD]; 34 | repeated int32 f2 = 2 [ packed = true, ctype = STRING_PIECE]; 35 | optional int64 f3 = 3 [ jstype = JS_NUMBER]; 36 | optional Sub f4 = 4 [ lazy = true]; 37 | optional int32 f5 = 5 [ deprecated = true]; 38 | } 39 | 40 | service Greeter { 41 | option deprecated = true; 42 | rpc Hello (M) returns (M){ 43 | option idempotency_level = NO_SIDE_EFFECTS; 44 | }; 45 | rpc Hello2 (M) returns (M){ 46 | option idempotency_level = IDEMPOTENT; 47 | option deprecated = false; 48 | }; 49 | rpc Hello3 (M) returns (M){ 50 | option deprecated = true; 51 | }; 52 | } 53 | 54 | enum Color { 55 | option deprecated = true; 56 | UNKNOWN = 0; 57 | BLUE = 12 [deprecated = false]; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /compiler/testdata/14_proto2_group.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package pkg; 3 | 4 | message M { 5 | optional group Group1 = 1 { 6 | optional string s2 = 2; 7 | optional string s3 = 3; 8 | } 9 | repeated group Group2 = 2 { 10 | optional string s5 = 5; 11 | optional string s6 = 6; 12 | repeated group Group3 = 7 { 13 | optional string s8 = 8; 14 | } 15 | } 16 | } 17 | 18 | message M2 { 19 | optional M.Group1 g1 = 1; 20 | optional pkg.M.Group1 g2 = 2; 21 | optional .pkg.M.Group1 g3 = 3; 22 | } 23 | 24 | message M3 { 25 | optional M.Group2.Group3 g1 = 1; 26 | optional pkg.M.Group2.Group3 g2 = 2; 27 | optional .pkg.M.Group2.Group3 g3 = 3; 28 | } 29 | 30 | message Nest { 31 | message Egg { 32 | optional group Group1 = 1 { 33 | optional string s2 = 2; 34 | optional string s3 = 3; 35 | } 36 | } 37 | } 38 | 39 | message Nest1 { 40 | optional Nest.Egg.Group1 g1 = 1; 41 | optional pkg.Nest.Egg.Group1 g2 = 2; 42 | optional .pkg.Nest.Egg.Group1 g3 = 3; 43 | } 44 | 45 | message Bento { 46 | optional group Box = 1 { 47 | message Condiment { 48 | optional bool wasabi = 10; 49 | } 50 | optional string s2 = 2; 51 | optional string s3 = 3; 52 | } 53 | } 54 | 55 | message Bento1 { 56 | optional Bento.Box.Condiment takeaway = 1; 57 | optional pkg.Bento.Box.Condiment byo = 2; 58 | optional .pkg.Bento.Box.Condiment byo2 = 3; 59 | } 60 | 61 | message GroupedEnum { 62 | optional group G1 = 1 { 63 | enum Color { 64 | UNKNOWN = 0; 65 | RED = 1; 66 | GREEN = 2; 67 | BLUE = 3; 68 | } 69 | optional Color color = 4; 70 | } 71 | optional G1.Color color = 5; 72 | } 73 | 74 | message GroupedEnum1 { 75 | optional GroupedEnum.G1.Color c1 = 1; 76 | optional pkg.GroupedEnum.G1.Color c2 = 2; 77 | optional .pkg.GroupedEnum.G1.Color c3 = 3; 78 | } 79 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_import_public.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: liujisi@google.com (Pherl Liu) 32 | 33 | syntax = "proto2"; 34 | 35 | package protobuf_unittest_import; 36 | 37 | option java_package = "com.google.protobuf.test"; 38 | 39 | message PublicImportMessage { 40 | optional int32 e = 1; 41 | } 42 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_arena.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package proto2_arena_unittest; 34 | 35 | option cc_enable_arenas = true; 36 | 37 | message NestedMessage { 38 | optional int32 d = 1; 39 | } 40 | 41 | message ArenaMessage { 42 | repeated NestedMessage repeated_nested_message = 1; 43 | } 44 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/unittest_import_public.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: liujisi@google.com (Pherl Liu) 32 | 33 | syntax = "proto2"; 34 | 35 | package protobuf_unittest_import; 36 | 37 | option java_package = "com.google.protobuf.test"; 38 | 39 | message PublicImportMessage { 40 | optional int32 e = 1; 41 | } 42 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_empty.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // This file intentionally left blank. (At one point this wouldn't compile 36 | // correctly.) 37 | 38 | syntax = "proto2"; 39 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/unittest_arena.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package proto2_arena_unittest; 34 | 35 | option cc_enable_arenas = true; 36 | 37 | message NestedMessage { 38 | optional int32 d = 1; 39 | } 40 | 41 | message ArenaMessage { 42 | repeated NestedMessage repeated_nested_message = 1; 43 | } 44 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/unittest_empty.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // This file intentionally left blank. (At one point this wouldn't compile 36 | // correctly.) 37 | 38 | syntax = "proto2"; 39 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_import_public_lite.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: liujisi@google.com (Pherl Liu) 32 | 33 | syntax = "proto2"; 34 | 35 | package protobuf_unittest_import; 36 | 37 | option optimize_for = LITE_RUNTIME; 38 | 39 | option java_package = "com.google.protobuf"; 40 | 41 | message PublicImportMessageLite { 42 | optional int32 e = 1; 43 | } 44 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/unittest_import_public_lite.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: liujisi@google.com (Pherl Liu) 32 | 33 | syntax = "proto2"; 34 | 35 | package protobuf_unittest_import; 36 | 37 | option optimize_for = LITE_RUNTIME; 38 | 39 | option java_package = "com.google.protobuf"; 40 | 41 | message PublicImportMessageLite { 42 | optional int32 e = 1; 43 | } 44 | -------------------------------------------------------------------------------- /testdata/conformance/any_test.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package protobuf_unittest; 34 | 35 | import "google/protobuf/any.proto"; 36 | 37 | option java_outer_classname = "TestAnyProto"; 38 | 39 | message TestAny { 40 | int32 int32_value = 1; 41 | google.protobuf.Any any_value = 2; 42 | repeated google.protobuf.Any repeated_any_value = 3; 43 | string text = 4; 44 | } 45 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/any_test.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package protobuf_unittest; 34 | 35 | import "google/protobuf/any.proto"; 36 | 37 | option java_outer_classname = "TestAnyProto"; 38 | 39 | message TestAny { 40 | int32 int32_value = 1; 41 | google.protobuf.Any any_value = 2; 42 | repeated google.protobuf.Any repeated_any_value = 3; 43 | string text = 4; 44 | } 45 | -------------------------------------------------------------------------------- /compiler/testdata/19_proto2_non_custom_options.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package pkg; 4 | 5 | import "google/protobuf/descriptor.proto"; 6 | 7 | option java_package = "java_package"; 8 | option java_outer_classname = "java_outer_classname"; 9 | option go_package = "go_package"; 10 | option objc_class_prefix = "PKG"; 11 | option csharp_namespace = "csharp_namespace"; 12 | option swift_prefix = "swift_prefix"; 13 | option php_class_prefix = "php_class_prefix"; 14 | option php_namespace = "php_namespace"; 15 | option php_metadata_namespace = "php_metadata_namespace"; 16 | option ruby_package = "ruby_package"; 17 | 18 | option java_multiple_files = true; 19 | option java_generate_equals_and_hash = true; 20 | option java_string_check_utf8 = false; 21 | option cc_generic_services = true; 22 | option java_generic_services = false; 23 | option py_generic_services = true; 24 | option php_generic_services = false; 25 | option deprecated = true; 26 | option cc_enable_arenas = true; 27 | option optimize_for = CODE_SIZE; 28 | 29 | extend google.protobuf.ExtensionRangeOptions { 30 | optional bool custom = 1000; 31 | } 32 | 33 | message M { 34 | message Sub { 35 | optional int64 sub = 1; 36 | } 37 | optional string f1 = 1 [ ctype = CORD]; 38 | repeated int32 f2 = 2 [ packed = true, ctype = STRING_PIECE]; 39 | optional int64 f3 = 3 [ jstype = JS_NUMBER]; 40 | optional Sub f4 = 4 [ lazy = true]; 41 | optional int32 f5 = 5 [ deprecated = true]; 42 | optional int32 f6 = 6 [ default = 42]; 43 | optional int32 f7 = 7 [ default = 13, deprecated = true]; 44 | optional group SubGroup = 8 [ deprecated = true] { 45 | optional int32 sgf1 = 1; 46 | } 47 | extensions 100, 105 to 109 [(custom) = true]; 48 | } 49 | 50 | service Greeter { 51 | option deprecated = true; 52 | rpc Hello (M) returns (M){ 53 | option idempotency_level = NO_SIDE_EFFECTS; 54 | }; 55 | rpc Hello2 (M) returns (M){ 56 | option idempotency_level = IDEMPOTENT; 57 | option deprecated = false; 58 | }; 59 | rpc Hello3 (M) returns (M){ 60 | option deprecated = true; 61 | }; 62 | } 63 | 64 | enum Color { 65 | option deprecated = true; 66 | UNKNOWN = 0; 67 | BLUE = 12 [deprecated = false]; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /main_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "path/filepath" 6 | "strings" 7 | "testing" 8 | 9 | "github.com/alecthomas/protobuf/compiler" 10 | "github.com/google/go-cmp/cmp" 11 | "github.com/stretchr/testify/require" 12 | "google.golang.org/protobuf/proto" 13 | "google.golang.org/protobuf/testing/protocmp" 14 | pb "google.golang.org/protobuf/types/descriptorpb" 15 | ) 16 | 17 | func TestFiledescriptorSetConformance(t *testing.T) { 18 | files, err := filepath.Glob("testdata/conformance/*.proto") 19 | require.NoError(t, err) 20 | for _, file := range files { 21 | t.Run(file, func(t *testing.T) { 22 | fdName := filepath.Base(file) 23 | importPaths := []string{"testdata/conformance/"} 24 | 25 | includeImports := true 26 | name := strings.TrimSuffix(fdName, ".proto") 27 | 28 | got, err := compiler.Compile([]string{fdName}, importPaths, includeImports) 29 | require.NoError(t, err) 30 | want := loadPB(t, "testdata/conformance/pb/"+name+".pb") 31 | require.Equal(t, len(got.File), len(want.File)) 32 | requireProtoEqual(t, want, got) 33 | }) 34 | } 35 | } 36 | 37 | func requireProtoEqual(t *testing.T, want, got proto.Message) { 38 | t.Helper() 39 | if proto.Equal(want, got) { 40 | return 41 | } 42 | if diff := cmp.Diff(want, got, protocmp.Transform()); diff != "" { 43 | t.Errorf("not equal (-want +got):\n%s", diff) 44 | } 45 | } 46 | 47 | func loadPB(t *testing.T, file string) *pb.FileDescriptorSet { 48 | t.Helper() 49 | pbBytes, err := os.ReadFile(file) 50 | require.NoError(t, err) 51 | fds := &pb.FileDescriptorSet{} 52 | err = proto.Unmarshal(pbBytes, fds) 53 | require.NoError(t, err) 54 | 55 | // Unmarshal again using the fds we just created as a resolver registry 56 | // so that extensions can be resolved properly. Without this, the 57 | // extension fields appear as RawFields which can have different 58 | // representations of the same field due to ordering, and then they 59 | // dont compare as equal when they semantically are. Properly resolving 60 | // extensions makes the comparison work. 61 | reg, err := compiler.NewRegistry(fds) 62 | require.NoError(t, err) 63 | err = proto.UnmarshalOptions{Resolver: reg}.Unmarshal(pbBytes, fds) 64 | require.NoError(t, err) 65 | return fds 66 | } 67 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_preserve_unknown_enum2.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package proto2_preserve_unknown_enum_unittest; 34 | 35 | enum MyEnum { 36 | FOO = 0; 37 | BAR = 1; 38 | BAZ = 2; 39 | } 40 | 41 | message MyMessage { 42 | optional MyEnum e = 1; 43 | repeated MyEnum repeated_e = 2; 44 | repeated MyEnum repeated_packed_e = 3 [packed=true]; 45 | repeated MyEnum repeated_packed_unexpected_e = 4; // not packed 46 | oneof o { 47 | MyEnum oneof_e_1 = 5; 48 | MyEnum oneof_e_2 = 6; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/unittest_preserve_unknown_enum2.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package proto2_preserve_unknown_enum_unittest; 34 | 35 | enum MyEnum { 36 | FOO = 0; 37 | BAR = 1; 38 | BAZ = 2; 39 | } 40 | 41 | message MyMessage { 42 | optional MyEnum e = 1; 43 | repeated MyEnum repeated_e = 2; 44 | repeated MyEnum repeated_packed_e = 3 [packed=true]; 45 | repeated MyEnum repeated_packed_unexpected_e = 4; // not packed 46 | oneof o { 47 | MyEnum oneof_e_1 = 5; 48 | MyEnum oneof_e_2 = 6; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_lite_imports_nonlite.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // 33 | // Tests that a "lite" message can import a regular message. 34 | 35 | syntax = "proto2"; 36 | package protobuf_unittest; 37 | 38 | import "google/protobuf/unittest.proto"; 39 | 40 | option optimize_for = LITE_RUNTIME; 41 | 42 | message TestLiteImportsNonlite { 43 | optional TestAllTypes message = 1; 44 | 45 | // Verifies that transitive required fields generates valid code. 46 | optional TestRequired message_with_required = 2; 47 | } 48 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_no_generic_services.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | 33 | syntax = "proto2"; 34 | 35 | package protobuf_unittest.no_generic_services_test; 36 | 37 | 38 | // *_generic_services are false by default. 39 | 40 | message TestMessage { 41 | optional int32 a = 1; 42 | extensions 1000 to max; 43 | } 44 | 45 | enum TestEnum { FOO = 1; } 46 | 47 | extend TestMessage { 48 | optional int32 test_extension = 1000; 49 | } 50 | 51 | service TestService { 52 | rpc Foo(TestMessage) returns (TestMessage); 53 | } 54 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/unittest_lite_imports_nonlite.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // 33 | // Tests that a "lite" message can import a regular message. 34 | 35 | syntax = "proto2"; 36 | package protobuf_unittest; 37 | 38 | import "google/protobuf/unittest.proto"; 39 | 40 | option optimize_for = LITE_RUNTIME; 41 | 42 | message TestLiteImportsNonlite { 43 | optional TestAllTypes message = 1; 44 | 45 | // Verifies that transitive required fields generates valid code. 46 | optional TestRequired message_with_required = 2; 47 | } 48 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/unittest_no_generic_services.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | 33 | syntax = "proto2"; 34 | 35 | package protobuf_unittest.no_generic_services_test; 36 | 37 | 38 | // *_generic_services are false by default. 39 | 40 | message TestMessage { 41 | optional int32 a = 1; 42 | extensions 1000 to max; 43 | } 44 | 45 | enum TestEnum { FOO = 1; } 46 | 47 | extend TestMessage { 48 | optional int32 test_extension = 1000; 49 | } 50 | 51 | service TestService { 52 | rpc Foo(TestMessage) returns (TestMessage); 53 | } 54 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_import_lite.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // 33 | // This is like unittest_import.proto but with optimize_for = LITE_RUNTIME. 34 | 35 | syntax = "proto2"; 36 | package protobuf_unittest_import; 37 | 38 | option optimize_for = LITE_RUNTIME; 39 | 40 | option java_package = "com.google.protobuf"; 41 | 42 | import public "google/protobuf/unittest_import_public_lite.proto"; 43 | 44 | message ImportMessageLite { 45 | optional int32 d = 1; 46 | } 47 | 48 | enum ImportEnumLite { 49 | IMPORT_LITE_FOO = 7; 50 | IMPORT_LITE_BAR = 8; 51 | IMPORT_LITE_BAZ = 9; 52 | } 53 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/unittest_import_lite.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // 33 | // This is like unittest_import.proto but with optimize_for = LITE_RUNTIME. 34 | 35 | syntax = "proto2"; 36 | package protobuf_unittest_import; 37 | 38 | option optimize_for = LITE_RUNTIME; 39 | 40 | option java_package = "com.google.protobuf"; 41 | 42 | import public "google/protobuf/unittest_import_public_lite.proto"; 43 | 44 | message ImportMessageLite { 45 | optional int32 d = 1; 46 | } 47 | 48 | enum ImportEnumLite { 49 | IMPORT_LITE_FOO = 7; 50 | IMPORT_LITE_BAR = 8; 51 | IMPORT_LITE_BAZ = 9; 52 | } 53 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_drop_unknown_fields.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package unittest_drop_unknown_fields; 34 | 35 | option objc_class_prefix = "DropUnknowns"; 36 | option csharp_namespace = "Google.Protobuf.TestProtos"; 37 | 38 | message Foo { 39 | enum NestedEnum { 40 | FOO = 0; 41 | BAR = 1; 42 | BAZ = 2; 43 | } 44 | int32 int32_value = 1; 45 | NestedEnum enum_value = 2; 46 | } 47 | 48 | message FooWithExtraFields { 49 | enum NestedEnum { 50 | FOO = 0; 51 | BAR = 1; 52 | BAZ = 2; 53 | MOO = 3; 54 | } 55 | int32 int32_value = 1; 56 | NestedEnum enum_value = 2; 57 | int32 extra_int32_value = 3; 58 | } 59 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/unittest_drop_unknown_fields.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package unittest_drop_unknown_fields; 34 | 35 | option objc_class_prefix = "DropUnknowns"; 36 | option csharp_namespace = "Google.Protobuf.TestProtos"; 37 | 38 | message Foo { 39 | enum NestedEnum { 40 | FOO = 0; 41 | BAR = 1; 42 | BAZ = 2; 43 | } 44 | int32 int32_value = 1; 45 | NestedEnum enum_value = 2; 46 | } 47 | 48 | message FooWithExtraFields { 49 | enum NestedEnum { 50 | FOO = 0; 51 | BAR = 1; 52 | BAZ = 2; 53 | MOO = 3; 54 | } 55 | int32 int32_value = 1; 56 | NestedEnum enum_value = 2; 57 | int32 extra_int32_value = 3; 58 | } 59 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | # Exhaustive list of options here: 2 | # https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml 3 | run: 4 | deadline: 5m 5 | tests: true 6 | 7 | output: 8 | print-issued-lines: false 9 | 10 | linters: 11 | enable-all: true 12 | disable: 13 | - exhaustivestruct 14 | - forbidigo 15 | - gci 16 | - gochecknoglobals 17 | - goconst 18 | - godot 19 | - godox 20 | - golint 21 | - gomnd 22 | - interfacer 23 | - ireturn 24 | - lll 25 | - maligned 26 | - nlreturn 27 | - noctx 28 | - revive 29 | - scopelint 30 | - wsl 31 | - paralleltest 32 | - wrapcheck 33 | - testpackage 34 | - varnamelen 35 | - funlen 36 | - cyclop 37 | - gocognit 38 | - gofumpt 39 | - exhaustruct 40 | - nosnakecase 41 | - nolintlint 42 | - nonamedreturns 43 | - gofmt 44 | - goimports 45 | 46 | linters-settings: 47 | govet: 48 | check-shadowing: true 49 | golint: 50 | min-confidence: 0 51 | dupl: 52 | threshold: 100 53 | goconst: 54 | min-len: 4 55 | min-occurrences: 3 56 | gocyclo: 57 | min-complexity: 25 # TODO (dweisberg) Lower this after refactor 58 | 59 | issues: 60 | max-per-linter: 20 61 | max-same: 0 62 | exclude-use-default: false 63 | exclude: 64 | # err shadowing 65 | - 'declaration of "err" shadows declaration at' 66 | # wrapcheck for errors.WithStack 67 | - 'github.com/pkg/errors.WithStack' 68 | # Params are often used as the input to action rollbacks and then converted into appropriate locators 69 | - 'should convert params .*Params.*Locator' 70 | # Captured by errcheck. 71 | - '^(G104|G204):' 72 | # Very commonly not checked. 73 | - 'Error return value of .(.*\.Help|.*\.MarkFlagRequired|Delete.*|(os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked' 74 | # Exclude Kong convenience tags (these can actually be made conformant with eg. `cmd:""`, but eh) 75 | - 'struct field tag .*(cmd|arg|required).* not compatible with reflect.StructTag.Get: bad syntax for struct tag pair' 76 | # gas: False positive is triggered by 'src, err := ioutil.ReadFile(filename)' 77 | - 'Potential file inclusion via variable' 78 | # Allow creating directories with 755 permissions 79 | - '^(G301|G307|G107):' 80 | - "unless it's in another file for this package" 81 | - "err113: do not define dynamic errors" 82 | -------------------------------------------------------------------------------- /compiler/compiler_test.go: -------------------------------------------------------------------------------- 1 | package compiler 2 | 3 | import ( 4 | "os" 5 | "path/filepath" 6 | "strings" 7 | "testing" 8 | 9 | "github.com/google/go-cmp/cmp" 10 | "github.com/stretchr/testify/require" 11 | "google.golang.org/protobuf/proto" 12 | "google.golang.org/protobuf/reflect/protodesc" 13 | "google.golang.org/protobuf/testing/protocmp" 14 | pb "google.golang.org/protobuf/types/descriptorpb" 15 | ) 16 | 17 | func requireProtoEqual(t *testing.T, want, got proto.Message) { 18 | t.Helper() 19 | if proto.Equal(want, got) { 20 | return 21 | } 22 | if diff := cmp.Diff(want, got, protocmp.Transform()); diff != "" { 23 | t.Errorf("not equal (-want +got):\n%s", diff) 24 | } 25 | } 26 | 27 | func TestFiledescriptorSet(t *testing.T) { 28 | files, err := filepath.Glob("testdata/*.proto") 29 | require.NoError(t, err) 30 | for _, file := range files { 31 | t.Run(file, func(t *testing.T) { 32 | fdName := strings.TrimPrefix(file, "testdata/") 33 | importPaths := []string{"testdata"} 34 | 35 | includeImports := true 36 | name := strings.TrimSuffix(filepath.Base(file), ".proto") 37 | if strings.HasSuffix(name, "_no_include") { 38 | includeImports = false 39 | } 40 | 41 | got, err := Compile([]string{fdName}, importPaths, includeImports) 42 | require.NoError(t, err) 43 | want := loadPB(t, "testdata/pb/"+name+".pb") 44 | require.Equal(t, len(got.File), len(want.File)) 45 | requireProtoEqual(t, want, got) 46 | }) 47 | } 48 | } 49 | 50 | func loadPB(t *testing.T, file string) *pb.FileDescriptorSet { 51 | t.Helper() 52 | pbBytes, err := os.ReadFile(file) 53 | require.NoError(t, err) 54 | fds := &pb.FileDescriptorSet{} 55 | err = proto.Unmarshal(pbBytes, fds) 56 | require.NoError(t, err) 57 | 58 | // Unmarshal again using the fds we just created as a resolver registry 59 | // so that extensions can be resolved properly. Without this, the 60 | // extension fields appear as RawFields which can have different 61 | // representations of the same field due to ordering, and then they 62 | // dont compare as equal when they semantically are. Properly resolving 63 | // extensions makes the comparison work. 64 | // We need to AllowUnresolvable as the _no_include pb files will not 65 | // load without it as it cannot resolve the imports. 66 | f, err := protodesc.FileOptions{AllowUnresolvable: true}.NewFiles(fds) 67 | require.NoError(t, err) 68 | reg := &Registry{Files: *f} 69 | err = proto.UnmarshalOptions{Resolver: reg}.Unmarshal(pbBytes, fds) 70 | require.NoError(t, err) 71 | return fds 72 | } 73 | -------------------------------------------------------------------------------- /testdata/conformance/source_context.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option java_package = "com.google.protobuf"; 37 | option java_outer_classname = "SourceContextProto"; 38 | option java_multiple_files = true; 39 | option objc_class_prefix = "GPB"; 40 | option go_package = "google.golang.org/protobuf/types/known/sourcecontextpb"; 41 | 42 | // `SourceContext` represents information about the source of a 43 | // protobuf element, like the file in which it is defined. 44 | message SourceContext { 45 | // The path-qualified name of the .proto file that contained the associated 46 | // protobuf element. For example: `"google/protobuf/source_context.proto"`. 47 | string file_name = 1; 48 | } 49 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/source_context.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option java_package = "com.google.protobuf"; 37 | option java_outer_classname = "SourceContextProto"; 38 | option java_multiple_files = true; 39 | option objc_class_prefix = "GPB"; 40 | option go_package = "google.golang.org/protobuf/types/known/sourcecontextpb"; 41 | 42 | // `SourceContext` represents information about the source of a 43 | // protobuf element, like the file in which it is defined. 44 | message SourceContext { 45 | // The path-qualified name of the .proto file that contained the associated 46 | // protobuf element. For example: `"google/protobuf/source_context.proto"`. 47 | string file_name = 1; 48 | } 49 | -------------------------------------------------------------------------------- /testdata/conformance/empty.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option go_package = "google.golang.org/protobuf/types/known/emptypb"; 37 | option java_package = "com.google.protobuf"; 38 | option java_outer_classname = "EmptyProto"; 39 | option java_multiple_files = true; 40 | option objc_class_prefix = "GPB"; 41 | option cc_enable_arenas = true; 42 | 43 | // A generic empty message that you can re-use to avoid defining duplicated 44 | // empty messages in your APIs. A typical example is to use it as the request 45 | // or the response type of an API method. For instance: 46 | // 47 | // service Foo { 48 | // rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); 49 | // } 50 | // 51 | message Empty {} 52 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/empty.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option go_package = "google.golang.org/protobuf/types/known/emptypb"; 37 | option java_package = "com.google.protobuf"; 38 | option java_outer_classname = "EmptyProto"; 39 | option java_multiple_files = true; 40 | option objc_class_prefix = "GPB"; 41 | option cc_enable_arenas = true; 42 | 43 | // A generic empty message that you can re-use to avoid defining duplicated 44 | // empty messages in your APIs. A typical example is to use it as the request 45 | // or the response type of an API method. For instance: 46 | // 47 | // service Foo { 48 | // rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); 49 | // } 50 | // 51 | message Empty {} 52 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_embed_optimize_for.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // A proto file which imports a proto file that uses optimize_for = CODE_SIZE. 36 | 37 | syntax = "proto2"; 38 | import "google/protobuf/unittest_optimize_for.proto"; 39 | 40 | package protobuf_unittest; 41 | 42 | // We optimize for speed here, but we are importing a proto that is optimized 43 | // for code size. 44 | option optimize_for = SPEED; 45 | 46 | message TestEmbedOptimizedForSize { 47 | // Test that embedding a message which has optimize_for = CODE_SIZE into 48 | // one optimized for speed works. 49 | optional TestOptimizedForSize optional_message = 1; 50 | repeated TestOptimizedForSize repeated_message = 2; 51 | } 52 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/unittest_embed_optimize_for.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // A proto file which imports a proto file that uses optimize_for = CODE_SIZE. 36 | 37 | syntax = "proto2"; 38 | import "google/protobuf/unittest_optimize_for.proto"; 39 | 40 | package protobuf_unittest; 41 | 42 | // We optimize for speed here, but we are importing a proto that is optimized 43 | // for code size. 44 | option optimize_for = SPEED; 45 | 46 | message TestEmbedOptimizedForSize { 47 | // Test that embedding a message which has optimize_for = CODE_SIZE into 48 | // one optimized for speed works. 49 | optional TestOptimizedForSize optional_message = 1; 50 | repeated TestOptimizedForSize repeated_message = 2; 51 | } 52 | -------------------------------------------------------------------------------- /testdata/conformance/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 | package proto2_wireformat_unittest; 39 | 40 | option cc_enable_arenas = true; 41 | option optimize_for = SPEED; 42 | option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 43 | 44 | // A message with message_set_wire_format. 45 | message TestMessageSet { 46 | // MessageSets are not supported by the Go protobuf implemetation. 47 | // We could build with `-tags protolegacy`, but we dont need this. 48 | // option message_set_wire_format = true; 49 | extensions 4 to max; 50 | } 51 | 52 | message TestMessageSetWireFormatContainer { 53 | optional TestMessageSet message_set = 1; 54 | } 55 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/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 | package proto2_wireformat_unittest; 39 | 40 | option cc_enable_arenas = true; 41 | option optimize_for = SPEED; 42 | option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 43 | 44 | // A message with message_set_wire_format. 45 | message TestMessageSet { 46 | // MessageSets are not supported by the Go protobuf implemetation. 47 | // We could build with `-tags protolegacy`, but we dont need this. 48 | // option message_set_wire_format = true; 49 | extensions 4 to max; 50 | } 51 | 52 | message TestMessageSetWireFormatContainer { 53 | optional TestMessageSet message_set = 1; 54 | } 55 | -------------------------------------------------------------------------------- /testdata/patches/no_message_sets.patch: -------------------------------------------------------------------------------- 1 | diff --git a/src/google/protobuf/test_messages_proto2.proto b/src/google/protobuf/test_messages_proto2.proto 2 | index c7b9c487a..86b04fc65 100644 3 | --- a/src/google/protobuf/test_messages_proto2.proto 4 | +++ b/src/google/protobuf/test_messages_proto2.proto 5 | @@ -237,7 +237,9 @@ message TestAllTypesProto2 { 6 | 7 | // message_set test case. 8 | message MessageSetCorrect { 9 | - option message_set_wire_format = true; 10 | + // MessageSets are not supported by the Go protobuf implemetation. 11 | + // We could build with `-tags protolegacy`, but we dont need this. 12 | + // option message_set_wire_format = true; 13 | 14 | extensions 4 to max; 15 | } 16 | diff --git a/src/google/protobuf/unittest_custom_options.proto b/src/google/protobuf/unittest_custom_options.proto 17 | index 1812d71ee..9a2b57ae2 100644 18 | --- a/src/google/protobuf/unittest_custom_options.proto 19 | +++ b/src/google/protobuf/unittest_custom_options.proto 20 | @@ -304,7 +304,9 @@ message VariousComplexOptions { 21 | // See descriptor_unittest.cc. 22 | 23 | message AggregateMessageSet { 24 | - option message_set_wire_format = true; 25 | + // MessageSets are not supported by the Go protobuf implemetation. 26 | + // We could build with `-tags protolegacy`, but we dont need this. 27 | + // option message_set_wire_format = true; 28 | 29 | extensions 4 to max; 30 | } 31 | diff --git a/src/google/protobuf/unittest_lite.proto b/src/google/protobuf/unittest_lite.proto 32 | index e2730acdb..bf8163102 100644 33 | --- a/src/google/protobuf/unittest_lite.proto 34 | +++ b/src/google/protobuf/unittest_lite.proto 35 | @@ -470,7 +470,9 @@ message TestOneofParsingLite { 36 | } 37 | 38 | message TestMessageSetLite { 39 | - option message_set_wire_format = true; 40 | + // MessageSets are not supported by the Go protobuf implemetation. 41 | + // We could build with `-tags protolegacy`, but we dont need this. 42 | + // option message_set_wire_format = true; 43 | 44 | extensions 100 to max; 45 | } 46 | diff --git a/src/google/protobuf/unittest_mset_wire_format.proto b/src/google/protobuf/unittest_mset_wire_format.proto 47 | index 04e4352e0..9d628fe7b 100644 48 | --- a/src/google/protobuf/unittest_mset_wire_format.proto 49 | +++ b/src/google/protobuf/unittest_mset_wire_format.proto 50 | @@ -43,7 +43,9 @@ option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; 51 | 52 | // A message with message_set_wire_format. 53 | message TestMessageSet { 54 | - option message_set_wire_format = true; 55 | + // MessageSets are not supported by the Go protobuf implemetation. 56 | + // We could build with `-tags protolegacy`, but we dont need this. 57 | + // option message_set_wire_format = true; 58 | extensions 4 to max; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_optimize_for.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // A proto file which uses optimize_for = CODE_SIZE. 36 | 37 | syntax = "proto2"; 38 | import "google/protobuf/unittest.proto"; 39 | 40 | package protobuf_unittest; 41 | 42 | option optimize_for = CODE_SIZE; 43 | 44 | message TestOptimizedForSize { 45 | optional int32 i = 1; 46 | optional ForeignMessage msg = 19; 47 | 48 | extensions 1000 to max; 49 | 50 | extend TestOptimizedForSize { 51 | optional int32 test_extension = 1234; 52 | optional TestRequiredOptimizedForSize test_extension2 = 1235; 53 | } 54 | 55 | oneof foo { 56 | int32 integer_field = 2; 57 | string string_field = 3; 58 | } 59 | } 60 | 61 | message TestRequiredOptimizedForSize { 62 | required int32 x = 1; 63 | } 64 | 65 | message TestOptionalOptimizedForSize { 66 | optional TestRequiredOptimizedForSize o = 1; 67 | } 68 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/unittest_optimize_for.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // A proto file which uses optimize_for = CODE_SIZE. 36 | 37 | syntax = "proto2"; 38 | import "google/protobuf/unittest.proto"; 39 | 40 | package protobuf_unittest; 41 | 42 | option optimize_for = CODE_SIZE; 43 | 44 | message TestOptimizedForSize { 45 | optional int32 i = 1; 46 | optional ForeignMessage msg = 19; 47 | 48 | extensions 1000 to max; 49 | 50 | extend TestOptimizedForSize { 51 | optional int32 test_extension = 1234; 52 | optional TestRequiredOptimizedForSize test_extension2 = 1235; 53 | } 54 | 55 | oneof foo { 56 | int32 integer_field = 2; 57 | string string_field = 3; 58 | } 59 | } 60 | 61 | message TestRequiredOptimizedForSize { 62 | required int32 x = 1; 63 | } 64 | 65 | message TestOptionalOptimizedForSize { 66 | optional TestRequiredOptimizedForSize o = 1; 67 | } 68 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_preserve_unknown_enum.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package proto3_preserve_unknown_enum_unittest; 34 | option objc_class_prefix = "UnknownEnums"; 35 | 36 | option csharp_namespace = "Google.Protobuf.TestProtos"; 37 | 38 | enum MyEnum { 39 | FOO = 0; 40 | BAR = 1; 41 | BAZ = 2; 42 | } 43 | 44 | enum MyEnumPlusExtra { 45 | E_FOO = 0; 46 | E_BAR = 1; 47 | E_BAZ = 2; 48 | E_EXTRA = 3; 49 | } 50 | 51 | message MyMessage { 52 | MyEnum e = 1; 53 | repeated MyEnum repeated_e = 2; 54 | repeated MyEnum repeated_packed_e = 3 [packed=true]; 55 | repeated MyEnumPlusExtra repeated_packed_unexpected_e = 4; // not packed 56 | oneof o { 57 | MyEnum oneof_e_1 = 5; 58 | MyEnum oneof_e_2 = 6; 59 | } 60 | } 61 | 62 | message MyMessagePlusExtra { 63 | MyEnumPlusExtra e = 1; 64 | repeated MyEnumPlusExtra repeated_e = 2; 65 | repeated MyEnumPlusExtra repeated_packed_e = 3 [packed=true]; 66 | repeated MyEnumPlusExtra repeated_packed_unexpected_e = 4 [packed=true]; 67 | oneof o { 68 | MyEnumPlusExtra oneof_e_1 = 5; 69 | MyEnumPlusExtra oneof_e_2 = 6; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/unittest_preserve_unknown_enum.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package proto3_preserve_unknown_enum_unittest; 34 | option objc_class_prefix = "UnknownEnums"; 35 | 36 | option csharp_namespace = "Google.Protobuf.TestProtos"; 37 | 38 | enum MyEnum { 39 | FOO = 0; 40 | BAR = 1; 41 | BAZ = 2; 42 | } 43 | 44 | enum MyEnumPlusExtra { 45 | E_FOO = 0; 46 | E_BAR = 1; 47 | E_BAZ = 2; 48 | E_EXTRA = 3; 49 | } 50 | 51 | message MyMessage { 52 | MyEnum e = 1; 53 | repeated MyEnum repeated_e = 2; 54 | repeated MyEnum repeated_packed_e = 3 [packed=true]; 55 | repeated MyEnumPlusExtra repeated_packed_unexpected_e = 4; // not packed 56 | oneof o { 57 | MyEnum oneof_e_1 = 5; 58 | MyEnum oneof_e_2 = 6; 59 | } 60 | } 61 | 62 | message MyMessagePlusExtra { 63 | MyEnumPlusExtra e = 1; 64 | repeated MyEnumPlusExtra repeated_e = 2; 65 | repeated MyEnumPlusExtra repeated_packed_e = 3 [packed=true]; 66 | repeated MyEnumPlusExtra repeated_packed_unexpected_e = 4 [packed=true]; 67 | oneof o { 68 | MyEnumPlusExtra oneof_e_1 = 5; 69 | MyEnumPlusExtra oneof_e_2 = 6; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_import.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // A proto file which is imported by unittest.proto to test importing. 36 | 37 | syntax = "proto2"; 38 | 39 | // We don't put this in a package within proto2 because we need to make sure 40 | // that the generated code doesn't depend on being in the proto2 namespace. 41 | // In test_util.h we do 42 | // "using namespace unittest_import = protobuf_unittest_import". 43 | package protobuf_unittest_import; 44 | 45 | option optimize_for = SPEED; 46 | option cc_enable_arenas = true; 47 | 48 | // Exercise the java_package option. 49 | option java_package = "com.google.protobuf.test"; 50 | 51 | // Do not set a java_outer_classname here to verify that Proto2 works without 52 | // one. 53 | 54 | // Test public import 55 | import public "google/protobuf/unittest_import_public.proto"; 56 | 57 | message ImportMessage { 58 | optional int32 d = 1; 59 | } 60 | 61 | enum ImportEnum { 62 | IMPORT_FOO = 7; 63 | IMPORT_BAR = 8; 64 | IMPORT_BAZ = 9; 65 | } 66 | 67 | 68 | // To use an enum in a map, it must has the first value as 0. 69 | enum ImportEnumForMap { 70 | UNKNOWN = 0; 71 | FOO = 1; 72 | BAR = 2; 73 | } 74 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_lazy_dependencies_enum.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: trafacz@google.com (Todd Rafacz) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // A proto file we will use for unit testing. 36 | 37 | syntax = "proto2"; 38 | 39 | // Some generic_services option(s) added automatically. 40 | // See: http://go/proto2-generic-services-default 41 | option cc_generic_services = true; // auto-added 42 | option java_generic_services = true; // auto-added 43 | option py_generic_services = true; // auto-added 44 | option cc_enable_arenas = true; 45 | 46 | // We don't put this in a package within proto2 because we need to make sure 47 | // that the generated code doesn't depend on being in the proto2 namespace. 48 | // In test_util.h we do "using namespace unittest = protobuf_unittest". 49 | package protobuf_unittest.lazy_imports; 50 | 51 | // Protos optimized for SPEED use a strict superset of the generated code 52 | // of equivalent ones optimized for CODE_SIZE, so we should optimize all our 53 | // tests for speed unless explicitly testing code size optimization. 54 | option optimize_for = SPEED; 55 | 56 | option java_outer_classname = "UnittestLazyImportsEnumProto"; 57 | 58 | enum LazyEnum { 59 | LAZY_ENUM_0 = 0; 60 | LAZY_ENUM_1 = 1; 61 | } 62 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/unittest_import.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // A proto file which is imported by unittest.proto to test importing. 36 | 37 | syntax = "proto2"; 38 | 39 | // We don't put this in a package within proto2 because we need to make sure 40 | // that the generated code doesn't depend on being in the proto2 namespace. 41 | // In test_util.h we do 42 | // "using namespace unittest_import = protobuf_unittest_import". 43 | package protobuf_unittest_import; 44 | 45 | option optimize_for = SPEED; 46 | option cc_enable_arenas = true; 47 | 48 | // Exercise the java_package option. 49 | option java_package = "com.google.protobuf.test"; 50 | 51 | // Do not set a java_outer_classname here to verify that Proto2 works without 52 | // one. 53 | 54 | // Test public import 55 | import public "google/protobuf/unittest_import_public.proto"; 56 | 57 | message ImportMessage { 58 | optional int32 d = 1; 59 | } 60 | 61 | enum ImportEnum { 62 | IMPORT_FOO = 7; 63 | IMPORT_BAR = 8; 64 | IMPORT_BAZ = 9; 65 | } 66 | 67 | 68 | // To use an enum in a map, it must has the first value as 0. 69 | enum ImportEnumForMap { 70 | UNKNOWN = 0; 71 | FOO = 1; 72 | BAR = 2; 73 | } 74 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/unittest_lazy_dependencies_enum.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: trafacz@google.com (Todd Rafacz) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // A proto file we will use for unit testing. 36 | 37 | syntax = "proto2"; 38 | 39 | // Some generic_services option(s) added automatically. 40 | // See: http://go/proto2-generic-services-default 41 | option cc_generic_services = true; // auto-added 42 | option java_generic_services = true; // auto-added 43 | option py_generic_services = true; // auto-added 44 | option cc_enable_arenas = true; 45 | 46 | // We don't put this in a package within proto2 because we need to make sure 47 | // that the generated code doesn't depend on being in the proto2 namespace. 48 | // In test_util.h we do "using namespace unittest = protobuf_unittest". 49 | package protobuf_unittest.lazy_imports; 50 | 51 | // Protos optimized for SPEED use a strict superset of the generated code 52 | // of equivalent ones optimized for CODE_SIZE, so we should optimize all our 53 | // tests for speed unless explicitly testing code size optimization. 54 | option optimize_for = SPEED; 55 | 56 | option java_outer_classname = "UnittestLazyImportsEnumProto"; 57 | 58 | enum LazyEnum { 59 | LAZY_ENUM_0 = 0; 60 | LAZY_ENUM_1 = 1; 61 | } 62 | -------------------------------------------------------------------------------- /parser/unquote.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | "strings" 7 | "unicode" 8 | 9 | "github.com/alecthomas/participle/v2/lexer" 10 | ) 11 | 12 | var escapeTable = map[rune]rune{ 13 | '0': '\000', 14 | 'a': '\x07', 15 | 'b': '\x08', 16 | 'e': '\x1B', 17 | 'f': '\x0C', 18 | 'n': '\x0A', 19 | 'r': '\x0D', 20 | 't': '\x09', 21 | 'v': '\x0B', 22 | '\\': '\x5C', 23 | '\'': '\x27', 24 | '"': '\x22', 25 | '?': '\x3F', 26 | } 27 | 28 | var stateBase = map[unquoteState]int{ 29 | uqHex: 16, uqOctal: 8, 30 | } 31 | 32 | type unquoteState int 33 | 34 | const ( 35 | uqDefault unquoteState = iota 36 | uqEscape 37 | uqHex 38 | uqOctal 39 | ) 40 | 41 | // C-style unquoting - supports octal \DDD and hex \xDDD 42 | func unquote(token lexer.Token) (lexer.Token, error) { 43 | kind := token.Value[0] // nolint: ifshort 44 | token.Value = token.Value[1 : len(token.Value)-1] 45 | // Single quoted, no escaping. 46 | if kind == '\'' { 47 | return token, nil 48 | } 49 | out := strings.Builder{} 50 | state := uqDefault 51 | // Digits being collected in hex/octal modes 52 | var digits string 53 | for _, rn := range token.Value { 54 | switch state { 55 | case uqEscape: 56 | if rn == 'x' { // nolint: gocritic 57 | state = uqHex 58 | } else if unicode.Is(unicode.Digit, rn) { 59 | state = uqOctal 60 | digits = string(rn) 61 | } else { 62 | escaped, ok := escapeTable[rn] 63 | if !ok { 64 | return token, fmt.Errorf("%s: %q: unknown escape sequence \"\\%c\"", token.Pos, token.Value, rn) 65 | } 66 | out.WriteRune(escaped) 67 | state = uqDefault 68 | } 69 | continue 70 | case uqHex: 71 | if unicode.Is(unicode.ASCII_Hex_Digit, rn) && len(digits) < 2 { 72 | digits += string(rn) 73 | continue 74 | } 75 | if err := flushDigits(digits, 16, &out); err != nil { 76 | return token, fmt.Errorf("%s: %w", token.Pos, err) 77 | } 78 | state = uqDefault 79 | digits = "" 80 | case uqOctal: 81 | if unicode.IsDigit(rn) && len(digits) < 3 { 82 | digits += string(rn) 83 | continue 84 | } 85 | if err := flushDigits(digits, 8, &out); err != nil { 86 | return token, fmt.Errorf("%s: %w", token.Pos, err) 87 | } 88 | state = uqDefault 89 | digits = "" 90 | case uqDefault: 91 | default: 92 | panic(state) 93 | } 94 | if rn == '\\' { 95 | state = uqEscape 96 | } else { 97 | out.WriteRune(rn) 98 | } 99 | } 100 | if digits != "" { 101 | if err := flushDigits(digits, stateBase[state], &out); err != nil { 102 | return token, fmt.Errorf("%s: %w", token.Pos, err) 103 | } 104 | } 105 | token.Value = out.String() 106 | return token, nil 107 | } 108 | 109 | func flushDigits(digits string, base int, out *strings.Builder) error { 110 | n, err := strconv.ParseUint(digits, base, 32) 111 | if err != nil { 112 | return fmt.Errorf("invalid base %d numeric value %s", base, digits) 113 | } 114 | if n > 255 { 115 | return fmt.Errorf("base %d value %s larger than 255", base, digits) 116 | } 117 | out.WriteByte(byte(n)) 118 | return nil 119 | } 120 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_lazy_dependencies_custom_option.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: trafacz@google.com (Todd Rafacz) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // A proto file we will use for unit testing. 36 | 37 | syntax = "proto2"; 38 | 39 | import "google/protobuf/unittest_lazy_dependencies_enum.proto"; 40 | import "google/protobuf/descriptor.proto"; 41 | 42 | // Some generic_services option(s) added automatically. 43 | // See: http://go/proto2-generic-services-default 44 | option cc_generic_services = true; // auto-added 45 | option java_generic_services = true; // auto-added 46 | option py_generic_services = true; // auto-added 47 | option cc_enable_arenas = true; 48 | 49 | // We don't put this in a package within proto2 because we need to make sure 50 | // that the generated code doesn't depend on being in the proto2 namespace. 51 | // In test_util.h we do "using namespace unittest = protobuf_unittest". 52 | package protobuf_unittest.lazy_imports; 53 | 54 | // Protos optimized for SPEED use a strict superset of the generated code 55 | // of equivalent ones optimized for CODE_SIZE, so we should optimize all our 56 | // tests for speed unless explicitly testing code size optimization. 57 | option optimize_for = SPEED; 58 | 59 | option java_outer_classname = "UnittestLazyImportsCustomOptionProto"; 60 | 61 | message LazyMessage { 62 | optional int32 a = 1; 63 | } 64 | 65 | extend google.protobuf.MessageOptions { 66 | optional LazyEnum lazy_enum_option = 138596335 [default = LAZY_ENUM_1]; 67 | } 68 | -------------------------------------------------------------------------------- /testdata/conformance/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 | // 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: trafacz@google.com (Todd Rafacz) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // A proto file we will use for unit testing. 36 | 37 | syntax = "proto2"; 38 | 39 | import "google/protobuf/unittest_lazy_dependencies_enum.proto"; 40 | import "google/protobuf/descriptor.proto"; 41 | 42 | // Some generic_services option(s) added automatically. 43 | // See: http://go/proto2-generic-services-default 44 | option cc_generic_services = true; // auto-added 45 | option java_generic_services = true; // auto-added 46 | option py_generic_services = true; // auto-added 47 | option cc_enable_arenas = true; 48 | 49 | // We don't put this in a package within proto2 because we need to make sure 50 | // that the generated code doesn't depend on being in the proto2 namespace. 51 | // In test_util.h we do "using namespace unittest = protobuf_unittest". 52 | package protobuf_unittest.lazy_imports; 53 | 54 | // Protos optimized for SPEED use a strict superset of the generated code 55 | // of equivalent ones optimized for CODE_SIZE, so we should optimize all our 56 | // tests for speed unless explicitly testing code size optimization. 57 | option optimize_for = SPEED; 58 | 59 | option java_outer_classname = "UnittestLazyImportsCustomOptionProto"; 60 | 61 | message LazyMessage { 62 | optional int32 a = 1; 63 | } 64 | 65 | extend google.protobuf.MessageOptions { 66 | optional LazyEnum lazy_enum_option = 138596335 [default = LAZY_ENUM_1]; 67 | } 68 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_lazy_dependencies.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: trafacz@google.com (Todd Rafacz) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // A proto file we will use for unit testing. 36 | 37 | syntax = "proto2"; 38 | 39 | import "google/protobuf/unittest_lazy_dependencies_custom_option.proto"; 40 | 41 | // Some generic_services option(s) added automatically. 42 | // See: http://go/proto2-generic-services-default 43 | option cc_generic_services = true; // auto-added 44 | option java_generic_services = true; // auto-added 45 | option py_generic_services = true; // auto-added 46 | option cc_enable_arenas = true; 47 | 48 | // We don't put this in a package within proto2 because we need to make sure 49 | // that the generated code doesn't depend on being in the proto2 namespace. 50 | // In test_util.h we do "using namespace unittest = protobuf_unittest". 51 | package protobuf_unittest.lazy_imports; 52 | 53 | // Protos optimized for SPEED use a strict superset of the generated code 54 | // of equivalent ones optimized for CODE_SIZE, so we should optimize all our 55 | // tests for speed unless explicitly testing code size optimization. 56 | option optimize_for = SPEED; 57 | 58 | option java_outer_classname = "UnittestLazyImportsProto"; 59 | 60 | // The following are used to test that the proto file 61 | // with the definition of the following field types is 62 | // not built when this proto file is built. Then test 63 | // that calling message_type() etc will build the correct 64 | // descriptor lazily and return it. 65 | 66 | message ImportedMessage { 67 | optional LazyMessage lazy_message = 1; 68 | } 69 | 70 | message MessageCustomOption { 71 | } 72 | 73 | message MessageCustomOption2 { 74 | option (lazy_enum_option) = LAZY_ENUM_0; 75 | } 76 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/unittest_lazy_dependencies.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: trafacz@google.com (Todd Rafacz) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // A proto file we will use for unit testing. 36 | 37 | syntax = "proto2"; 38 | 39 | import "google/protobuf/unittest_lazy_dependencies_custom_option.proto"; 40 | 41 | // Some generic_services option(s) added automatically. 42 | // See: http://go/proto2-generic-services-default 43 | option cc_generic_services = true; // auto-added 44 | option java_generic_services = true; // auto-added 45 | option py_generic_services = true; // auto-added 46 | option cc_enable_arenas = true; 47 | 48 | // We don't put this in a package within proto2 because we need to make sure 49 | // that the generated code doesn't depend on being in the proto2 namespace. 50 | // In test_util.h we do "using namespace unittest = protobuf_unittest". 51 | package protobuf_unittest.lazy_imports; 52 | 53 | // Protos optimized for SPEED use a strict superset of the generated code 54 | // of equivalent ones optimized for CODE_SIZE, so we should optimize all our 55 | // tests for speed unless explicitly testing code size optimization. 56 | option optimize_for = SPEED; 57 | 58 | option java_outer_classname = "UnittestLazyImportsProto"; 59 | 60 | // The following are used to test that the proto file 61 | // with the definition of the following field types is 62 | // not built when this proto file is built. Then test 63 | // that calling message_type() etc will build the correct 64 | // descriptor lazily and return it. 65 | 66 | message ImportedMessage { 67 | optional LazyMessage lazy_message = 1; 68 | } 69 | 70 | message MessageCustomOption { 71 | } 72 | 73 | message MessageCustomOption2 { 74 | option (lazy_enum_option) = LAZY_ENUM_0; 75 | } 76 | -------------------------------------------------------------------------------- /testdata/conformance/map_proto2_unittest.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | option cc_enable_arenas = true; 33 | 34 | import "google/protobuf/unittest_import.proto"; 35 | 36 | // We don't put this in a package within proto2 because we need to make sure 37 | // that the generated code doesn't depend on being in the proto2 namespace. 38 | // In map_test_util.h we do "using namespace unittest = protobuf_unittest". 39 | package protobuf_unittest; 40 | 41 | enum Proto2MapEnum { 42 | PROTO2_MAP_ENUM_FOO = 0; 43 | PROTO2_MAP_ENUM_BAR = 1; 44 | PROTO2_MAP_ENUM_BAZ = 2; 45 | } 46 | 47 | enum Proto2MapEnumPlusExtra { 48 | E_PROTO2_MAP_ENUM_FOO = 0; 49 | E_PROTO2_MAP_ENUM_BAR = 1; 50 | E_PROTO2_MAP_ENUM_BAZ = 2; 51 | E_PROTO2_MAP_ENUM_EXTRA = 3; 52 | } 53 | 54 | message TestEnumMap { 55 | map known_map_field = 101; 56 | map unknown_map_field = 102; 57 | } 58 | 59 | message TestEnumMapPlusExtra { 60 | map known_map_field = 101; 61 | map unknown_map_field = 102; 62 | } 63 | 64 | message TestImportEnumMap { 65 | map import_enum_amp = 1; 66 | } 67 | 68 | message TestIntIntMap { 69 | map m = 1; 70 | } 71 | 72 | // Test all key types: string, plus the non-floating-point scalars. 73 | message TestMaps { 74 | map m_int32 = 1; 75 | map m_int64 = 2; 76 | map m_uint32 = 3; 77 | map m_uint64 = 4; 78 | map m_sint32 = 5; 79 | map m_sint64 = 6; 80 | map m_fixed32 = 7; 81 | map m_fixed64 = 8; 82 | map m_sfixed32 = 9; 83 | map m_sfixed64 = 10; 84 | map m_bool = 11; 85 | map m_string = 12; 86 | } 87 | 88 | // Test maps in submessages. 89 | message TestSubmessageMaps { 90 | optional TestMaps m = 1; 91 | } 92 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/map_proto2_unittest.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | option cc_enable_arenas = true; 33 | 34 | import "google/protobuf/unittest_import.proto"; 35 | 36 | // We don't put this in a package within proto2 because we need to make sure 37 | // that the generated code doesn't depend on being in the proto2 namespace. 38 | // In map_test_util.h we do "using namespace unittest = protobuf_unittest". 39 | package protobuf_unittest; 40 | 41 | enum Proto2MapEnum { 42 | PROTO2_MAP_ENUM_FOO = 0; 43 | PROTO2_MAP_ENUM_BAR = 1; 44 | PROTO2_MAP_ENUM_BAZ = 2; 45 | } 46 | 47 | enum Proto2MapEnumPlusExtra { 48 | E_PROTO2_MAP_ENUM_FOO = 0; 49 | E_PROTO2_MAP_ENUM_BAR = 1; 50 | E_PROTO2_MAP_ENUM_BAZ = 2; 51 | E_PROTO2_MAP_ENUM_EXTRA = 3; 52 | } 53 | 54 | message TestEnumMap { 55 | map known_map_field = 101; 56 | map unknown_map_field = 102; 57 | } 58 | 59 | message TestEnumMapPlusExtra { 60 | map known_map_field = 101; 61 | map unknown_map_field = 102; 62 | } 63 | 64 | message TestImportEnumMap { 65 | map import_enum_amp = 1; 66 | } 67 | 68 | message TestIntIntMap { 69 | map m = 1; 70 | } 71 | 72 | // Test all key types: string, plus the non-floating-point scalars. 73 | message TestMaps { 74 | map m_int32 = 1; 75 | map m_int64 = 2; 76 | map m_uint32 = 3; 77 | map m_uint64 = 4; 78 | map m_sint32 = 5; 79 | map m_sint64 = 6; 80 | map m_fixed32 = 7; 81 | map m_fixed64 = 8; 82 | map m_sfixed32 = 9; 83 | map m_sfixed64 = 10; 84 | map m_bool = 11; 85 | map m_string = 12; 86 | } 87 | 88 | // Test maps in submessages. 89 | message TestSubmessageMaps { 90 | optional TestMaps m = 1; 91 | } 92 | -------------------------------------------------------------------------------- /compiler/registry.go: -------------------------------------------------------------------------------- 1 | package compiler 2 | 3 | import ( 4 | "strings" 5 | 6 | "google.golang.org/protobuf/reflect/protodesc" 7 | "google.golang.org/protobuf/reflect/protoreflect" 8 | "google.golang.org/protobuf/reflect/protoregistry" 9 | "google.golang.org/protobuf/types/descriptorpb" 10 | "google.golang.org/protobuf/types/dynamicpb" 11 | ) 12 | 13 | type Registry struct { 14 | protoregistry.Files 15 | } 16 | 17 | func NewRegistry(fds *descriptorpb.FileDescriptorSet) (*Registry, error) { 18 | f, err := protodesc.NewFiles(fds) 19 | if err != nil { 20 | return nil, err 21 | } 22 | return &Registry{Files: *f}, nil 23 | } 24 | 25 | // FindExtensionByName implements protoregistry.ExtensionTypeResolver. 26 | func (f *Registry) FindExtensionByName(field protoreflect.FullName) (protoreflect.ExtensionType, error) { 27 | if desc, err := protoregistry.GlobalTypes.FindExtensionByName(field); err == nil { 28 | return desc, nil 29 | } 30 | desc, err := f.FindDescriptorByName(field) 31 | if err != nil { 32 | return nil, err 33 | } 34 | ed, ok := desc.(protoreflect.ExtensionDescriptor) 35 | if !ok { 36 | return nil, protoregistry.NotFound 37 | } 38 | return dynamicpb.NewExtensionType(ed), nil 39 | } 40 | 41 | // FindExtensionByNumber implements protoregistry.ExtensionTypeResolver. 42 | func (f *Registry) FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error) { 43 | if desc, err := protoregistry.GlobalTypes.FindExtensionByNumber(message, field); err == nil { 44 | return desc, nil 45 | } 46 | // FileDescriptor and MessageDescriptor implement this interface. 47 | type extensionContainer interface { 48 | Messages() protoreflect.MessageDescriptors 49 | Extensions() protoreflect.ExtensionDescriptors 50 | } 51 | 52 | var getExtension func(extensionContainer) protoreflect.ExtensionType 53 | getExtension = func(ec extensionContainer) protoreflect.ExtensionType { 54 | eds := ec.Extensions() 55 | for i := 0; i < eds.Len(); i++ { 56 | ed := eds.Get(i) 57 | if ed.ContainingMessage().FullName() == message && ed.Number() == field { 58 | return dynamicpb.NewExtensionType(ed) 59 | } 60 | } 61 | 62 | mds := ec.Messages() 63 | for i := 0; i < mds.Len(); i++ { 64 | if et := getExtension(mds.Get(i)); et != nil { 65 | return et 66 | } 67 | } 68 | 69 | return nil 70 | } 71 | 72 | var et protoreflect.ExtensionType 73 | f.RangeFiles(func(fd protoreflect.FileDescriptor) bool { 74 | et = getExtension(fd) 75 | return et == nil 76 | }) 77 | if et == nil { 78 | return nil, protoregistry.NotFound 79 | } 80 | return et, nil 81 | } 82 | 83 | // FindMessageByName implements protoregistry.MessageTypeResolver. 84 | func (f *Registry) FindMessageByName(name protoreflect.FullName) (protoreflect.MessageType, error) { 85 | if desc, err := protoregistry.GlobalTypes.FindMessageByName(name); err == nil { 86 | return desc, nil 87 | } 88 | desc, err := f.FindDescriptorByName(name) 89 | if err != nil { 90 | return nil, err 91 | } 92 | md, ok := desc.(protoreflect.MessageDescriptor) 93 | if !ok { 94 | return nil, protoregistry.NotFound 95 | } 96 | return dynamicpb.NewMessageType(md), nil 97 | } 98 | 99 | // FindMessageByURL implements protoregistry.MessageTypeResolver. 100 | func (f *Registry) FindMessageByURL(url string) (protoreflect.MessageType, error) { 101 | if desc, err := protoregistry.GlobalTypes.FindMessageByURL(url); err == nil { 102 | return desc, nil 103 | } 104 | message := protoreflect.FullName(url) 105 | // Strip off before the last slash - we only look locally for the 106 | // message and do not hit the network. The part after the last slash 107 | // must be the full name of the message. 108 | if i := strings.LastIndexByte(url, '/'); i >= 0 { 109 | message = message[i+len("/"):] 110 | } 111 | return f.FindMessageByName(message) 112 | } 113 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Run `make help` to display help 2 | 3 | all: build test lint ## build, test and lint go source 4 | 5 | ci: clean check-uptodate all ## Full clean build and up-to-date checks as run on CI 6 | 7 | check-uptodate: sync pb tidy 8 | test -z "$$(git status --porcelain -- go.mod go.sum '*.proto' '*.pb')" 9 | 10 | .PHONY: all check-uptodate ci clean 11 | 12 | # --- Test ------------------------------------------------------------- 13 | build: 14 | go build ./... 15 | 16 | test: ## Test go source 17 | go test ./... 18 | 19 | tidy: 20 | go mod tidy 21 | 22 | lint: ## Lint go source code 23 | golangci-lint run 24 | 25 | .PHONY: lint test 26 | 27 | # --- Conformance ------------------------------------------------------ 28 | sync: sync-googleapis | testdata/conformance/google/protobuf ## Clone and copy conformance protos from GitHub 29 | $(eval DEST := $(shell mktemp -d)) 30 | git clone --depth=1 https://github.com/protocolbuffers/protobuf.git $(DEST) 31 | for patch in testdata/patches/*.patch; do patch -d $(DEST) -p1 < $${patch}; done 32 | cp $(DEST)/src/google/protobuf/*.proto testdata/conformance 33 | cp $(DEST)/src/google/protobuf/*.proto testdata/conformance/google/protobuf 34 | cp $(DEST)/conformance/*.proto testdata/conformance 35 | cp $(DEST)/src/google/protobuf/descriptor.proto compiler/testdata/google/protobuf/descriptor.proto 36 | rm -rf $(DEST) 37 | 38 | sync-googleapis: 39 | $(eval DEST := $(shell mktemp -d)) 40 | git clone --depth=1 https://github.com/googleapis/googleapis.git $(DEST) 41 | cp $(DEST)/google/api/http.proto compiler/testdata/google/api 42 | cp $(DEST)/google/api/annotations.proto compiler/testdata/google/api 43 | rm -rf $(DEST) 44 | 45 | testdata/conformance/google/protobuf: 46 | mkdir -p testdata/conformance/google/protobuf 47 | 48 | clean:: ## Remove generated files 49 | rm -rf testdata/conformance/* 50 | 51 | .PHONY: sync sync-googleapis 52 | 53 | # --- Protos ----------------------------------------------------------- 54 | COMPILER_PROTO_FILES = $(wildcard compiler/testdata/*.proto) 55 | COMPILER_PB_FILES = $(patsubst compiler/testdata/%.proto,compiler/testdata/pb/%.pb,$(COMPILER_PROTO_FILES)) 56 | CONFORMANCE_PROTO_FILES = $(wildcard testdata/conformance/*.proto) 57 | CONFORMANCE_PB_FILES = $(patsubst testdata/conformance/%.proto,testdata/conformance/pb/%.pb,$(CONFORMANCE_PROTO_FILES)) 58 | 59 | pb: $(COMPILER_PB_FILES) $(CONFORMANCE_PB_FILES) ## Generate binary FileDescriptorSet as pb files from compiler/testdata/*.proto 60 | 61 | compiler/testdata/pb/%_no_include.pb: compiler/testdata/%_no_include.proto 62 | protoc -I compiler/testdata -o $@ $< 63 | 64 | compiler/testdata/pb/%.pb: compiler/testdata/%.proto 65 | protoc --include_imports -I compiler/testdata -o $@ $< 66 | 67 | testdata/conformance/pb/%.pb: testdata/conformance/%.proto | testdata/conformance/pb 68 | protoc --include_imports -I compiler/testdata -I testdata/conformance -o $@ $< 69 | 70 | testdata/conformance/pb: 71 | mkdir -p testdata/conformance/pb 72 | 73 | clean:: 74 | rm -rf compiler/testdata/pb/*.pb 75 | 76 | .PHONY: pb 77 | 78 | # --- Utilities -------------------------------------------------------- 79 | COLOUR_NORMAL = $(shell tput sgr0 2>/dev/null) 80 | COLOUR_WHITE = $(shell tput setaf 7 2>/dev/null) 81 | 82 | help: 83 | @awk -F ':.*## ' 'NF == 2 && $$1 ~ /^[A-Za-z0-9%_-]+$$/ { printf "$(COLOUR_WHITE)%-25s$(COLOUR_NORMAL)%s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort 84 | 85 | .PHONY: help 86 | 87 | define nl 88 | 89 | 90 | endef 91 | ifndef ACTIVE_HERMIT 92 | $(eval $(subst \n,$(nl),$(shell bin/hermit env -r | sed 's/^\(.*\)$$/export \1\\n/'))) 93 | endif 94 | 95 | # Ensure make version is gnu make 3.82 or higher 96 | ifeq ($(filter undefine,$(value .FEATURES)),) 97 | $(error Unsupported Make version. \ 98 | $(nl)Use GNU Make 3.82 or higher (current: $(MAKE_VERSION)). \ 99 | $(nl)Activate 🐚 hermit with `. bin/activate-hermit` and run again \ 100 | $(nl)or use `bin/make`) 101 | endif 102 | 103 | -------------------------------------------------------------------------------- /testdata/conformance/struct.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option cc_enable_arenas = true; 37 | option go_package = "google.golang.org/protobuf/types/known/structpb"; 38 | option java_package = "com.google.protobuf"; 39 | option java_outer_classname = "StructProto"; 40 | option java_multiple_files = true; 41 | option objc_class_prefix = "GPB"; 42 | 43 | // `Struct` represents a structured data value, consisting of fields 44 | // which map to dynamically typed values. In some languages, `Struct` 45 | // might be supported by a native representation. For example, in 46 | // scripting languages like JS a struct is represented as an 47 | // object. The details of that representation are described together 48 | // with the proto support for the language. 49 | // 50 | // The JSON representation for `Struct` is JSON object. 51 | message Struct { 52 | // Unordered map of dynamically typed values. 53 | map fields = 1; 54 | } 55 | 56 | // `Value` represents a dynamically typed value which can be either 57 | // null, a number, a string, a boolean, a recursive struct value, or a 58 | // list of values. A producer of value is expected to set one of these 59 | // variants. Absence of any variant indicates an error. 60 | // 61 | // The JSON representation for `Value` is JSON value. 62 | message Value { 63 | // The kind of value. 64 | oneof kind { 65 | // Represents a null value. 66 | NullValue null_value = 1; 67 | // Represents a double value. 68 | double number_value = 2; 69 | // Represents a string value. 70 | string string_value = 3; 71 | // Represents a boolean value. 72 | bool bool_value = 4; 73 | // Represents a structured value. 74 | Struct struct_value = 5; 75 | // Represents a repeated `Value`. 76 | ListValue list_value = 6; 77 | } 78 | } 79 | 80 | // `NullValue` is a singleton enumeration to represent the null value for the 81 | // `Value` type union. 82 | // 83 | // The JSON representation for `NullValue` is JSON `null`. 84 | enum NullValue { 85 | // Null value. 86 | NULL_VALUE = 0; 87 | } 88 | 89 | // `ListValue` is a wrapper around a repeated field of values. 90 | // 91 | // The JSON representation for `ListValue` is JSON array. 92 | message ListValue { 93 | // Repeated field of dynamically typed values. 94 | repeated Value values = 1; 95 | } 96 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/struct.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option cc_enable_arenas = true; 37 | option go_package = "google.golang.org/protobuf/types/known/structpb"; 38 | option java_package = "com.google.protobuf"; 39 | option java_outer_classname = "StructProto"; 40 | option java_multiple_files = true; 41 | option objc_class_prefix = "GPB"; 42 | 43 | // `Struct` represents a structured data value, consisting of fields 44 | // which map to dynamically typed values. In some languages, `Struct` 45 | // might be supported by a native representation. For example, in 46 | // scripting languages like JS a struct is represented as an 47 | // object. The details of that representation are described together 48 | // with the proto support for the language. 49 | // 50 | // The JSON representation for `Struct` is JSON object. 51 | message Struct { 52 | // Unordered map of dynamically typed values. 53 | map fields = 1; 54 | } 55 | 56 | // `Value` represents a dynamically typed value which can be either 57 | // null, a number, a string, a boolean, a recursive struct value, or a 58 | // list of values. A producer of value is expected to set one of these 59 | // variants. Absence of any variant indicates an error. 60 | // 61 | // The JSON representation for `Value` is JSON value. 62 | message Value { 63 | // The kind of value. 64 | oneof kind { 65 | // Represents a null value. 66 | NullValue null_value = 1; 67 | // Represents a double value. 68 | double number_value = 2; 69 | // Represents a string value. 70 | string string_value = 3; 71 | // Represents a boolean value. 72 | bool bool_value = 4; 73 | // Represents a structured value. 74 | Struct struct_value = 5; 75 | // Represents a repeated `Value`. 76 | ListValue list_value = 6; 77 | } 78 | } 79 | 80 | // `NullValue` is a singleton enumeration to represent the null value for the 81 | // `Value` type union. 82 | // 83 | // The JSON representation for `NullValue` is JSON `null`. 84 | enum NullValue { 85 | // Null value. 86 | NULL_VALUE = 0; 87 | } 88 | 89 | // `ListValue` is a wrapper around a repeated field of values. 90 | // 91 | // The JSON representation for `ListValue` is JSON array. 92 | message ListValue { 93 | // Repeated field of dynamically typed values. 94 | repeated Value values = 1; 95 | } 96 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_mset.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // This file is similar to unittest_mset_wire_format.proto, but does not 36 | // have a TestMessageSet, so it can be downgraded to proto1. 37 | 38 | syntax = "proto2"; 39 | 40 | import "google/protobuf/unittest_mset_wire_format.proto"; 41 | 42 | package protobuf_unittest; 43 | 44 | option cc_enable_arenas = true; 45 | option optimize_for = SPEED; 46 | 47 | message TestMessageSetContainer { 48 | optional proto2_wireformat_unittest.TestMessageSet message_set = 1; 49 | } 50 | 51 | message NestedTestMessageSetContainer { 52 | optional TestMessageSetContainer container = 1; 53 | optional NestedTestMessageSetContainer child = 2; 54 | } 55 | 56 | message TestMessageSetExtension1 { 57 | extend proto2_wireformat_unittest.TestMessageSet { 58 | optional TestMessageSetExtension1 message_set_extension = 1545008; 59 | } 60 | optional int32 i = 15; 61 | optional proto2_wireformat_unittest.TestMessageSet recursive = 16; 62 | optional string test_aliasing = 17 [ctype = STRING_PIECE]; 63 | } 64 | 65 | message TestMessageSetExtension2 { 66 | extend proto2_wireformat_unittest.TestMessageSet { 67 | optional TestMessageSetExtension2 message_set_extension = 1547769; 68 | } 69 | optional string str = 25; 70 | } 71 | 72 | message NestedTestInt { 73 | optional fixed32 a = 1; 74 | optional NestedTestInt child = 2; 75 | } 76 | 77 | message TestMessageSetExtension3 { 78 | extend proto2_wireformat_unittest.TestMessageSet { 79 | optional TestMessageSetExtension3 message_set_extension = 195273129; 80 | } 81 | optional NestedTestInt msg = 35; 82 | } 83 | 84 | // This message was used to generate 85 | // //net/proto2/python/internal/testdata/message_set_message, but is commented 86 | // out since it must not actually exist in code, to simulate an "unknown" 87 | // extension. 88 | // message TestMessageSetUnknownExtension { 89 | // extend TestMessageSet { 90 | // optional TestMessageSetUnknownExtension message_set_extension = 56141421; 91 | // } 92 | // optional int64 a = 1; 93 | // } 94 | 95 | // MessageSet wire format is equivalent to this. 96 | message RawMessageSet { 97 | repeated group Item = 1 { 98 | required int32 type_id = 2; 99 | required bytes message = 3; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/unittest_mset.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | // 35 | // This file is similar to unittest_mset_wire_format.proto, but does not 36 | // have a TestMessageSet, so it can be downgraded to proto1. 37 | 38 | syntax = "proto2"; 39 | 40 | import "google/protobuf/unittest_mset_wire_format.proto"; 41 | 42 | package protobuf_unittest; 43 | 44 | option cc_enable_arenas = true; 45 | option optimize_for = SPEED; 46 | 47 | message TestMessageSetContainer { 48 | optional proto2_wireformat_unittest.TestMessageSet message_set = 1; 49 | } 50 | 51 | message NestedTestMessageSetContainer { 52 | optional TestMessageSetContainer container = 1; 53 | optional NestedTestMessageSetContainer child = 2; 54 | } 55 | 56 | message TestMessageSetExtension1 { 57 | extend proto2_wireformat_unittest.TestMessageSet { 58 | optional TestMessageSetExtension1 message_set_extension = 1545008; 59 | } 60 | optional int32 i = 15; 61 | optional proto2_wireformat_unittest.TestMessageSet recursive = 16; 62 | optional string test_aliasing = 17 [ctype = STRING_PIECE]; 63 | } 64 | 65 | message TestMessageSetExtension2 { 66 | extend proto2_wireformat_unittest.TestMessageSet { 67 | optional TestMessageSetExtension2 message_set_extension = 1547769; 68 | } 69 | optional string str = 25; 70 | } 71 | 72 | message NestedTestInt { 73 | optional fixed32 a = 1; 74 | optional NestedTestInt child = 2; 75 | } 76 | 77 | message TestMessageSetExtension3 { 78 | extend proto2_wireformat_unittest.TestMessageSet { 79 | optional TestMessageSetExtension3 message_set_extension = 195273129; 80 | } 81 | optional NestedTestInt msg = 35; 82 | } 83 | 84 | // This message was used to generate 85 | // //net/proto2/python/internal/testdata/message_set_message, but is commented 86 | // out since it must not actually exist in code, to simulate an "unknown" 87 | // extension. 88 | // message TestMessageSetUnknownExtension { 89 | // extend TestMessageSet { 90 | // optional TestMessageSetUnknownExtension message_set_extension = 56141421; 91 | // } 92 | // optional int64 a = 1; 93 | // } 94 | 95 | // MessageSet wire format is equivalent to this. 96 | message RawMessageSet { 97 | repeated group Item = 1 { 98 | required int32 type_id = 2; 99 | required bytes message = 3; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /testdata/conformance/unittest_proto3_optional.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package protobuf_unittest; 34 | 35 | import "google/protobuf/descriptor.proto"; 36 | 37 | option java_multiple_files = true; 38 | option java_package = "com.google.protobuf.testing.proto"; 39 | 40 | message TestProto3Optional { 41 | message NestedMessage { 42 | // The field name "b" fails to compile in proto1 because it conflicts with 43 | // a local variable named "b" in one of the generated methods. Doh. 44 | // This file needs to compile in proto1 to test backwards-compatibility. 45 | optional int32 bb = 1; 46 | } 47 | 48 | enum NestedEnum { 49 | UNSPECIFIED = 0; 50 | FOO = 1; 51 | BAR = 2; 52 | BAZ = 3; 53 | NEG = -1; // Intentionally negative. 54 | } 55 | 56 | // Singular 57 | optional int32 optional_int32 = 1; 58 | optional int64 optional_int64 = 2; 59 | optional uint32 optional_uint32 = 3; 60 | optional uint64 optional_uint64 = 4; 61 | optional sint32 optional_sint32 = 5; 62 | optional sint64 optional_sint64 = 6; 63 | optional fixed32 optional_fixed32 = 7; 64 | optional fixed64 optional_fixed64 = 8; 65 | optional sfixed32 optional_sfixed32 = 9; 66 | optional sfixed64 optional_sfixed64 = 10; 67 | optional float optional_float = 11; 68 | optional double optional_double = 12; 69 | optional bool optional_bool = 13; 70 | optional string optional_string = 14; 71 | optional bytes optional_bytes = 15; 72 | optional string optional_cord = 16 [ctype = CORD]; 73 | 74 | optional NestedMessage optional_nested_message = 18; 75 | optional NestedMessage lazy_nested_message = 19 [lazy = true]; 76 | optional NestedEnum optional_nested_enum = 21; 77 | 78 | // Add some non-optional fields to verify we can mix them. 79 | int32 singular_int32 = 22; 80 | int64 singular_int64 = 23; 81 | } 82 | 83 | message TestProto3OptionalMessage { 84 | message NestedMessage { 85 | string s = 1; 86 | } 87 | 88 | NestedMessage nested_message = 1; 89 | optional NestedMessage optional_nested_message = 2; 90 | } 91 | 92 | message Proto3OptionalExtensions { 93 | option (protobuf_unittest.Proto3OptionalExtensions.ext_no_optional) = 8; 94 | option (protobuf_unittest.Proto3OptionalExtensions.ext_with_optional) = 16; 95 | 96 | extend google.protobuf.MessageOptions { 97 | int32 ext_no_optional = 355886728; 98 | optional int32 ext_with_optional = 355886729; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /testdata/conformance/google/protobuf/unittest_proto3_optional.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package protobuf_unittest; 34 | 35 | import "google/protobuf/descriptor.proto"; 36 | 37 | option java_multiple_files = true; 38 | option java_package = "com.google.protobuf.testing.proto"; 39 | 40 | message TestProto3Optional { 41 | message NestedMessage { 42 | // The field name "b" fails to compile in proto1 because it conflicts with 43 | // a local variable named "b" in one of the generated methods. Doh. 44 | // This file needs to compile in proto1 to test backwards-compatibility. 45 | optional int32 bb = 1; 46 | } 47 | 48 | enum NestedEnum { 49 | UNSPECIFIED = 0; 50 | FOO = 1; 51 | BAR = 2; 52 | BAZ = 3; 53 | NEG = -1; // Intentionally negative. 54 | } 55 | 56 | // Singular 57 | optional int32 optional_int32 = 1; 58 | optional int64 optional_int64 = 2; 59 | optional uint32 optional_uint32 = 3; 60 | optional uint64 optional_uint64 = 4; 61 | optional sint32 optional_sint32 = 5; 62 | optional sint64 optional_sint64 = 6; 63 | optional fixed32 optional_fixed32 = 7; 64 | optional fixed64 optional_fixed64 = 8; 65 | optional sfixed32 optional_sfixed32 = 9; 66 | optional sfixed64 optional_sfixed64 = 10; 67 | optional float optional_float = 11; 68 | optional double optional_double = 12; 69 | optional bool optional_bool = 13; 70 | optional string optional_string = 14; 71 | optional bytes optional_bytes = 15; 72 | optional string optional_cord = 16 [ctype = CORD]; 73 | 74 | optional NestedMessage optional_nested_message = 18; 75 | optional NestedMessage lazy_nested_message = 19 [lazy = true]; 76 | optional NestedEnum optional_nested_enum = 21; 77 | 78 | // Add some non-optional fields to verify we can mix them. 79 | int32 singular_int32 = 22; 80 | int64 singular_int64 = 23; 81 | } 82 | 83 | message TestProto3OptionalMessage { 84 | message NestedMessage { 85 | string s = 1; 86 | } 87 | 88 | NestedMessage nested_message = 1; 89 | optional NestedMessage optional_nested_message = 2; 90 | } 91 | 92 | message Proto3OptionalExtensions { 93 | option (protobuf_unittest.Proto3OptionalExtensions.ext_no_optional) = 8; 94 | option (protobuf_unittest.Proto3OptionalExtensions.ext_with_optional) = 16; 95 | 96 | extend google.protobuf.MessageOptions { 97 | int32 ext_no_optional = 355886728; 98 | optional int32 ext_with_optional = 355886729; 99 | } 100 | } 101 | --------------------------------------------------------------------------------