├── .circleci └── config.yml ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── go.mod ├── go.sum ├── grpcdynamic ├── stub.go └── stub_test.go ├── grpcreflect ├── adapt.go ├── client.go ├── client_test.go ├── doc.go ├── server.go └── server_test.go ├── internal ├── fielddefault │ └── field_default.go ├── pinv1 │ └── pinv1.go ├── register │ └── register.go ├── reparse │ └── reparse.go ├── sort │ └── sort.go ├── testing │ ├── protoset.go │ └── test_service.go ├── testprotos │ ├── desc_test1.pb.go │ ├── desc_test1.pb.srcinfo.go │ ├── desc_test1.proto │ ├── desc_test1.protoset │ ├── desc_test2.pb.go │ ├── desc_test2.pb.srcinfo.go │ ├── desc_test2.proto │ ├── desc_test_comments.pb.go │ ├── desc_test_comments.pb.srcinfo.go │ ├── desc_test_comments.proto │ ├── desc_test_comments.protoset │ ├── desc_test_complex.pb.go │ ├── desc_test_complex.pb.srcinfo.go │ ├── desc_test_complex.proto │ ├── desc_test_complex.protoset │ ├── desc_test_complex_source_info.protoset │ ├── desc_test_defaults.pb.go │ ├── desc_test_defaults.pb.srcinfo.go │ ├── desc_test_defaults.proto │ ├── desc_test_editions.pb.go │ ├── desc_test_editions.pb.srcinfo.go │ ├── desc_test_editions.proto │ ├── desc_test_editions.protoset │ ├── desc_test_field_types.pb.go │ ├── desc_test_field_types.pb.srcinfo.go │ ├── desc_test_field_types.proto │ ├── desc_test_oneof.pb.go │ ├── desc_test_oneof.pb.srcinfo.go │ ├── desc_test_oneof.proto │ ├── desc_test_options.pb.go │ ├── desc_test_options.pb.srcinfo.go │ ├── desc_test_options.proto │ ├── desc_test_proto3.pb.go │ ├── desc_test_proto3.pb.srcinfo.go │ ├── desc_test_proto3.proto │ ├── desc_test_proto3.protoset │ ├── desc_test_value.pb.go │ ├── desc_test_value.pb.srcinfo.go │ ├── desc_test_value.proto │ ├── desc_test_wellknowntypes.pb.go │ ├── desc_test_wellknowntypes.pb.srcinfo.go │ ├── desc_test_wellknowntypes.proto │ ├── descriptor.protoset │ ├── duration.protoset │ ├── gen.go │ ├── grpc │ │ ├── dummy.pb.go │ │ ├── dummy.pb.srcinfo.go │ │ ├── dummy.proto │ │ ├── dummy_grpc.pb.go │ │ ├── test.pb.go │ │ ├── test.pb.srcinfo.go │ │ ├── test.proto │ │ └── test_grpc.pb.go │ ├── make_protos.sh │ ├── nopkg │ │ ├── desc_test_nopkg.pb.go │ │ ├── desc_test_nopkg.pb.srcinfo.go │ │ ├── desc_test_nopkg.proto │ │ ├── desc_test_nopkg_new.pb.go │ │ ├── desc_test_nopkg_new.pb.srcinfo.go │ │ └── desc_test_nopkg_new.proto │ ├── pkg │ │ ├── desc_test_pkg.pb.go │ │ ├── desc_test_pkg.pb.srcinfo.go │ │ └── desc_test_pkg.proto │ └── proto3_optional │ │ ├── desc_test_proto3_optional.pb.go │ │ ├── desc_test_proto3_optional.pb.srcinfo.go │ │ ├── desc_test_proto3_optional.proto │ │ └── desc_test_proto3_optional.protoset └── util.go ├── protobuilder ├── builder.go ├── builder_test.go ├── doc.go ├── enum.go ├── field.go ├── file.go ├── message.go ├── resolver.go ├── service.go └── types.go ├── protodescs ├── edition.go └── sort.go ├── protomessage ├── as.go ├── as_test.go ├── reparse.go ├── reparse_test.go ├── walk.go └── walk_test.go ├── protoprint ├── doc.go ├── message_literal.go ├── print.go ├── print_test.go ├── sort.go ├── source_locs.go └── testfiles │ ├── check-protos.sh │ ├── desc_test1-compact.proto │ ├── desc_test1-custom-sort.proto │ ├── desc_test1-default.proto │ ├── desc_test1-multiline-style-comments.proto │ ├── desc_test1-no-trailing-comments.proto │ ├── desc_test1-only-doc-comments.proto │ ├── desc_test1-sorted-AND-multiline-style-comments.proto │ ├── desc_test1-sorted.proto │ ├── desc_test1-trailing-on-next-line.proto │ ├── desc_test2-compact.proto │ ├── desc_test2-custom-sort.proto │ ├── desc_test2-default.proto │ ├── desc_test2-multiline-style-comments.proto │ ├── desc_test2-no-trailing-comments.proto │ ├── desc_test2-only-doc-comments.proto │ ├── desc_test2-sorted-AND-multiline-style-comments.proto │ ├── desc_test2-sorted.proto │ ├── desc_test2-trailing-on-next-line.proto │ ├── desc_test_comments-compact.proto │ ├── desc_test_comments-custom-sort.proto │ ├── desc_test_comments-default.proto │ ├── desc_test_comments-multiline-style-comments.proto │ ├── desc_test_comments-no-trailing-comments.proto │ ├── desc_test_comments-only-doc-comments.proto │ ├── desc_test_comments-sorted-AND-multiline-style-comments.proto │ ├── desc_test_comments-sorted.proto │ ├── desc_test_comments-trailing-on-next-line.proto │ ├── desc_test_complex-compact.proto │ ├── desc_test_complex-custom-sort.proto │ ├── desc_test_complex-default.proto │ ├── desc_test_complex-multiline-style-comments.proto │ ├── desc_test_complex-no-trailing-comments.proto │ ├── desc_test_complex-only-doc-comments.proto │ ├── desc_test_complex-sorted-AND-multiline-style-comments.proto │ ├── desc_test_complex-sorted.proto │ ├── desc_test_complex-trailing-on-next-line.proto │ ├── desc_test_complex_source_info-compact.proto │ ├── desc_test_complex_source_info-default.proto │ ├── desc_test_complex_source_info-multiline-style-comments.proto │ ├── desc_test_complex_source_info-no-trailing-comments.proto │ ├── desc_test_complex_source_info-only-doc-comments.proto │ ├── desc_test_complex_source_info-sorted-AND-multiline-style-comments.proto │ ├── desc_test_complex_source_info-sorted.proto │ ├── desc_test_complex_source_info-trailing-on-next-line.proto │ ├── desc_test_editions-compact.proto │ ├── desc_test_editions-custom-sort.proto │ ├── desc_test_editions-default.proto │ ├── desc_test_editions-multiline-style-comments.proto │ ├── desc_test_editions-no-trailing-comments.proto │ ├── desc_test_editions-only-doc-comments.proto │ ├── desc_test_editions-sorted-AND-multiline-style-comments.proto │ ├── desc_test_editions-sorted.proto │ ├── desc_test_editions-trailing-on-next-line.proto │ ├── desc_test_proto3-compact.proto │ ├── desc_test_proto3-custom-sort.proto │ ├── desc_test_proto3-default.proto │ ├── desc_test_proto3-multiline-style-comments.proto │ ├── desc_test_proto3-no-trailing-comments.proto │ ├── desc_test_proto3-only-doc-comments.proto │ ├── desc_test_proto3-sorted-AND-multiline-style-comments.proto │ ├── desc_test_proto3-sorted.proto │ ├── desc_test_proto3-trailing-on-next-line.proto │ ├── desc_test_proto3_optional-compact.proto │ ├── desc_test_proto3_optional-custom-sort.proto │ ├── desc_test_proto3_optional-default.proto │ ├── desc_test_proto3_optional-multiline-style-comments.proto │ ├── desc_test_proto3_optional-no-trailing-comments.proto │ ├── desc_test_proto3_optional-only-doc-comments.proto │ ├── desc_test_proto3_optional-sorted-AND-multiline-style-comments.proto │ ├── desc_test_proto3_optional-sorted.proto │ ├── desc_test_proto3_optional-trailing-on-next-line.proto │ ├── descriptor-compact.proto │ ├── descriptor-custom-sort.proto │ ├── descriptor-default.proto │ ├── descriptor-multiline-style-comments.proto │ ├── descriptor-no-trailing-comments.proto │ ├── descriptor-only-doc-comments.proto │ ├── descriptor-sorted-AND-multiline-style-comments.proto │ ├── descriptor-sorted.proto │ ├── descriptor-trailing-on-next-line.proto │ ├── test-non-files-compact.txt │ ├── test-non-files-full.txt │ ├── test-uninterpreted-options.proto │ └── test-unrecognized-options.proto ├── protoresolve ├── combine.go ├── desc_protos.go ├── doc.go ├── errors.go ├── helpers.go ├── kind.go ├── registry.go ├── registry_test.go ├── remotereg │ ├── converter.go │ ├── remote_registry.go │ ├── remote_registry_test.go │ ├── type_fetchers.go │ └── type_fetchers_test.go ├── resolver_test.go ├── resolvers.go ├── resolvers_test.go └── types.go ├── sourceinfo ├── cmd │ └── protoc-gen-gosrcinfo │ │ └── main.go ├── doc.go ├── export_test.go ├── registry.go ├── registry_test.go └── update.go └── sourceloc ├── sourceloc.go └── sourceloc_test.go /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | shared_configs: 2 | simple_job_steps: &simple_job_steps 3 | - checkout 4 | - run: 5 | name: Run tests 6 | command: | 7 | make deps test 8 | 9 | 10 | # Use the latest 2.1 version of CircleCI pipeline process engine. See: https://circleci.com/docs/2.0/configuration-reference 11 | version: 2.1 12 | 13 | orbs: 14 | win: circleci/windows@5.0 15 | 16 | jobs: 17 | build-windows: 18 | executor: 19 | name: win/default 20 | steps: 21 | - run: git config --global core.autocrlf false 22 | - checkout 23 | - run: go test ./... 24 | 25 | build-1-23: 26 | working_directory: ~/repo 27 | docker: 28 | - image: cimg/go:1.23 29 | steps: *simple_job_steps 30 | 31 | build-1-24: 32 | working_directory: ~/repo 33 | docker: 34 | - image: cimg/go:1.24 35 | steps: 36 | - checkout 37 | - restore_cache: 38 | keys: 39 | - go-mod-v4-{{ checksum "go.sum" }} 40 | - run: 41 | name: Install Dependencies 42 | command: go mod download 43 | - save_cache: 44 | key: go-mod-v4-{{ checksum "go.sum" }} 45 | paths: 46 | - "/go/pkg/mod" 47 | - run: 48 | name: Run tests 49 | command: | 50 | #mkdir -p /tmp/test-reports 51 | #gotestsum --junitfile /tmp/test-reports/unit-tests.xml 52 | make ci 53 | #- store_test_results: 54 | # path: /tmp/test-reports 55 | 56 | build-1-24-u: 57 | working_directory: ~/repo 58 | docker: 59 | - image: cimg/go:1.24 60 | steps: 61 | - checkout 62 | - run: 63 | name: Update depdendencies 64 | command: | 65 | go get -u ./... 66 | - run: 67 | name: Run tests 68 | command: | 69 | make deps test 70 | 71 | workflows: 72 | pr-build-test: 73 | jobs: 74 | # - build-windows 75 | - build-1-23 76 | - build-1-24 77 | - build-1-24-u 78 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | internal/testprotos/protoc 2 | coverage.out 3 | 4 | # Generated file for Goland workspace 5 | .idea 6 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: ci 2 | ci: deps checkgofmt checkgenerate errcheck golint vet staticcheck ineffassign test 3 | 4 | .PHONY: deps 5 | deps: 6 | go get -d -v -t ./... 7 | 8 | .PHONY: updatedeps 9 | updatedeps: 10 | go get -d -v -t -u -f ./... 11 | 12 | .PHONY: install 13 | install: 14 | go install ./... 15 | 16 | .PHONY: checkgofmt 17 | checkgofmt: 18 | @echo gofmt -s -l . 19 | @output="$$(gofmt -s -l .)" ; \ 20 | if [ -n "$$output" ]; then \ 21 | echo "$$output"; \ 22 | echo "Run gofmt on the above files!"; \ 23 | exit 1; \ 24 | fi 25 | 26 | # workaround https://github.com/golang/protobuf/issues/214 until in master 27 | .PHONY: vet 28 | vet: 29 | go vet ./... 30 | 31 | .PHONY: staticcheck 32 | staticcheck: 33 | @go install honnef.co/go/tools/cmd/staticcheck@v0.6.1 34 | staticcheck ./... 35 | 36 | .PHONY: ineffassign 37 | ineffassign: 38 | @go install github.com/gordonklaus/ineffassign@v0.0.0-20200309095847-7953dde2c7bf 39 | ineffassign . 40 | 41 | # Intentionally omitted from CI, but target here for ad-hoc reports. 42 | .PHONY: golint 43 | golint: 44 | @go install golang.org/x/lint/golint@v0.0.0-20210508222113-6edffad5e616 45 | golint -min_confidence 0.9 -set_exit_status ./... 46 | 47 | .PHONY: errcheck 48 | errcheck: 49 | @go install github.com/kisielk/errcheck@v1.9.0 50 | errcheck ./... 51 | 52 | .PHONY: test 53 | test: generate 54 | go test -cover -race ./... 55 | ./protoprint/testfiles/check-protos.sh > /dev/null 56 | 57 | .PHONY: generate 58 | generate: 59 | @go install golang.org/x/tools/cmd/goimports@v0.14.0 60 | go generate ./... 61 | go generate ./internal/testprotos 62 | goimports -w -local github.com/jhump/protoreflect/v2 . 63 | 64 | .PHONY: checkgenerate 65 | checkgenerate: generate 66 | # Make sure generate target doesn't produce a diff 67 | test -z "$$(git status --porcelain | tee /dev/stderr)" 68 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/jhump/protoreflect/v2 2 | 3 | go 1.23.0 4 | 5 | require ( 6 | github.com/bufbuild/protocompile v0.14.1 7 | github.com/google/go-cmp v0.6.0 8 | github.com/jhump/protoreflect v1.17.1-0.20240913204751-8f5fd1dcb3c5 9 | github.com/stretchr/testify v1.9.0 10 | golang.org/x/sync v0.12.0 11 | google.golang.org/grpc v1.66.2 12 | google.golang.org/protobuf v1.34.2 13 | ) 14 | 15 | require ( 16 | github.com/davecgh/go-spew v1.1.1 // indirect 17 | github.com/golang/protobuf v1.5.4 // indirect 18 | github.com/kr/pretty v0.3.0 // indirect 19 | github.com/pmezard/go-difflib v1.0.0 // indirect 20 | github.com/rogpeppe/go-internal v1.9.0 // indirect 21 | golang.org/x/net v0.38.0 // indirect 22 | golang.org/x/sys v0.31.0 // indirect 23 | golang.org/x/text v0.23.0 // indirect 24 | google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect 25 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect 26 | gopkg.in/yaml.v3 v3.0.1 // indirect 27 | ) 28 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw= 2 | github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c= 3 | github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 4 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 5 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 6 | github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= 7 | github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= 8 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 9 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 10 | github.com/jhump/protoreflect v1.17.1-0.20240913204751-8f5fd1dcb3c5 h1:OUsOWe/nhWohrzIjKP7Wk3Bt1lhDHn0w39uiT/zTWPM= 11 | github.com/jhump/protoreflect v1.17.1-0.20240913204751-8f5fd1dcb3c5/go.mod h1:uUKhM0KLkqvoYeM5BSlLxkJ3Dja3r0N08ru0cacT99E= 12 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 13 | github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= 14 | github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= 15 | github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= 16 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 17 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 18 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 19 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 20 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 21 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 22 | github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= 23 | github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= 24 | github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= 25 | github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= 26 | github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 27 | golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= 28 | golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= 29 | golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw= 30 | golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= 31 | golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= 32 | golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= 33 | golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= 34 | golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= 35 | google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 h1:1GBuWVLM/KMVUv1t1En5Gs+gFZCNd360GGb4sSxtrhU= 36 | google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= 37 | google.golang.org/grpc v1.66.2 h1:3QdXkuq3Bkh7w+ywLdLvM56cmGvQHUMZpiCzt6Rqaoo= 38 | google.golang.org/grpc v1.66.2/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= 39 | google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= 40 | google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= 41 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 42 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 43 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= 44 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= 45 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= 46 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 47 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 48 | -------------------------------------------------------------------------------- /grpcreflect/doc.go: -------------------------------------------------------------------------------- 1 | // Package grpcreflect provides gRPC-specific extensions to protobuf reflection. 2 | // This includes a way to access rich service descriptors for all services that 3 | // a gRPC server exports. 4 | // 5 | // Also included is an easy-to-use client for the [gRPC reflection service]. This 6 | // client makes it easy to ask a server (that supports the reflection service) 7 | // for metadata on its exported services, which could be used to construct a 8 | // dynamic client. (See the grpcdynamic package in this same repo for more on 9 | // that.) 10 | // 11 | // [gRPC reflection service]: https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1/reflection.proto 12 | package grpcreflect 13 | -------------------------------------------------------------------------------- /grpcreflect/server.go: -------------------------------------------------------------------------------- 1 | package grpcreflect 2 | 3 | import ( 4 | "fmt" 5 | 6 | "google.golang.org/grpc" 7 | "google.golang.org/grpc/reflection" 8 | "google.golang.org/protobuf/reflect/protoreflect" 9 | "google.golang.org/protobuf/reflect/protoregistry" 10 | 11 | "github.com/jhump/protoreflect/v2/protoresolve" 12 | ) 13 | 14 | // GRPCServer is the interface provided by a gRPC server. In addition to being a 15 | // service registrar (for registering services and handlers), it also has an 16 | // accessor for retrieving metadata about all registered services. 17 | type GRPCServer = reflection.GRPCServer 18 | 19 | // LoadServiceDescriptors loads the service descriptors for all services exposed by the 20 | // given GRPC server. 21 | func LoadServiceDescriptors(s GRPCServer) (map[string]protoreflect.ServiceDescriptor, error) { 22 | descs := map[string]protoreflect.ServiceDescriptor{} 23 | for name, info := range s.GetServiceInfo() { 24 | // See if the service info provides the schema in the service metadata. 25 | sd, ok := info.Metadata.(protoreflect.ServiceDescriptor) 26 | if !ok { 27 | var err error 28 | sd, err = findServiceDescriptor(name) 29 | if err != nil { 30 | return nil, err 31 | } 32 | } 33 | descs[name] = sd 34 | } 35 | return descs, nil 36 | } 37 | 38 | // LoadServiceDescriptor loads a rich descriptor for a given service description 39 | // generated by protoc-gen-go. Generated code contains an exported symbol with 40 | // a name like "_serviceDesc" which is the service's description. It 41 | // is used internally to register a service implementation with a GRPC server. 42 | // But it can also be used by this package to retrieve the rich descriptor for 43 | // the service. 44 | func LoadServiceDescriptor(svc *grpc.ServiceDesc) (protoreflect.ServiceDescriptor, error) { 45 | // See if the service info provides the schema in the service metadata. 46 | if sd, ok := svc.Metadata.(protoreflect.ServiceDescriptor); ok { 47 | return sd, nil 48 | } 49 | sd, err := findServiceDescriptor(svc.ServiceName) 50 | if err != nil { 51 | return nil, fmt.Errorf("could not resolve descriptor for service %q: %w", svc.ServiceName, err) 52 | } 53 | return sd, nil 54 | } 55 | 56 | func findServiceDescriptor(name string) (protoreflect.ServiceDescriptor, error) { 57 | d, err := protoregistry.GlobalFiles.FindDescriptorByName(protoreflect.FullName(name)) 58 | if err != nil { 59 | return nil, fmt.Errorf("could not resolve descriptor for service %q: %w", name, err) 60 | } 61 | sd, ok := d.(protoreflect.ServiceDescriptor) 62 | if !ok { 63 | return nil, protoresolve.NewUnexpectedTypeError(protoresolve.DescriptorKindService, d, "") 64 | } 65 | return sd, nil 66 | } 67 | -------------------------------------------------------------------------------- /grpcreflect/server_test.go: -------------------------------------------------------------------------------- 1 | package grpcreflect 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/require" 7 | "google.golang.org/grpc" 8 | "google.golang.org/protobuf/reflect/protoreflect" 9 | 10 | testprotosgrpc "github.com/jhump/protoreflect/v2/internal/testprotos/grpc" 11 | ) 12 | 13 | type testService struct { 14 | testprotosgrpc.DummyServiceServer 15 | } 16 | 17 | func TestLoadServiceDescriptors(t *testing.T) { 18 | s := grpc.NewServer() 19 | testprotosgrpc.RegisterDummyServiceServer(s, testService{}) 20 | sds, err := LoadServiceDescriptors(s) 21 | require.NoError(t, err) 22 | require.Equal(t, 1, len(sds)) 23 | sd := sds["testprotos.DummyService"] 24 | require.NotNil(t, sd) 25 | checkServiceDescriptor(t, sd) 26 | } 27 | 28 | func TestLoadServiceDescriptor(t *testing.T) { 29 | sd, err := LoadServiceDescriptor(&testprotosgrpc.DummyService_ServiceDesc) 30 | require.NoError(t, err) 31 | checkServiceDescriptor(t, sd) 32 | } 33 | 34 | func checkServiceDescriptor(t *testing.T, sd protoreflect.ServiceDescriptor) { 35 | t.Helper() 36 | 37 | cases := []struct { 38 | method protoreflect.Name 39 | request, response protoreflect.FullName 40 | }{ 41 | {"DoSomething", "testprotos.DummyRequest", "jhump.protoreflect.desc.Bar"}, 42 | {"DoSomethingElse", "testprotos.TestMessage", "testprotos.DummyResponse"}, 43 | {"DoSomethingAgain", "jhump.protoreflect.desc.Bar", "testprotos.AnotherTestMessage"}, 44 | {"DoSomethingForever", "testprotos.DummyRequest", "testprotos.DummyResponse"}, 45 | } 46 | 47 | require.Equal(t, len(cases), sd.Methods().Len()) 48 | 49 | for i, c := range cases { 50 | md := sd.Methods().Get(i) 51 | require.Equal(t, c.method, md.Name()) 52 | require.Equal(t, c.request, md.Input().FullName()) 53 | require.Equal(t, c.response, md.Output().FullName()) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /internal/fielddefault/field_default.go: -------------------------------------------------------------------------------- 1 | package fielddefault 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "math" 7 | "strconv" 8 | 9 | "google.golang.org/protobuf/reflect/protoreflect" 10 | ) 11 | 12 | // DefaultValue returns the string representation of the default value for 13 | // the given field. If it has no default, this returns the empty string. 14 | // The string representation is the same as stored in the default_value 15 | // field of a google.protobuf.FieldDescriptorProto message. 16 | func DefaultValue(fld protoreflect.FieldDescriptor) string { 17 | if !fld.HasDefault() || !fld.HasPresence() || 18 | fld.Cardinality() != protoreflect.Optional || fld.Message() != nil { 19 | return "" 20 | } 21 | defVal := fld.Default() 22 | if !defVal.IsValid() { 23 | return "" 24 | } 25 | switch fld.Kind() { 26 | case protoreflect.StringKind: 27 | return defVal.String() 28 | case protoreflect.BytesKind: 29 | return encodeDefaultBytes(defVal.Bytes()) 30 | case protoreflect.EnumKind: 31 | return string(fld.DefaultEnumValue().Name()) 32 | case protoreflect.FloatKind, protoreflect.DoubleKind: 33 | flt := defVal.Float() 34 | switch { 35 | case math.IsInf(flt, 1): 36 | return "inf" 37 | case math.IsInf(flt, -1): 38 | return "-inf" 39 | case math.IsNaN(flt): 40 | return "nan" 41 | } 42 | bitSize := 64 43 | if fld.Kind() == protoreflect.FloatKind { 44 | bitSize = 32 45 | } 46 | return strconv.FormatFloat(flt, 'g', -1, bitSize) 47 | case protoreflect.BoolKind: 48 | return strconv.FormatBool(defVal.Bool()) 49 | case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind, 50 | protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: 51 | return strconv.FormatInt(defVal.Int(), 10) 52 | case protoreflect.Uint32Kind, protoreflect.Fixed32Kind, 53 | protoreflect.Uint64Kind, protoreflect.Fixed64Kind: 54 | return strconv.FormatUint(defVal.Uint(), 10) 55 | default: 56 | // Shouldn't happen; above cases should be exhaustive... 57 | return fmt.Sprintf("%v", defVal.Interface()) 58 | } 59 | } 60 | 61 | func encodeDefaultBytes(data []byte) string { 62 | var buf bytes.Buffer 63 | // This uses the same algorithm as the protoc C++ code for escaping strings. 64 | // The protoc C++ code in turn uses the abseil C++ library's CEscape function: 65 | // https://github.com/abseil/abseil-cpp/blob/934f613818ffcb26c942dff4a80be9a4031c662c/absl/strings/escaping.cc#L406 66 | for _, c := range data { 67 | switch c { 68 | case '\n': 69 | buf.WriteString("\\n") 70 | case '\r': 71 | buf.WriteString("\\r") 72 | case '\t': 73 | buf.WriteString("\\t") 74 | case '"': 75 | buf.WriteString("\\\"") 76 | case '\'': 77 | buf.WriteString("\\'") 78 | case '\\': 79 | buf.WriteString("\\\\") 80 | default: 81 | if c >= 0x20 && c < 0x7f { 82 | // simple printable characters 83 | buf.WriteByte(c) 84 | } else { 85 | // use octal escape for all other values 86 | buf.WriteRune('\\') 87 | buf.WriteByte('0' + ((c >> 6) & 0x7)) 88 | buf.WriteByte('0' + ((c >> 3) & 0x7)) 89 | buf.WriteByte('0' + (c & 0x7)) 90 | } 91 | } 92 | } 93 | return buf.String() 94 | } 95 | -------------------------------------------------------------------------------- /internal/pinv1/pinv1.go: -------------------------------------------------------------------------------- 1 | // Package pinv1 is not used. It's sole purpose is to create a faux import 2 | // of the v1 of this module. That way if someone links in both v1 and v2 in 3 | // their program, it will pull in a later v1 version that shares sourceinfo 4 | // with v2. That way, regardless of what version of the sourceinfo package 5 | // was used, v1 or v2, all sourceinfo for all files is available. 6 | package pinv1 7 | 8 | //lint:file-ignore SA1019 The old v1 package is deprecated, but this is not a real dependency... 9 | 10 | import "github.com/jhump/protoreflect/desc" 11 | 12 | var _ desc.Descriptor = nil 13 | -------------------------------------------------------------------------------- /internal/register/register.go: -------------------------------------------------------------------------------- 1 | package register 2 | 3 | import ( 4 | "google.golang.org/protobuf/reflect/protoreflect" 5 | "google.golang.org/protobuf/reflect/protoregistry" 6 | "google.golang.org/protobuf/types/dynamicpb" 7 | ) 8 | 9 | // RegisterTypesVisibleToFile registers types (extensions and messages) that are 10 | // visible to the given file. This includes types defined in file as well as types 11 | // defined in the files that it imports (and any public imports thereof, etc). 12 | func RegisterTypesVisibleToFile(file protoreflect.FileDescriptor, reg *protoregistry.Types, includeMessages bool) { 13 | registerTypes(file, reg, includeMessages) 14 | imports := file.Imports() 15 | for i, length := 0, imports.Len(); i < length; i++ { 16 | dep := imports.Get(i).FileDescriptor 17 | RegisterTypesInImportedFile(dep, reg, includeMessages) 18 | } 19 | } 20 | 21 | // RegisterTypesInImportedFile registers types (extensions and messages) in the 22 | // given file as well as those in its public imports. So if another file imports 23 | // the given file, this adds all types made visible to that importing file. 24 | func RegisterTypesInImportedFile(file protoreflect.FileDescriptor, reg *protoregistry.Types, includeMessages bool) { 25 | registerTypes(file, reg, includeMessages) 26 | imports := file.Imports() 27 | for i, length := 0, imports.Len(); i < length; i++ { 28 | dep := file.Imports().Get(i) 29 | if dep.IsPublic { 30 | RegisterTypesInImportedFile(dep.FileDescriptor, reg, includeMessages) 31 | } 32 | } 33 | } 34 | 35 | type typeContainer interface { 36 | Messages() protoreflect.MessageDescriptors 37 | Extensions() protoreflect.ExtensionDescriptors 38 | } 39 | 40 | // NB: This is similar to the unexported function of the same name in protoresolve, but 41 | // this version is best effort and ignores all errors, and it doesn't register enums. 42 | func registerTypes(container typeContainer, reg *protoregistry.Types, includeMessages bool) { 43 | msgs := container.Messages() 44 | for i, length := 0, msgs.Len(); i < length; i++ { 45 | msg := msgs.Get(i) 46 | if includeMessages { 47 | _ = reg.RegisterMessage(dynamicpb.NewMessageType(msg)) 48 | } 49 | // register nested types 50 | registerTypes(msg, reg, includeMessages) 51 | } 52 | 53 | exts := container.Extensions() 54 | for i, length := 0, exts.Len(); i < length; i++ { 55 | ext := exts.Get(i) 56 | _ = reg.RegisterExtension(dynamicpb.NewExtensionType(ext)) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /internal/reparse/reparse.go: -------------------------------------------------------------------------------- 1 | package reparse 2 | 3 | import ( 4 | "google.golang.org/protobuf/proto" 5 | "google.golang.org/protobuf/reflect/protoreflect" 6 | 7 | "github.com/jhump/protoreflect/v2/internal" 8 | ) 9 | 10 | // ReparseUnrecognized uses the given resolver to re-parse any unrecognized 11 | // fields in msg. It returns true if any changes were made due to successfully 12 | // re-parsing fields. 13 | func ReparseUnrecognized(msg protoreflect.Message, resolver resolver) bool { 14 | var changed bool 15 | msg.Range(func(fld protoreflect.FieldDescriptor, val protoreflect.Value) bool { 16 | if !internal.IsMessageKind(fld.Kind()) { 17 | return true 18 | } 19 | if fld.IsList() { 20 | l := val.List() 21 | for i := 0; i < l.Len(); i++ { 22 | if ReparseUnrecognized(l.Get(i).Message(), resolver) { 23 | changed = true 24 | } 25 | } 26 | } else if fld.IsMap() { 27 | mapVal := fld.MapValue() 28 | if !internal.IsMessageKind(mapVal.Kind()) { 29 | return true 30 | } 31 | m := val.Map() 32 | m.Range(func(k protoreflect.MapKey, v protoreflect.Value) bool { 33 | if ReparseUnrecognized(v.Message(), resolver) { 34 | changed = true 35 | } 36 | return true 37 | }) 38 | } else if ReparseUnrecognized(val.Message(), resolver) { 39 | changed = true 40 | } 41 | return true 42 | }) 43 | 44 | unk := msg.GetUnknown() 45 | if len(unk) > 0 { 46 | other := msg.New().Interface() 47 | if err := (proto.UnmarshalOptions{Resolver: resolver}).Unmarshal(unk, other); err == nil { 48 | msg.SetUnknown(nil) 49 | proto.Merge(msg.Interface(), other) 50 | changed = true 51 | } 52 | } 53 | 54 | return changed 55 | } 56 | 57 | // resolver is the interface required by the Resolver field 58 | // of proto.UnmarshalOptions. 59 | type resolver interface { 60 | FindExtensionByName(field protoreflect.FullName) (protoreflect.ExtensionType, error) 61 | FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error) 62 | } 63 | -------------------------------------------------------------------------------- /internal/sort/sort.go: -------------------------------------------------------------------------------- 1 | package sort 2 | 3 | import ( 4 | "fmt" 5 | 6 | "google.golang.org/protobuf/types/descriptorpb" 7 | ) 8 | 9 | // SortFiles topologically sorts the given file descriptor protos. It returns 10 | // an error if the given files include duplicates (more than one entry with the 11 | // same path) or if any of the files refer to imports which are not present in 12 | // the given files. 13 | func SortFiles(files []*descriptorpb.FileDescriptorProto) error { 14 | allFiles := make(map[string]fileState, len(files)) 15 | for _, file := range files { 16 | if _, exists := allFiles[file.GetName()]; exists { 17 | return fmt.Errorf("duplicate file %q", file.GetName()) 18 | } 19 | allFiles[file.GetName()] = fileState{file: file} 20 | } 21 | origLen := len(files) 22 | files = files[:0] 23 | for _, file := range files { 24 | if err := addFileSorted(file, allFiles, &files); err != nil { 25 | return err 26 | } 27 | } 28 | if origLen != len(files) { 29 | // should not be possible since we've already removed duplicates... 30 | return fmt.Errorf("internal: sorted files has length %d, but original had length %d", len(files), origLen) 31 | } 32 | return nil 33 | } 34 | 35 | func addFileSorted(file *descriptorpb.FileDescriptorProto, allFiles map[string]fileState, sorted *[]*descriptorpb.FileDescriptorProto) error { 36 | state := allFiles[file.GetName()] 37 | if state.added { 38 | return nil 39 | } 40 | state.added = true 41 | allFiles[file.GetName()] = state 42 | for _, dep := range file.GetDependency() { 43 | depFile := allFiles[dep] 44 | if depFile.file == nil { 45 | return fmt.Errorf("file %q imports %q, but %q is not present", file.GetName(), dep, dep) 46 | } 47 | if err := addFileSorted(depFile.file, allFiles, sorted); err != nil { 48 | return err 49 | } 50 | } 51 | *sorted = append(*sorted, file) 52 | return nil 53 | } 54 | 55 | type fileState struct { 56 | file *descriptorpb.FileDescriptorProto 57 | added bool 58 | } 59 | -------------------------------------------------------------------------------- /internal/testing/protoset.go: -------------------------------------------------------------------------------- 1 | package testing 2 | 3 | import ( 4 | "io" 5 | "os" 6 | 7 | "google.golang.org/protobuf/proto" 8 | "google.golang.org/protobuf/reflect/protodesc" 9 | "google.golang.org/protobuf/reflect/protoreflect" 10 | "google.golang.org/protobuf/types/descriptorpb" 11 | ) 12 | 13 | // LoadProtoset loads the compiled protoset file at the given path. It returns 14 | // the last file descriptor in the set. When generating a protoset for a single 15 | // file, that file is always last (and its dependencies before it). 16 | func LoadProtoset(path string) (protoreflect.FileDescriptor, error) { 17 | var fds descriptorpb.FileDescriptorSet 18 | f, err := os.Open(path) 19 | if err != nil { 20 | return nil, err 21 | } 22 | defer func() { 23 | _ = f.Close() 24 | }() 25 | bb, err := io.ReadAll(f) 26 | if err != nil { 27 | return nil, err 28 | } 29 | if err = proto.Unmarshal(bb, &fds); err != nil { 30 | return nil, err 31 | } 32 | res, err := protodesc.NewFiles(&fds) 33 | if err != nil { 34 | return nil, err 35 | } 36 | // return the last file in the set 37 | return res.FindFileByPath(fds.File[len(fds.File)-1].GetName()) 38 | } 39 | -------------------------------------------------------------------------------- /internal/testing/test_service.go: -------------------------------------------------------------------------------- 1 | package testing 2 | 3 | import ( 4 | "context" 5 | "io" 6 | 7 | "google.golang.org/protobuf/types/known/emptypb" 8 | 9 | "github.com/jhump/protoreflect/v2/internal/testprotos/grpc" 10 | ) 11 | 12 | // TestService is a very simple test service that just echos back request payloads 13 | type TestService struct { 14 | grpc.UnimplementedTestServiceServer 15 | } 16 | 17 | // EmptyCall satisfies the grpc.TestServiceServer interface. It always succeeds. 18 | func (TestService) EmptyCall(_ context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) { 19 | return &emptypb.Empty{}, nil 20 | } 21 | 22 | // UnaryCall satisfies the grpc.TestServiceServer interface. It always succeeds, echoing 23 | // back the payload present in the request. 24 | func (TestService) UnaryCall(_ context.Context, req *grpc.SimpleRequest) (*grpc.SimpleResponse, error) { 25 | return &grpc.SimpleResponse{ 26 | Payload: req.Payload, 27 | }, nil 28 | } 29 | 30 | // StreamingOutputCall satisfies the grpc.TestServiceServer interface. It only fails if the 31 | // client cancels or disconnects (thus causing ss.Send to return an error). It echoes a number of 32 | // responses equal to the request's number of response parameters. The requested parameter details, 33 | // however, ignored. The response payload is always an echo of the request payload. 34 | func (TestService) StreamingOutputCall(req *grpc.StreamingOutputCallRequest, ss grpc.TestService_StreamingOutputCallServer) error { 35 | for i := 0; i < len(req.GetResponseParameters()); i++ { 36 | err := ss.Send(&grpc.StreamingOutputCallResponse{ 37 | Payload: req.Payload, 38 | }) 39 | if err != nil { 40 | return err 41 | } 42 | } 43 | return nil 44 | } 45 | 46 | // StreamingInputCall satisfies the grpc.TestServiceServer interface. It always succeeds, 47 | // sending back the total observed size of all request payloads. 48 | func (TestService) StreamingInputCall(ss grpc.TestService_StreamingInputCallServer) error { 49 | sz := 0 50 | for { 51 | req, err := ss.Recv() 52 | if err == io.EOF { 53 | break 54 | } 55 | if err != nil { 56 | return err 57 | } 58 | sz += len(req.Payload.GetBody()) 59 | } 60 | return ss.SendAndClose(&grpc.StreamingInputCallResponse{ 61 | AggregatedPayloadSize: int32(sz), 62 | }) 63 | } 64 | 65 | // FullDuplexCall satisfies the grpc.TestServiceServer interface. It only fails if the 66 | // client cancels or disconnects (thus causing ss.Send to return an error). For each request 67 | // message it receives, it sends back a response message with the same payload. 68 | func (TestService) FullDuplexCall(ss grpc.TestService_FullDuplexCallServer) error { 69 | for { 70 | req, err := ss.Recv() 71 | if err == io.EOF { 72 | return nil 73 | } 74 | if err != nil { 75 | return err 76 | } 77 | 78 | err = ss.Send(&grpc.StreamingOutputCallResponse{ 79 | Payload: req.Payload, 80 | }) 81 | if err != nil { 82 | return err 83 | } 84 | } 85 | } 86 | 87 | // HalfDuplexCall satisfies the grpc.TestServiceServer interface. It only fails if the 88 | // client cancels or disconnects (thus causing ss.Send to return an error). For each request 89 | // message it receives, it sends back a response message with the same payload. But since it is 90 | // half-duplex, all of the request payloads are buffered and responses will only be sent after 91 | // the request stream is half-closed. 92 | func (TestService) HalfDuplexCall(ss grpc.TestService_HalfDuplexCallServer) error { 93 | var data []*grpc.Payload 94 | for { 95 | req, err := ss.Recv() 96 | if err == io.EOF { 97 | break 98 | } 99 | if err != nil { 100 | return err 101 | } 102 | data = append(data, req.Payload) 103 | } 104 | 105 | for _, d := range data { 106 | err := ss.Send(&grpc.StreamingOutputCallResponse{ 107 | Payload: d, 108 | }) 109 | if err != nil { 110 | return err 111 | } 112 | } 113 | return nil 114 | } 115 | -------------------------------------------------------------------------------- /internal/testprotos/desc_test1.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | 5 | package testprotos; 6 | 7 | // Comment for TestMessage 8 | message TestMessage { 9 | // Comment for NestedMessage 10 | message NestedMessage { 11 | // Comment for AnotherNestedMessage 12 | message AnotherNestedMessage { 13 | // Comment for AnotherTestMessage extensions (1) 14 | extend AnotherTestMessage { 15 | // Comment for flags 16 | repeated bool flags = 200 [packed = true]; 17 | } 18 | // Comment for YetAnotherNestedMessage 19 | message YetAnotherNestedMessage { 20 | // Comment for DeeplyNestedEnum 21 | enum DeeplyNestedEnum { 22 | // Comment for VALUE1 23 | VALUE1 = 1; 24 | // Comment for VALUE2 25 | VALUE2 = 2; 26 | } 27 | // Comment for foo 28 | optional string foo = 1; 29 | // Comment for bar 30 | optional int32 bar = 2; 31 | // Comment for baz 32 | optional bytes baz = 3; 33 | // Comment for dne 34 | optional DeeplyNestedEnum dne = 4; 35 | // Comment for anm 36 | optional AnotherNestedMessage anm = 5; 37 | // Comment for nm 38 | optional NestedMessage nm = 6; 39 | // Comment for tm 40 | optional TestMessage tm = 7; 41 | } 42 | // Comment for yanm 43 | repeated YetAnotherNestedMessage yanm = 1; 44 | } 45 | // Comment for anm 46 | optional AnotherNestedMessage anm = 1; 47 | // Comment for yanm 48 | optional AnotherNestedMessage 49 | .YetAnotherNestedMessage // multi-line type ref 50 | yanm = 2; 51 | } 52 | // Comment for NestedEnum 53 | enum NestedEnum { 54 | // Comment for VALUE1 55 | VALUE1 = 1; 56 | // Comment for VALUE2 57 | VALUE2 = 2; 58 | } 59 | // Comment for nm 60 | optional NestedMessage nm = 1; 61 | // Comment for anm 62 | optional NestedMessage.AnotherNestedMessage anm = 2; 63 | // Comment for yanm 64 | optional NestedMessage.AnotherNestedMessage // another multi-line type ref 65 | .YetAnotherNestedMessage yanm = 3; 66 | // Comment for ne 67 | repeated NestedEnum ne = 4; 68 | } 69 | 70 | // Comment for AnotherTestMessage 71 | message AnotherTestMessage { 72 | // Comment for dne 73 | optional TestMessage.NestedMessage.AnotherNestedMessage.YetAnotherNestedMessage.DeeplyNestedEnum dne = 1; 74 | // Comment for map_field1 75 | map map_field1 = 2; 76 | // Comment for map_field2 77 | map map_field2 = 3; 78 | // Comment for map_field3 79 | map map_field3 = 4; 80 | // Comment for map_field4 81 | map map_field4 = 5; 82 | // Comment for RockNRoll 83 | optional group RockNRoll = 6 { 84 | // Comment for beatles 85 | optional string beatles = 1; 86 | // Comment for stones 87 | optional string stones = 2; 88 | // Comment for doors 89 | optional string doors = 3; 90 | } 91 | // Comment for atmoo 92 | oneof atmoo { 93 | // Comment for str 94 | string str = 7; 95 | // Comment for int 96 | int64 int = 8; 97 | } 98 | // Comment for WithOptions 99 | optional group WithOptions = 9 [deprecated = true] { 100 | } 101 | 102 | extensions 100 to 200; 103 | } 104 | 105 | // Comment for AnotherTestMessage extensions (2) 106 | extend AnotherTestMessage { 107 | // Comment for xtm 108 | optional TestMessage xtm = 100; 109 | // Comment for xs 110 | optional string xs = 101; 111 | } 112 | 113 | // Comment for AnotherTestMessage extensions (3) 114 | extend AnotherTestMessage { 115 | // Comment for xi 116 | optional int32 xi = 102; 117 | // Comment for xui 118 | optional uint64 xui = 103; 119 | } 120 | 121 | // Comment for SomeEnum 122 | enum SomeEnum { 123 | // Comment for SOME_VAL 124 | SOME_VAL = 0; 125 | // Comment for ANOTHER_VAL 126 | ANOTHER_VAL = 1; 127 | // Comment for YET_ANOTHER_VAL 128 | YET_ANOTHER_VAL = 2; 129 | } 130 | 131 | // Comment for SomeService 132 | service SomeService { 133 | // Comment for SomeMethod 134 | rpc SomeMethod(TestMessage) returns (TestMessage); 135 | // Comment for SomeOtherMethod 136 | rpc SomeOtherMethod(AnotherTestMessage) returns (AnotherTestMessage); 137 | } 138 | -------------------------------------------------------------------------------- /internal/testprotos/desc_test1.protoset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jhump/protoreflect/170fc7af656126cb450190be2f9e43ab305e6f27/internal/testprotos/desc_test1.protoset -------------------------------------------------------------------------------- /internal/testprotos/desc_test2.pb.srcinfo.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gosrcinfo. DO NOT EDIT. 2 | // source: desc_test2.proto 3 | 4 | package testprotos 5 | 6 | import ( 7 | sourceinfo "github.com/jhump/protoreflect/v2/sourceinfo" 8 | ) 9 | 10 | func init() { 11 | srcInfo := []byte{ 12 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x4c, 0x94, 0xdb, 0x7a, 0xdb, 0x36, 13 | 0x10, 0x84, 0xb1, 0x1c, 0x90, 0x04, 0x11, 0x27, 0x21, 0x27, 0xb6, 0x45, 0xda, 0x3a, 0xc4, 0x72, 14 | 0x24, 0x47, 0x2a, 0x29, 0xdb, 0xfd, 0xd2, 0x43, 0x7a, 0xd3, 0xf6, 0xb6, 0x7d, 0xff, 0xf7, 0xe9, 15 | 0xb7, 0x00, 0xd6, 0xcd, 0xdd, 0xfc, 0xb3, 0xd8, 0x59, 0x08, 0x00, 0x15, 0x1b, 0x7a, 0xe7, 0x5e, 16 | 0x24, 0x86, 0x28, 0x57, 0x84, 0x73, 0x54, 0x15, 0x88, 0xca, 0xfd, 0x1b, 0xbb, 0x58, 0x85, 0x77, 17 | 0x59, 0x66, 0x13, 0x6e, 0x4e, 0xe6, 0x75, 0x96, 0xd9, 0xf4, 0x6e, 0x9f, 0xcc, 0x98, 0x65, 0x36, 18 | 0x6b, 0xf7, 0x4f, 0x32, 0x25, 0xcb, 0x6c, 0x36, 0x6e, 0x97, 0xcc, 0x5d, 0x96, 0xd9, 0x6c, 0xdd, 19 | 0x4b, 0x32, 0x97, 0x2c, 0xb3, 0x19, 0xdc, 0x1f, 0xc9, 0x3c, 0x64, 0x19, 0xa2, 0x54, 0x44, 0x74, 20 | 0x9f, 0xd4, 0x84, 0x23, 0xae, 0xdc, 0x5d, 0x92, 0x42, 0xbc, 0x77, 0x0f, 0x49, 0x56, 0xc4, 0x07, 21 | 0x77, 0x88, 0x31, 0x56, 0xde, 0xd1, 0xf7, 0x6e, 0x27, 0x31, 0x46, 0x78, 0x27, 0x44, 0x1f, 0xfa, 22 | 0xf8, 0x2e, 0x7a, 0xef, 0x2a, 0x47, 0x0c, 0xe1, 0x31, 0x5e, 0xc5, 0x5a, 0xc1, 0x2b, 0xf5, 0x46, 23 | 0x0d, 0x31, 0x0c, 0x6b, 0x23, 0x21, 0x86, 0xcd, 0xd6, 0x08, 0xc4, 0xf0, 0xb0, 0x2f, 0x21, 0x42, 24 | 0x30, 0x9c, 0x4b, 0x49, 0xbc, 0x92, 0x85, 0x48, 0x43, 0x70, 0xb0, 0x01, 0xa2, 0x2b, 0xbf, 0x1c, 25 | 0x8c, 0x40, 0xf0, 0xeb, 0x29, 0x5e, 0x69, 0x48, 0x70, 0xf4, 0x9f, 0xc2, 0x6d, 0x97, 0x6b, 0x41, 26 | 0xc7, 0x7d, 0xfa, 0x30, 0x94, 0x01, 0x15, 0x71, 0xdd, 0xbf, 0x96, 0xb6, 0xaa, 0x51, 0x3a, 0x19, 27 | 0x09, 0x71, 0x7d, 0x9e, 0x8d, 0x40, 0x5c, 0x3f, 0xbf, 0x94, 0x36, 0x10, 0x37, 0xfd, 0xa5, 0x94, 28 | 0xd0, 0x28, 0x1d, 0x8d, 0x84, 0xb8, 0x79, 0xb2, 0x10, 0xe8, 0xca, 0x79, 0x29, 0x6d, 0x9e, 0x58, 29 | 0x05, 0x9b, 0xe6, 0x13, 0xd9, 0xcf, 0xf1, 0x0d, 0xb1, 0x1a, 0xec, 0xa7, 0x7a, 0x21, 0x56, 0x3f, 30 | 0xd9, 0x6c, 0x0f, 0x62, 0xf5, 0x36, 0xbb, 0x26, 0xc6, 0xf0, 0x77, 0x29, 0xd5, 0x5e, 0xc9, 0x42, 31 | 0xea, 0x86, 0x18, 0x87, 0x27, 0x23, 0x21, 0xc6, 0xaf, 0xb6, 0x93, 0x1a, 0xc4, 0x38, 0x2f, 0x46, 32 | 0x81, 0x18, 0x2f, 0x7f, 0x19, 0xb5, 0xc4, 0xf8, 0xfd, 0xcf, 0x32, 0xa0, 0x21, 0xa6, 0xf0, 0x73, 33 | 0x29, 0x35, 0x5e, 0xc9, 0x06, 0x34, 0x35, 0x31, 0x0d, 0x2b, 0x23, 0x21, 0xa6, 0x71, 0x32, 0x02, 34 | 0x31, 0xad, 0x37, 0x46, 0x81, 0x98, 0xb6, 0xaf, 0xf1, 0x7d, 0x6c, 0x12, 0x69, 0x71, 0xf7, 0x52, 35 | 0x6e, 0x44, 0xe8, 0xef, 0xc2, 0xd6, 0x6e, 0x44, 0xef, 0xee, 0xee, 0xed, 0x46, 0x5a, 0xe2, 0xbe, 36 | 0xb7, 0x94, 0xb6, 0x56, 0xba, 0x31, 0x12, 0xe2, 0xfe, 0x76, 0x34, 0x02, 0x71, 0x7f, 0xbf, 0x2e, 37 | 0x6d, 0x81, 0x58, 0xf7, 0xf6, 0x88, 0x42, 0xad, 0x74, 0x6b, 0x24, 0xc4, 0x7a, 0x65, 0xdb, 0xd4, 38 | 0x9d, 0xac, 0xd7, 0x9b, 0xd2, 0xd6, 0x11, 0x9b, 0x7e, 0x57, 0x4a, 0x5d, 0xad, 0x64, 0x6d, 0x9d, 39 | 0x10, 0x9b, 0xb7, 0xb6, 0x0e, 0xc4, 0x66, 0xbd, 0x4d, 0x8f, 0x5e, 0xe8, 0x1f, 0xdc, 0x63, 0x7e, 40 | 0xf4, 0xba, 0xf9, 0x87, 0xb0, 0x4a, 0x71, 0xa2, 0x8f, 0x7e, 0x1f, 0x7e, 0x4d, 0x2d, 0x92, 0x1e, 41 | 0xfd, 0xbe, 0x1c, 0x9d, 0xa4, 0x47, 0xbf, 0x1f, 0x66, 0x23, 0x21, 0xf6, 0xcb, 0xab, 0x11, 0x88, 42 | 0xfd, 0xb7, 0x5f, 0x52, 0x78, 0x45, 0x7f, 0x70, 0x4f, 0x39, 0x5c, 0x9f, 0xe0, 0x21, 0x7c, 0x4c, 43 | 0xe1, 0x95, 0x86, 0x1f, 0xc3, 0xf7, 0xd4, 0x52, 0xa5, 0xf0, 0x63, 0x09, 0xaf, 0x52, 0xf8, 0xb1, 44 | 0x84, 0x57, 0x29, 0xfc, 0xb8, 0x7c, 0x33, 0x02, 0x71, 0xfc, 0xed, 0xf7, 0xd8, 0x45, 0x69, 0xe9, 45 | 0x4f, 0xfa, 0x0f, 0xd4, 0xc5, 0xaa, 0x75, 0xc4, 0x39, 0x7c, 0xd1, 0x31, 0xad, 0xab, 0x88, 0x53, 46 | 0xfb, 0x31, 0x6b, 0xaf, 0x7e, 0x9f, 0x75, 0x43, 0x9c, 0x87, 0x29, 0x6b, 0x21, 0xce, 0x77, 0x9b, 47 | 0xac, 0x41, 0x9c, 0x3f, 0x3f, 0xea, 0x76, 0x5b, 0xa1, 0x9f, 0xc3, 0x73, 0x97, 0x7c, 0xf9, 0x21, 48 | 0x47, 0x3f, 0xd6, 0xb9, 0xe4, 0x48, 0x4d, 0xcc, 0xc3, 0x6d, 0xd6, 0x42, 0xcc, 0xab, 0x9c, 0xa3, 49 | 0x9f, 0xe9, 0x9c, 0x73, 0x3c, 0xfe, 0xcf, 0xf1, 0xf8, 0x71, 0x4d, 0x93, 0xb5, 0x1e, 0x01, 0xf4, 50 | 0x08, 0x96, 0xf2, 0xdd, 0x21, 0x1d, 0xc1, 0xd2, 0x8f, 0x46, 0x35, 0xb1, 0x4c, 0x5b, 0x23, 0x21, 51 | 0x96, 0xdd, 0xd1, 0x08, 0xc4, 0x72, 0x5a, 0x4a, 0x88, 0x10, 0x97, 0xfe, 0xb9, 0x94, 0x74, 0x9f, 52 | 0x97, 0xb7, 0x10, 0xdd, 0xe9, 0x65, 0xda, 0x19, 0xe9, 0xca, 0xcf, 0x4f, 0x46, 0x20, 0x2e, 0xe7, 53 | 0xcb, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xbd, 0xf7, 0xbd, 0xbc, 0xc7, 0x05, 0x00, 0x00, 54 | } 55 | sourceinfo.Register("desc_test2.proto", srcInfo) 56 | } 57 | -------------------------------------------------------------------------------- /internal/testprotos/desc_test2.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | option java_generate_equals_and_hash = true; 5 | option java_multiple_files = true; 6 | option java_package = "com.github.jhump.protoreflect.internal.testprotos"; 7 | option cc_enable_arenas = true; 8 | option ruby_package = "protoreflect-testprotos"; 9 | option csharp_namespace = "jhump.protoreflect.testprotos"; 10 | 11 | package testprotos; 12 | 13 | import "desc_test1.proto"; 14 | import "pkg/desc_test_pkg.proto"; 15 | import "nopkg/desc_test_nopkg.proto"; 16 | 17 | message Frobnitz { 18 | optional TestMessage a = 1; 19 | optional AnotherTestMessage b = 2; 20 | oneof abc { 21 | TestMessage.NestedMessage c1 = 3; 22 | TestMessage.NestedEnum c2 = 4; 23 | } 24 | optional TestMessage.NestedMessage d = 5; 25 | optional TestMessage.NestedEnum e = 6 [default = VALUE2]; 26 | repeated string f = 7 [deprecated = true]; 27 | oneof def { 28 | int32 g1 = 8; 29 | sint32 g2 = 9; 30 | uint32 g3 = 10; 31 | } 32 | } 33 | 34 | message Whatchamacallit { 35 | required jhump.protoreflect.desc.Foo foos = 1; 36 | } 37 | 38 | message Whatzit { 39 | repeated jhump.protoreflect.desc.Bar gyzmeau = 1; 40 | } 41 | 42 | extend TopLevel { 43 | optional TopLevel otl = 100; 44 | 45 | optional group GroupX = 104 { 46 | optional int64 groupxi = 1041; 47 | optional string groupxs = 1042; 48 | } 49 | } -------------------------------------------------------------------------------- /internal/testprotos/desc_test_comments.protoset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jhump/protoreflect/170fc7af656126cb450190be2f9e43ab305e6f27/internal/testprotos/desc_test_comments.protoset -------------------------------------------------------------------------------- /internal/testprotos/desc_test_complex.protoset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jhump/protoreflect/170fc7af656126cb450190be2f9e43ab305e6f27/internal/testprotos/desc_test_complex.protoset -------------------------------------------------------------------------------- /internal/testprotos/desc_test_complex_source_info.protoset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jhump/protoreflect/170fc7af656126cb450190be2f9e43ab305e6f27/internal/testprotos/desc_test_complex_source_info.protoset -------------------------------------------------------------------------------- /internal/testprotos/desc_test_editions.pb.srcinfo.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gosrcinfo. DO NOT EDIT. 2 | // source: desc_test_editions.proto 3 | 4 | package testprotos 5 | 6 | import ( 7 | sourceinfo "github.com/jhump/protoreflect/v2/sourceinfo" 8 | ) 9 | 10 | func init() { 11 | srcInfo := []byte{ 12 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x4c, 0x92, 0xef, 0x92, 0xd3, 0x30, 13 | 0x0c, 0xc4, 0x2d, 0xad, 0xdd, 0x3a, 0x72, 0x9c, 0x5c, 0xd4, 0xeb, 0x4d, 0xd3, 0xd2, 0xe3, 0xa0, 14 | 0x74, 0x5a, 0xbe, 0xf2, 0x18, 0x1c, 0x33, 0xc0, 0xfb, 0xbf, 0x0c, 0x23, 0xff, 0xe9, 0xf1, 0x4d, 15 | 0xbf, 0x68, 0xb5, 0xde, 0xd8, 0x92, 0x8d, 0x7a, 0xe7, 0xee, 0x24, 0x51, 0x68, 0x54, 0x38, 0xb7, 16 | 0x58, 0xc5, 0x0a, 0x76, 0x3b, 0xab, 0xa2, 0xc2, 0xbb, 0x77, 0x19, 0x84, 0x63, 0xaa, 0x65, 0xfd, 17 | 0xb8, 0x71, 0xf7, 0xf2, 0xf1, 0x47, 0x2d, 0x45, 0xd8, 0x3b, 0xf5, 0xd1, 0xbd, 0x90, 0x88, 0xc0, 18 | 0x3b, 0x52, 0xc4, 0x98, 0x6a, 0x2d, 0x8a, 0x81, 0x8f, 0x92, 0xc4, 0x7b, 0x27, 0x4e, 0x31, 0xa4, 19 | 0xb5, 0x02, 0x3b, 0x45, 0xe2, 0x49, 0x46, 0x09, 0x06, 0xc1, 0x68, 0xdb, 0x89, 0x14, 0x29, 0x0e, 20 | 0x9d, 0xa0, 0x48, 0x63, 0x6e, 0x63, 0xa4, 0xc8, 0xfc, 0xab, 0xb5, 0x28, 0x18, 0xf5, 0x31, 0xb2, 21 | 0x5e, 0x7c, 0xe9, 0x04, 0x45, 0x5e, 0x8f, 0x9d, 0xa2, 0x22, 0x9f, 0xde, 0x25, 0xcb, 0xa6, 0xd0, 22 | 0x5e, 0x91, 0x3f, 0xfd, 0x6c, 0x9e, 0xac, 0x98, 0xf9, 0x7b, 0x53, 0x72, 0x30, 0xea, 0x9e, 0x76, 23 | 0xde, 0x1c, 0xf7, 0x9d, 0xa0, 0x98, 0x0f, 0x6b, 0xa7, 0xa8, 0x98, 0x8f, 0xf7, 0x4e, 0x5b, 0xc5, 24 | 0x7c, 0xbd, 0x35, 0x4b, 0x28, 0x16, 0xfe, 0xdb, 0x5a, 0xd8, 0x18, 0x3d, 0x75, 0x22, 0xc5, 0xb2, 25 | 0x7c, 0xee, 0x64, 0xca, 0xaf, 0x97, 0x4e, 0x51, 0xb1, 0x7c, 0xfb, 0xd3, 0x62, 0xc2, 0x62, 0x2e, 26 | 0xd7, 0xdf, 0x32, 0x9a, 0x27, 0x9c, 0xfa, 0x1d, 0xef, 0x51, 0xa5, 0xb0, 0x4b, 0xda, 0xc9, 0xa1, 27 | 0x4a, 0x51, 0xee, 0xf3, 0xd9, 0x3f, 0xc9, 0x24, 0xdb, 0x8a, 0xc1, 0x78, 0xf8, 0x60, 0x52, 0x3c, 28 | 0x4b, 0xfa, 0x60, 0x28, 0x9e, 0xa7, 0xd9, 0x5e, 0x2f, 0x38, 0xf5, 0x07, 0xf7, 0x5a, 0x5e, 0x2f, 29 | 0x98, 0xee, 0x10, 0x92, 0xfd, 0x46, 0x28, 0xa6, 0x2b, 0xcf, 0x76, 0x62, 0xa8, 0x16, 0x2b, 0x4b, 30 | 0x27, 0x56, 0xac, 0x79, 0x6a, 0x42, 0x52, 0x9c, 0x1e, 0x42, 0x2a, 0xd4, 0x85, 0xb6, 0x51, 0xa7, 31 | 0x3c, 0x55, 0xf7, 0xa0, 0x38, 0xf3, 0x6b, 0x1d, 0x0a, 0x4e, 0x71, 0x4e, 0xbb, 0x06, 0xa4, 0x38, 32 | 0xef, 0xcf, 0x25, 0x0f, 0xa9, 0x7f, 0xb3, 0xbd, 0xb4, 0x09, 0xf3, 0x7a, 0x0b, 0x43, 0xad, 0xa1, 33 | 0xf8, 0xc2, 0xf7, 0x32, 0x40, 0xd8, 0xfe, 0x07, 0x16, 0xf4, 0xc2, 0xb9, 0x9c, 0x48, 0x25, 0xe8, 34 | 0x85, 0x63, 0x27, 0x56, 0x5c, 0xd2, 0xd8, 0x84, 0xa4, 0xb8, 0xd6, 0xb5, 0x33, 0x28, 0xd4, 0x85, 35 | 0x16, 0xf4, 0x9a, 0x72, 0x13, 0xb2, 0xe2, 0xf6, 0x70, 0xb4, 0xb1, 0xdb, 0x43, 0x58, 0x7a, 0x69, 36 | 0xfc, 0x17, 0x00, 0x00, 0xff, 0xff, 0xd2, 0x2d, 0xad, 0x70, 0x40, 0x03, 0x00, 0x00, 37 | } 38 | sourceinfo.Register("desc_test_editions.proto", srcInfo) 39 | } 40 | -------------------------------------------------------------------------------- /internal/testprotos/desc_test_editions.proto: -------------------------------------------------------------------------------- 1 | edition = "2023"; 2 | 3 | package testprotos; 4 | 5 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 6 | 7 | option features = { enum_type: CLOSED }; 8 | 9 | message Foo { 10 | reserved reserved_field; 11 | 12 | int32 a = 1; 13 | 14 | int32 required_field = 2 [features = { field_presence: LEGACY_REQUIRED }]; 15 | 16 | int32 default_field = 3 [default = 99]; 17 | 18 | DelimitedField delimitedfield = 4 [features = { message_encoding: DELIMITED }]; 19 | 20 | message DelimitedField { 21 | int32 b = 1; 22 | } 23 | } 24 | 25 | enum Closed { 26 | CLOSED_C = 1; 27 | 28 | CLOSED_A = 2; 29 | 30 | reserved CLOSED_E, CLOSED_F; 31 | } 32 | 33 | enum Open { 34 | option features = { enum_type: OPEN }; 35 | 36 | OPEN_B = 0; 37 | 38 | OPEN_C = -1; 39 | 40 | OPEN_A = 2; 41 | } -------------------------------------------------------------------------------- /internal/testprotos/desc_test_editions.protoset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jhump/protoreflect/170fc7af656126cb450190be2f9e43ab305e6f27/internal/testprotos/desc_test_editions.protoset -------------------------------------------------------------------------------- /internal/testprotos/desc_test_field_types.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | 5 | package testprotos; 6 | 7 | message UnaryFields { 8 | optional int32 i = 1; 9 | optional int64 j = 2; 10 | optional sint32 k = 3; 11 | optional sint64 l = 4; 12 | optional uint32 m = 5; 13 | optional uint64 n = 6; 14 | optional fixed32 o = 7; 15 | optional fixed64 p = 8; 16 | optional sfixed32 q = 9; 17 | optional sfixed64 r = 10; 18 | optional float s = 11; 19 | optional double t = 12; 20 | optional bytes u = 13; 21 | optional string v = 14; 22 | optional bool w = 15; 23 | 24 | optional RepeatedFields x = 16; 25 | optional group GroupY = 17 { 26 | optional string ya = 171; 27 | optional int32 yb = 172; 28 | } 29 | optional TestEnum z = 18; 30 | } 31 | 32 | enum TestEnum { 33 | INVALID = 0; 34 | FIRST = 1; 35 | SECOND = 2; 36 | THIRD = 3; 37 | } 38 | 39 | message RepeatedFields { 40 | repeated int32 i = 1; 41 | repeated int64 j = 2; 42 | repeated sint32 k = 3; 43 | repeated sint64 l = 4; 44 | repeated uint32 m = 5; 45 | repeated uint64 n = 6; 46 | repeated fixed32 o = 7; 47 | repeated fixed64 p = 8; 48 | repeated sfixed32 q = 9; 49 | repeated sfixed64 r = 10; 50 | repeated float s = 11; 51 | repeated double t = 12; 52 | repeated bytes u = 13; 53 | repeated string v = 14; 54 | repeated bool w = 15; 55 | 56 | repeated UnaryFields x = 16; 57 | repeated group GroupY = 17 { 58 | optional string ya = 171; 59 | optional int32 yb = 172; 60 | } 61 | repeated TestEnum z = 18; 62 | } 63 | 64 | message RepeatedPackedFields { 65 | repeated int32 i = 1 [packed = true]; 66 | repeated int64 j = 2 [packed = true]; 67 | repeated sint32 k = 3 [packed = true]; 68 | repeated sint64 l = 4 [packed = true]; 69 | repeated uint32 m = 5 [packed = true]; 70 | repeated uint64 n = 6 [packed = true]; 71 | repeated fixed32 o = 7 [packed = true]; 72 | repeated fixed64 p = 8 [packed = true]; 73 | repeated sfixed32 q = 9 [packed = true]; 74 | repeated sfixed64 r = 10 [packed = true]; 75 | repeated float s = 11 [packed = true]; 76 | repeated double t = 12 [packed = true]; 77 | repeated bool u = 13 [packed = true]; 78 | 79 | repeated group GroupY = 14 { 80 | repeated int32 yb = 141 [packed = true]; 81 | } 82 | repeated TestEnum v = 15 [packed = true]; 83 | } 84 | 85 | message MapKeyFields { 86 | map i = 1; 87 | map j = 2; 88 | map k = 3; 89 | map l = 4; 90 | map m = 5; 91 | map n = 6; 92 | map o = 7; 93 | map p = 8; 94 | map q = 9; 95 | map r = 10; 96 | map s = 11; 97 | map t = 12; 98 | } 99 | 100 | message MapValFields { 101 | map i = 1; 102 | map j = 2; 103 | map k = 3; 104 | map l = 4; 105 | map m = 5; 106 | map n = 6; 107 | map o = 7; 108 | map p = 8; 109 | map q = 9; 110 | map r = 10; 111 | map s = 11; 112 | map t = 12; 113 | map u = 13; 114 | map v = 14; 115 | map w = 15; 116 | map x = 16; 117 | map y = 17; 118 | } -------------------------------------------------------------------------------- /internal/testprotos/desc_test_oneof.pb.srcinfo.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gosrcinfo. DO NOT EDIT. 2 | // source: desc_test_oneof.proto 3 | 4 | package testprotos 5 | 6 | import ( 7 | sourceinfo "github.com/jhump/protoreflect/v2/sourceinfo" 8 | ) 9 | 10 | func init() { 11 | srcInfo := []byte{ 12 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x3c, 0xcf, 0x6b, 0x96, 0xeb, 0x20, 13 | 0x0c, 0x03, 0x60, 0x8c, 0x0c, 0x21, 0x0e, 0xe9, 0x43, 0xbd, 0xb7, 0xcf, 0x79, 0x2c, 0x68, 0xf6, 14 | 0xbf, 0x9f, 0x39, 0x9e, 0x62, 0xfe, 0xf1, 0x1d, 0x55, 0x55, 0x6c, 0x95, 0x9a, 0xd2, 0x59, 0xac, 15 | 0x99, 0x74, 0x22, 0x25, 0xfa, 0xab, 0x11, 0x39, 0xfd, 0xd8, 0x6a, 0xb9, 0x6d, 0xef, 0x67, 0x33, 16 | 0xc9, 0x84, 0xa6, 0x8b, 0x99, 0x65, 0x4d, 0xd4, 0xea, 0x25, 0x33, 0x68, 0x12, 0xa2, 0xb6, 0x7f, 17 | 0xd6, 0x4d, 0x35, 0xb5, 0x44, 0x5d, 0xf2, 0x09, 0xd6, 0xad, 0xb8, 0x84, 0x58, 0xda, 0x6e, 0x9b, 18 | 0x67, 0x39, 0x11, 0x4d, 0x5f, 0xef, 0x28, 0xa7, 0xe2, 0x5a, 0x43, 0x42, 0x34, 0xbb, 0x86, 0x40, 19 | 0xb4, 0xc7, 0x73, 0xd4, 0x84, 0x58, 0xf5, 0x63, 0x44, 0x52, 0x5c, 0x16, 0xf2, 0x6c, 0xbb, 0x85, 20 | 0x40, 0xac, 0xcf, 0xd7, 0xa8, 0x65, 0xc2, 0xe6, 0x5a, 0x2e, 0xae, 0x16, 0x12, 0xc2, 0xd6, 0x58, 21 | 0xcb, 0x20, 0x6c, 0xae, 0x81, 0xd8, 0xf4, 0x3e, 0x22, 0x14, 0x57, 0x7c, 0x24, 0x84, 0xd8, 0xec, 22 | 0x12, 0xf2, 0x5f, 0x5e, 0x6f, 0xa3, 0xa6, 0x44, 0xd7, 0xe7, 0x88, 0xb4, 0xb8, 0xa2, 0xa6, 0x42, 23 | 0x74, 0xfb, 0x1f, 0x02, 0xd1, 0xef, 0x8f, 0x51, 0x2b, 0xc4, 0x3e, 0x6f, 0x2b, 0x7f, 0x8a, 0xdb, 24 | 0x8a, 0x10, 0xfb, 0xbc, 0xad, 0x80, 0xd8, 0xe7, 0x6d, 0x95, 0x38, 0xcc, 0xb5, 0x5a, 0x5c, 0xb1, 25 | 0x56, 0x85, 0x38, 0xcc, 0xb5, 0x0a, 0xe2, 0x30, 0xd7, 0x16, 0xe2, 0xa8, 0xdf, 0x23, 0x5a, 0xaa, 26 | 0xeb, 0x14, 0x12, 0xe2, 0x78, 0x8e, 0xbf, 0x5c, 0x40, 0x1c, 0x3f, 0xbf, 0x7e, 0x03, 0x00, 0x00, 27 | 0xff, 0xff, 0x90, 0xf5, 0xb6, 0x26, 0x1d, 0x02, 0x00, 0x00, 28 | } 29 | sourceinfo.Register("desc_test_oneof.proto", srcInfo) 30 | } 31 | -------------------------------------------------------------------------------- /internal/testprotos/desc_test_oneof.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | 5 | package testprotos; 6 | 7 | message OneOfMessage { 8 | oneof value { 9 | bytes binary_value = 1; 10 | string string_value = 2; 11 | bool boolean_value = 3; 12 | int32 int_value = 4; 13 | int64 int64_value = 5; 14 | double double_value = 6; 15 | float float_value = 7; 16 | OneOfMessage msg_value = 8; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /internal/testprotos/desc_test_options.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | 5 | package testprotos; 6 | 7 | import "google/protobuf/descriptor.proto"; 8 | 9 | extend google.protobuf.MessageOptions { 10 | optional bool mfubar = 10101; 11 | } 12 | 13 | extend google.protobuf.FieldOptions { 14 | repeated string ffubar = 10101; 15 | optional bytes ffubarb = 10102; 16 | } 17 | 18 | extend google.protobuf.EnumOptions { 19 | optional int32 efubar = 10101; 20 | optional sint32 efubars = 10102; 21 | optional sfixed32 efubarsf = 10103; 22 | optional uint32 efubaru = 10104; 23 | optional fixed32 efubaruf = 10105; 24 | } 25 | 26 | extend google.protobuf.EnumValueOptions { 27 | optional int64 evfubar = 10101; 28 | optional sint64 evfubars = 10102; 29 | optional sfixed64 evfubarsf = 10103; 30 | optional uint64 evfubaru = 10104; 31 | optional fixed64 evfubaruf = 10105; 32 | } 33 | 34 | extend google.protobuf.ServiceOptions { 35 | optional ReallySimpleMessage sfubar = 10101; 36 | optional ReallySimpleEnum sfubare = 10102; 37 | } 38 | 39 | extend google.protobuf.MethodOptions { 40 | repeated float mtfubar = 10101; 41 | optional double mtfubard = 10102; 42 | } 43 | 44 | // Test message used by custom options 45 | message ReallySimpleMessage { 46 | optional uint64 id = 1; 47 | optional string name = 2; 48 | } 49 | 50 | // Test enum used by custom options 51 | enum ReallySimpleEnum { 52 | VALUE = 1; 53 | } 54 | 55 | extend google.protobuf.ExtensionRangeOptions { 56 | repeated string exfubar = 10101; 57 | optional bytes exfubarb = 10102; 58 | } 59 | 60 | extend google.protobuf.OneofOptions { 61 | repeated string oofubar = 10101; 62 | optional bytes oofubarb = 10102; 63 | } 64 | -------------------------------------------------------------------------------- /internal/testprotos/desc_test_proto3.pb.srcinfo.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gosrcinfo. DO NOT EDIT. 2 | // source: desc_test_proto3.proto 3 | 4 | package testprotos 5 | 6 | import ( 7 | sourceinfo "github.com/jhump/protoreflect/v2/sourceinfo" 8 | ) 9 | 10 | func init() { 11 | srcInfo := []byte{ 12 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x3c, 0xd3, 0xdf, 0x8e, 0xd3, 0x3c, 13 | 0x10, 0x05, 0x70, 0xdb, 0xc7, 0xf6, 0xe7, 0x75, 0xb3, 0x6d, 0x73, 0xd2, 0x3f, 0x5f, 0x93, 0x6e, 14 | 0x9b, 0xa4, 0x15, 0x2b, 0x01, 0xd2, 0x4a, 0x5c, 0x80, 0x40, 0x20, 0x40, 0xac, 0x10, 0xda, 0xe5, 15 | 0x02, 0x71, 0x8f, 0x78, 0xff, 0xb7, 0x40, 0x93, 0x7a, 0x7a, 0x97, 0xdf, 0x9e, 0x99, 0xc9, 0xd8, 16 | 0x9b, 0xe6, 0x48, 0x6f, 0xcc, 0xc9, 0xe6, 0x94, 0x6d, 0x45, 0x18, 0x43, 0x79, 0x4a, 0x84, 0x33, 17 | 0xcf, 0xf9, 0x26, 0xbb, 0x34, 0xbb, 0x3c, 0xa6, 0x6c, 0x1d, 0xe1, 0x4d, 0x23, 0x7f, 0x84, 0x21, 18 | 0xa2, 0x69, 0xa7, 0x47, 0x4b, 0xfc, 0x67, 0x86, 0x9c, 0xb3, 0x0b, 0x86, 0xfe, 0xc6, 0xcc, 0x6d, 19 | 0xce, 0x19, 0xc1, 0x58, 0xe2, 0x26, 0x2c, 0xf2, 0x2c, 0xfb, 0x60, 0x9c, 0x21, 0x72, 0x5a, 0xe5, 20 | 0x2a, 0x07, 0x81, 0x15, 0x2d, 0x54, 0x8e, 0xc8, 0x6c, 0x4a, 0xa1, 0x25, 0x66, 0xe9, 0xff, 0x12, 21 | 0xd9, 0x49, 0x54, 0x39, 0x62, 0xb6, 0xde, 0x96, 0x42, 0x47, 0x54, 0xa9, 0x29, 0x91, 0xb4, 0x55, 22 | 0x69, 0xae, 0x92, 0xac, 0x66, 0x29, 0x04, 0x71, 0x7b, 0x2d, 0x94, 0x6d, 0x6f, 0xaf, 0x85, 0x70, 23 | 0xc4, 0x6d, 0x4d, 0xd9, 0xdd, 0x1b, 0xfa, 0xa5, 0xd9, 0x4e, 0xbb, 0x7b, 0x59, 0x70, 0x99, 0xa6, 24 | 0x95, 0xfc, 0xb4, 0x7b, 0x9d, 0xce, 0xd2, 0x22, 0xf0, 0xa2, 0xa5, 0x2a, 0x12, 0x75, 0xdd, 0xa9, 25 | 0x2c, 0x51, 0xef, 0x8f, 0x2a, 0x10, 0xf5, 0x78, 0x2a, 0x43, 0x2c, 0xc1, 0xb4, 0x2d, 0x91, 0x0d, 26 | 0xa2, 0xb9, 0x4a, 0xb2, 0x05, 0x55, 0x20, 0xb8, 0xde, 0x94, 0x36, 0x47, 0x34, 0x69, 0x5f, 0x22, 27 | 0x17, 0x45, 0x8d, 0xca, 0x12, 0xcd, 0x4a, 0x47, 0xca, 0x31, 0x9b, 0xb6, 0x2b, 0x6d, 0x20, 0x56, 28 | 0xe9, 0x6b, 0x89, 0x10, 0x45, 0x6f, 0x55, 0x96, 0x58, 0xbd, 0xfb, 0xa8, 0x92, 0xca, 0xcf, 0x5f, 29 | 0x4a, 0x9b, 0x27, 0xd6, 0xd7, 0x93, 0xfa, 0x28, 0xda, 0xa9, 0x2c, 0xb1, 0x6e, 0xf5, 0x6c, 0x1e, 30 | 0xc4, 0xfa, 0x7a, 0xb6, 0x40, 0x6c, 0xd2, 0xeb, 0x12, 0x85, 0x28, 0xea, 0x55, 0x96, 0xd8, 0x0c, 31 | 0xf7, 0x2a, 0x10, 0x9b, 0x97, 0xaf, 0xa6, 0xfb, 0xb6, 0xf4, 0x3b, 0xb3, 0xbf, 0xdc, 0xb7, 0xdc, 32 | 0xc0, 0x2e, 0xad, 0xa6, 0x71, 0x56, 0xee, 0xbb, 0x4d, 0xa7, 0xa9, 0xc5, 0x4e, 0x37, 0xdc, 0xa6, 33 | 0x56, 0x65, 0x89, 0xb6, 0x3b, 0xa8, 0x40, 0xb4, 0xc3, 0x58, 0xda, 0x2c, 0xd1, 0x25, 0x8d, 0xac, 34 | 0x17, 0x2d, 0x55, 0x81, 0xe8, 0xea, 0x8d, 0x4a, 0x2a, 0xb7, 0x3b, 0x15, 0x88, 0x6e, 0x7f, 0x27, 35 | 0x3b, 0x45, 0x43, 0x7f, 0x90, 0x9f, 0x42, 0xce, 0x88, 0xf2, 0xaa, 0xc3, 0xe5, 0x1b, 0x88, 0xd3, 36 | 0x37, 0x70, 0x4c, 0x3f, 0xa5, 0x25, 0x5e, 0xfe, 0xcf, 0xc7, 0x6a, 0xab, 0x72, 0xc4, 0x71, 0x77, 37 | 0x56, 0x81, 0x38, 0x3e, 0x3c, 0x95, 0x36, 0x4b, 0xf4, 0xe9, 0x47, 0x89, 0xe4, 0xbd, 0x7d, 0xd5, 38 | 0xa9, 0x02, 0xd1, 0xdf, 0x9d, 0x54, 0x8e, 0xe8, 0xcf, 0x0f, 0x2a, 0x10, 0xfd, 0x87, 0xef, 0x65, 39 | 0x88, 0x23, 0x86, 0xf4, 0xb7, 0x44, 0x32, 0x72, 0xa8, 0xf6, 0x2a, 0xc9, 0x0e, 0xef, 0x55, 0x91, 40 | 0x18, 0x1e, 0x9f, 0x54, 0x20, 0x86, 0xe7, 0x3f, 0x65, 0x08, 0x88, 0x31, 0xfd, 0x2e, 0x91, 0x7c, 41 | 0x03, 0x63, 0x75, 0x50, 0x05, 0x62, 0xec, 0x5f, 0xa8, 0x1c, 0x31, 0xde, 0xbf, 0x51, 0x45, 0x62, 42 | 0xfc, 0xf4, 0x4d, 0x25, 0x53, 0x1e, 0x7f, 0xfd, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x4c, 0xf0, 0x36, 43 | 0x6d, 0x33, 0x04, 0x00, 0x00, 44 | } 45 | sourceinfo.Register("desc_test_proto3.proto", srcInfo) 46 | } 47 | -------------------------------------------------------------------------------- /internal/testprotos/desc_test_proto3.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | 5 | package testprotos; 6 | 7 | import "desc_test1.proto"; 8 | import "pkg/desc_test_pkg.proto"; 9 | 10 | enum Proto3Enum { 11 | UNKNOWN = 0; 12 | VALUE_NEG1 = -1; 13 | VALUE1 = 1; 14 | VALUE2 = 2; 15 | } 16 | 17 | message TestRequest { 18 | repeated Proto3Enum foo = 1; 19 | string bar = 2; 20 | TestMessage baz = 3; 21 | TestMessage.NestedMessage.AnotherNestedMessage snafu = 4; 22 | map flags = 5; 23 | map others = 6; 24 | } 25 | 26 | message TestResponse { 27 | AnotherTestMessage atm = 1; 28 | repeated int32 vs = 2; 29 | } 30 | 31 | service TestService { 32 | rpc DoSomething (TestRequest) returns (jhump.protoreflect.desc.Bar); 33 | rpc DoSomethingElse (stream TestMessage) returns (TestResponse); 34 | rpc DoSomethingAgain (jhump.protoreflect.desc.Bar) returns (stream AnotherTestMessage); 35 | rpc DoSomethingForever (stream TestRequest) returns (stream TestResponse); 36 | } 37 | -------------------------------------------------------------------------------- /internal/testprotos/desc_test_proto3.protoset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jhump/protoreflect/170fc7af656126cb450190be2f9e43ab305e6f27/internal/testprotos/desc_test_proto3.protoset -------------------------------------------------------------------------------- /internal/testprotos/desc_test_value.pb.srcinfo.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gosrcinfo. DO NOT EDIT. 2 | // source: desc_test_value.proto 3 | 4 | package testprotos 5 | 6 | import ( 7 | sourceinfo "github.com/jhump/protoreflect/v2/sourceinfo" 8 | ) 9 | 10 | func init() { 11 | srcInfo := []byte{ 12 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x34, 0xcb, 0x41, 0xaa, 0x02, 0x41, 13 | 0x10, 0x83, 0xe1, 0x74, 0xa5, 0x66, 0x5e, 0x75, 0x7a, 0x56, 0x99, 0xd5, 0x73, 0x21, 0xa8, 0xe0, 14 | 0x65, 0xbc, 0xff, 0x7d, 0xa4, 0x90, 0xd9, 0xe5, 0xfb, 0x21, 0xda, 0x9d, 0xc0, 0x1a, 0x2a, 0x8d, 15 | 0xc3, 0x04, 0xac, 0xa9, 0x20, 0xcc, 0xc0, 0xbb, 0x63, 0x99, 0x1b, 0x3e, 0x1d, 0x6b, 0xfd, 0x66, 16 | 0x69, 0x84, 0xf9, 0x87, 0x53, 0x52, 0x24, 0x9c, 0xb3, 0xff, 0x12, 0x13, 0xc3, 0x9c, 0x75, 0x6a, 17 | 0x29, 0x13, 0x01, 0x53, 0xf9, 0xd2, 0xa1, 0xad, 0xb1, 0xb7, 0xfe, 0x2f, 0x0d, 0x53, 0xb7, 0xfb, 18 | 0x25, 0x9a, 0x7a, 0x3c, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x13, 0x93, 0x7a, 0xe4, 0x8b, 0x00, 19 | 0x00, 0x00, 20 | } 21 | sourceinfo.Register("desc_test_value.proto", srcInfo) 22 | } 23 | -------------------------------------------------------------------------------- /internal/testprotos/desc_test_value.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/struct.proto"; 4 | 5 | 6 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 7 | 8 | package testprotos; 9 | 10 | message SimpleValue { 11 | google.protobuf.Value list = 1; 12 | } 13 | -------------------------------------------------------------------------------- /internal/testprotos/desc_test_wellknowntypes.pb.srcinfo.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gosrcinfo. DO NOT EDIT. 2 | // source: desc_test_wellknowntypes.proto 3 | 4 | package testprotos 5 | 6 | import ( 7 | sourceinfo "github.com/jhump/protoreflect/v2/sourceinfo" 8 | ) 9 | 10 | func init() { 11 | srcInfo := []byte{ 12 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x3c, 0x92, 0xeb, 0x6e, 0xdb, 0x30, 13 | 0x0c, 0x85, 0x45, 0x1f, 0x45, 0x96, 0x69, 0xa7, 0x48, 0x4e, 0xae, 0x30, 0x32, 0x60, 0x4d, 0xba, 14 | 0xe6, 0xd6, 0x75, 0xdd, 0x73, 0xec, 0xfd, 0xdf, 0x67, 0xa0, 0x6b, 0xf2, 0x1f, 0x3f, 0xd3, 0x1f, 15 | 0x0f, 0x44, 0x49, 0x0b, 0x73, 0x4a, 0x3f, 0x44, 0xab, 0xca, 0x40, 0xa4, 0x44, 0xab, 0x2a, 0xd1, 16 | 0xa4, 0x7f, 0xda, 0x69, 0x53, 0xfb, 0xef, 0xb2, 0xaa, 0x34, 0x44, 0x4e, 0x1b, 0xfb, 0x88, 0x44, 17 | 0x94, 0x74, 0x99, 0x4a, 0x21, 0xda, 0x74, 0x9b, 0xca, 0x86, 0xa8, 0xe9, 0x3e, 0x95, 0x20, 0xba, 18 | 0xf4, 0x3e, 0x95, 0x99, 0xd0, 0x74, 0x53, 0xd5, 0x26, 0x27, 0xe6, 0xc1, 0xb2, 0x54, 0x91, 0x93, 19 | 0x10, 0x43, 0x1d, 0xb5, 0xd7, 0x9c, 0x53, 0x93, 0x88, 0x65, 0xfd, 0xab, 0x83, 0x2e, 0x0c, 0x8a, 20 | 0xd1, 0xab, 0x93, 0x10, 0xcb, 0xf3, 0x87, 0x13, 0x88, 0xe5, 0x9f, 0xaf, 0x59, 0x13, 0xe2, 0xa5, 21 | 0xfe, 0x9e, 0x5b, 0x52, 0x8c, 0x7e, 0x3a, 0x59, 0xef, 0xf5, 0xe6, 0x04, 0xe2, 0xe5, 0xf9, 0x31, 22 | 0x6b, 0x0d, 0xb1, 0xaa, 0x3e, 0xb1, 0x29, 0x46, 0x17, 0x27, 0x21, 0x56, 0x6f, 0x57, 0x27, 0x10, 23 | 0xab, 0xc7, 0x73, 0xd6, 0x40, 0xac, 0xeb, 0x73, 0x6e, 0xa1, 0x18, 0x9d, 0x9d, 0x84, 0x58, 0x5f, 24 | 0xde, 0x9d, 0xec, 0xcf, 0xfb, 0x63, 0xd6, 0x32, 0xc1, 0x7a, 0x9f, 0x5b, 0xb9, 0x18, 0xf9, 0xd9, 25 | 0xb2, 0x10, 0x3c, 0xbf, 0x39, 0x81, 0xe0, 0xf5, 0x36, 0x6b, 0x0b, 0x62, 0x13, 0x69, 0x8b, 0x62, 26 | 0xe4, 0x69, 0x0b, 0x21, 0x36, 0x91, 0xb6, 0x00, 0xb1, 0x89, 0xb4, 0x42, 0x6c, 0x43, 0x2b, 0x13, 27 | 0xb9, 0x56, 0x84, 0xd8, 0x86, 0x56, 0x40, 0x6c, 0x43, 0x6b, 0x89, 0x5d, 0xac, 0xa4, 0x2d, 0x46, 28 | 0xbe, 0x92, 0x56, 0x88, 0x5d, 0xac, 0xa4, 0x05, 0xb1, 0x8b, 0x95, 0x54, 0x62, 0x1f, 0x5a, 0x2d, 29 | 0x46, 0xae, 0x55, 0x21, 0xf6, 0xa1, 0x55, 0x10, 0xfb, 0xd0, 0x3a, 0xe2, 0x10, 0xf7, 0xd6, 0x15, 30 | 0x23, 0xd7, 0x3a, 0x21, 0x0e, 0xa1, 0x75, 0x20, 0x0e, 0x0f, 0xbf, 0x37, 0x25, 0x8e, 0x91, 0xa6, 31 | 0xc5, 0xc8, 0xcf, 0xa6, 0x42, 0x1c, 0xe3, 0x6c, 0x0a, 0xe2, 0x78, 0xf7, 0xb4, 0x9e, 0x18, 0xe3, 32 | 0x71, 0xf5, 0xd9, 0x68, 0xe5, 0x54, 0x88, 0x71, 0xed, 0x5a, 0x2f, 0xc4, 0x78, 0xf5, 0xe5, 0xf5, 33 | 0x20, 0xc6, 0x4f, 0x7f, 0x6a, 0x03, 0x71, 0x8a, 0x21, 0x43, 0x36, 0xf2, 0x21, 0x43, 0x21, 0x4e, 34 | 0x6b, 0xbf, 0xc5, 0x41, 0x88, 0xd3, 0x2f, 0x1f, 0x32, 0x80, 0x38, 0x7d, 0x7e, 0xfd, 0x0f, 0x00, 35 | 0x00, 0xff, 0xff, 0x8f, 0x9a, 0x26, 0x74, 0x67, 0x03, 0x00, 0x00, 36 | } 37 | sourceinfo.Register("desc_test_wellknowntypes.proto", srcInfo) 38 | } 39 | -------------------------------------------------------------------------------- /internal/testprotos/desc_test_wellknowntypes.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | 5 | package testprotos; 6 | 7 | import "google/protobuf/any.proto"; 8 | import "google/protobuf/duration.proto"; 9 | import "google/protobuf/timestamp.proto"; 10 | import "google/protobuf/struct.proto"; 11 | import "google/protobuf/wrappers.proto"; 12 | 13 | message TestWellKnownTypes { 14 | google.protobuf.Timestamp start_time = 1; 15 | google.protobuf.Duration elapsed = 2; 16 | 17 | google.protobuf.DoubleValue dbl = 3; 18 | google.protobuf.FloatValue flt = 4; 19 | google.protobuf.BoolValue bl = 5; 20 | google.protobuf.Int32Value i32 = 6; 21 | google.protobuf.Int64Value i64 = 7; 22 | google.protobuf.UInt32Value u32 = 8; 23 | google.protobuf.UInt64Value u64 = 9; 24 | google.protobuf.StringValue str = 10; 25 | google.protobuf.BytesValue byt = 11; 26 | 27 | repeated google.protobuf.Value json = 12; 28 | 29 | repeated google.protobuf.Any extras = 13; 30 | } -------------------------------------------------------------------------------- /internal/testprotos/descriptor.protoset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jhump/protoreflect/170fc7af656126cb450190be2f9e43ab305e6f27/internal/testprotos/descriptor.protoset -------------------------------------------------------------------------------- /internal/testprotos/duration.protoset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jhump/protoreflect/170fc7af656126cb450190be2f9e43ab305e6f27/internal/testprotos/duration.protoset -------------------------------------------------------------------------------- /internal/testprotos/gen.go: -------------------------------------------------------------------------------- 1 | package testprotos 2 | 3 | //go:generate ./make_protos.sh 4 | -------------------------------------------------------------------------------- /internal/testprotos/grpc/dummy.pb.srcinfo.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gosrcinfo. DO NOT EDIT. 2 | // source: grpc/dummy.proto 3 | 4 | package grpc 5 | 6 | import ( 7 | sourceinfo "github.com/jhump/protoreflect/v2/sourceinfo" 8 | ) 9 | 10 | func init() { 11 | srcInfo := []byte{ 12 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x6c, 0xd2, 0x5f, 0x6f, 0xd3, 0x3c, 13 | 0x14, 0x06, 0x70, 0xdb, 0xc7, 0xf1, 0xdb, 0xba, 0x5d, 0xbb, 0x9e, 0xa6, 0x5b, 0xdf, 0x36, 0xc9, 14 | 0xbc, 0x09, 0x90, 0x40, 0xac, 0x80, 0x86, 0x10, 0x7f, 0xa4, 0x21, 0x18, 0x13, 0x37, 0x08, 0x4d, 15 | 0x30, 0x09, 0x71, 0x35, 0x45, 0xa9, 0x57, 0xc2, 0x42, 0x53, 0x25, 0xd9, 0x60, 0x5f, 0x97, 0x2f, 16 | 0xc0, 0x57, 0x40, 0x6e, 0x7d, 0xee, 0xb8, 0xaa, 0x7f, 0x7d, 0x7a, 0x4e, 0xaa, 0x27, 0xd6, 0x0a, 17 | 0x25, 0x63, 0x7b, 0x5c, 0xb7, 0x34, 0xef, 0x22, 0x30, 0x86, 0xee, 0xd4, 0x42, 0x10, 0xec, 0x4c, 18 | 0xb7, 0xb5, 0x68, 0x75, 0x36, 0xc7, 0x96, 0xe6, 0x02, 0x41, 0xb2, 0xa1, 0xfb, 0x12, 0x18, 0x82, 19 | 0x62, 0x93, 0xf5, 0x91, 0x23, 0xfc, 0xc7, 0xf6, 0xb5, 0xd6, 0x42, 0x32, 0x94, 0x6d, 0xb6, 0xcd, 20 | 0xb5, 0xd6, 0x20, 0x19, 0x47, 0x68, 0xb7, 0x42, 0xdd, 0xd1, 0x52, 0x32, 0xc1, 0x10, 0xb4, 0xf8, 21 | 0x5f, 0x77, 0x75, 0xe0, 0x20, 0x9d, 0x34, 0x29, 0x40, 0xd0, 0x9d, 0x6d, 0x12, 0x47, 0xd0, 0x83, 22 | 0x90, 0x04, 0x08, 0x7a, 0x77, 0xec, 0x97, 0x70, 0x84, 0x8e, 0x18, 0xf8, 0x88, 0x07, 0x4e, 0x2d, 23 | 0x92, 0xcb, 0xda, 0x5d, 0x12, 0x20, 0x74, 0xfa, 0xdb, 0x7e, 0x4c, 0x20, 0x74, 0xc5, 0x8e, 0x8f, 24 | 0x84, 0x72, 0xda, 0x22, 0x71, 0x84, 0x6e, 0x8f, 0x56, 0x0a, 0x40, 0xe8, 0x86, 0x23, 0x3f, 0x06, 25 | 0x08, 0x5b, 0xe2, 0x95, 0x8f, 0x40, 0x39, 0x3d, 0x26, 0x71, 0x84, 0xad, 0x27, 0xcf, 0x48, 0xee, 26 | 0x97, 0x2f, 0x5e, 0xfa, 0x31, 0x89, 0xd0, 0x13, 0x89, 0x8f, 0xa4, 0x72, 0x1a, 0x92, 0x38, 0x42, 27 | 0x2f, 0xa4, 0x16, 0x24, 0x20, 0xf4, 0xa2, 0xd8, 0x8f, 0x05, 0x08, 0x7d, 0x71, 0xcf, 0x47, 0x81, 28 | 0x72, 0x9a, 0x90, 0x38, 0x42, 0x7f, 0xba, 0x4f, 0x02, 0x84, 0xfe, 0x9d, 0xbb, 0xeb, 0xbe, 0x39, 29 | 0x4a, 0x64, 0xa3, 0x4d, 0xdf, 0xae, 0x01, 0x6c, 0x6d, 0xfe, 0x3c, 0x77, 0x7d, 0x0f, 0x45, 0xbc, 30 | 0x1e, 0xe1, 0x82, 0x29, 0xa7, 0x90, 0xc4, 0x11, 0x86, 0xa3, 0x31, 0x09, 0x10, 0x86, 0xd3, 0xc8, 31 | 0x8f, 0x71, 0x84, 0x50, 0x50, 0xc4, 0xa5, 0x93, 0x26, 0x05, 0x08, 0xa1, 0x7f, 0x4d, 0x7c, 0xdd, 32 | 0x77, 0x38, 0x18, 0x92, 0x00, 0x21, 0xdc, 0xd9, 0xd5, 0x7f, 0xb8, 0x16, 0x8a, 0xa1, 0x9c, 0xb0, 33 | 0x3d, 0x3e, 0xf9, 0xcd, 0xcd, 0xdb, 0xb4, 0xce, 0xb3, 0xb4, 0x28, 0x6e, 0x4d, 0x51, 0x96, 0x57, 34 | 0xb5, 0xf9, 0x7e, 0x5d, 0x37, 0xa6, 0xc8, 0xaf, 0xac, 0x39, 0xb7, 0x75, 0xf3, 0xd9, 0x56, 0x37, 35 | 0x79, 0x66, 0x4d, 0xbe, 0x34, 0x07, 0xb3, 0xd9, 0xa3, 0xb9, 0xad, 0xb3, 0x8b, 0xc6, 0xd6, 0xcd, 36 | 0xc5, 0xaa, 0x2a, 0x9b, 0xf2, 0x68, 0xb6, 0xfe, 0x38, 0x98, 0x99, 0xd3, 0x5f, 0x99, 0x5d, 0x35, 37 | 0xe6, 0xa7, 0x35, 0xe5, 0xb2, 0xb8, 0xd5, 0x66, 0x61, 0x97, 0xb6, 0x4a, 0x1b, 0x6b, 0x16, 0x9f, 38 | 0xce, 0x4e, 0x0e, 0x2b, 0x5b, 0xa4, 0x8d, 0x9d, 0x9b, 0xac, 0x9c, 0x5b, 0x73, 0x59, 0x56, 0xa6, 39 | 0xf9, 0x96, 0xd7, 0x66, 0x95, 0x66, 0x57, 0xe9, 0xc2, 0x3e, 0x34, 0xcb, 0xb2, 0xf1, 0x0f, 0x38, 40 | 0x98, 0x99, 0x73, 0x17, 0x65, 0xe5, 0xea, 0xd6, 0x14, 0xb6, 0xa9, 0xcd, 0x75, 0x6d, 0xdc, 0xf3, 41 | 0x4c, 0x65, 0x2f, 0x0b, 0x9b, 0x35, 0x79, 0xb9, 0xd4, 0xa6, 0xbc, 0xb1, 0x95, 0xa9, 0xd3, 0x7c, 42 | 0xfe, 0xaf, 0xed, 0x55, 0xf9, 0xc3, 0x2c, 0xaa, 0x55, 0xe6, 0x07, 0x66, 0xda, 0x35, 0xaf, 0x5c, 43 | 0xa1, 0x93, 0xcd, 0x4d, 0x57, 0xeb, 0x9b, 0x3e, 0x15, 0xef, 0x5d, 0x31, 0x6a, 0x73, 0x9b, 0xa7, 44 | 0x6a, 0x40, 0x12, 0x08, 0xd3, 0xe1, 0x1e, 0x09, 0x10, 0xa6, 0x0f, 0x4e, 0xfd, 0x18, 0x47, 0x88, 45 | 0xc4, 0x89, 0x8f, 0x5c, 0xbb, 0x91, 0x1a, 0x91, 0x02, 0x84, 0x68, 0x37, 0x26, 0x09, 0x84, 0x28, 46 | 0xb9, 0x4f, 0x02, 0x84, 0xe8, 0xe9, 0x1b, 0xbf, 0x44, 0x20, 0xc4, 0xe2, 0xab, 0x8f, 0xdc, 0xca, 47 | 0x58, 0xed, 0x90, 0x5c, 0x36, 0x3e, 0x22, 0x29, 0x84, 0xf8, 0xf8, 0x1d, 0x09, 0x10, 0xe2, 0xd3, 48 | 0x2f, 0x7e, 0x09, 0x20, 0x24, 0xe2, 0xa3, 0x8f, 0xdc, 0x4d, 0x4f, 0xd4, 0x98, 0x14, 0x20, 0x24, 49 | 0x13, 0x43, 0x12, 0x08, 0xc9, 0xfe, 0x21, 0x49, 0x21, 0x24, 0xcf, 0x8f, 0x49, 0x6e, 0xcb, 0xeb, 50 | 0x0f, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x6a, 0x64, 0x91, 0x1e, 0x5d, 0x04, 0x00, 0x00, 51 | } 52 | sourceinfo.Register("grpc/dummy.proto", srcInfo) 53 | } 54 | -------------------------------------------------------------------------------- /internal/testprotos/grpc/dummy.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos/grpc"; 4 | 5 | package testprotos; 6 | 7 | import "desc_test1.proto"; 8 | import "pkg/desc_test_pkg.proto"; 9 | 10 | message DummyRequest { 11 | repeated bytes foo = 1; 12 | string bar = 2; 13 | TestMessage baz = 3; 14 | TestMessage.NestedMessage.AnotherNestedMessage snafu = 4; 15 | map flags = 5; 16 | map others = 6; 17 | } 18 | 19 | message DummyResponse { 20 | AnotherTestMessage atm = 1; 21 | repeated int32 vs = 2; 22 | } 23 | 24 | // Basically looks just like TestService in "../desc_test_proto3.proto". Except we only 25 | // generate gRPC-related code for this package, not in "..". This copy lets us test reflection 26 | // over said gRPC-related code from grpcreflect. 27 | service DummyService { 28 | rpc DoSomething (DummyRequest) returns (jhump.protoreflect.desc.Bar); 29 | rpc DoSomethingElse (stream TestMessage) returns (DummyResponse); 30 | rpc DoSomethingAgain (jhump.protoreflect.desc.Bar) returns (stream AnotherTestMessage); 31 | rpc DoSomethingForever (stream DummyRequest) returns (stream DummyResponse); 32 | } 33 | -------------------------------------------------------------------------------- /internal/testprotos/make_protos.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | cd $(dirname $0) 6 | 7 | PROTOC_VERSION="28.1" 8 | PROTOC_OS="$(uname -s)" 9 | PROTOC_ARCH="$(uname -m)" 10 | case "${PROTOC_OS}" in 11 | Darwin) PROTOC_OS="osx" ;; 12 | Linux) PROTOC_OS="linux" ;; 13 | *) 14 | echo "Invalid value for uname -s: ${PROTOC_OS}" >&2 15 | exit 1 16 | esac 17 | 18 | # This is for macs with M1 chips. Precompiled binaries for osx/amd64 are not available for download, so for that case 19 | # we download the x86_64 version instead. This will work as long as rosetta2 is installed. 20 | if [ "$PROTOC_OS" = "osx" ] && [ "$PROTOC_ARCH" = "arm64" ]; then 21 | PROTOC_ARCH="x86_64" 22 | fi 23 | 24 | PROTOC="${PWD}/protoc/bin/protoc" 25 | 26 | if [[ "$(${PROTOC} --version 2>/dev/null)" != "libprotoc ${PROTOC_VERSION}" ]]; then 27 | rm -rf ./protoc 28 | mkdir -p protoc 29 | curl -L "https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${PROTOC_OS}-${PROTOC_ARCH}.zip" > protoc/protoc.zip 30 | cd ./protoc && unzip protoc.zip && cd .. 31 | fi 32 | 33 | go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.34.2 34 | go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1 35 | go install github.com/jhump/protoreflect/v2/sourceinfo/cmd/protoc-gen-gosrcinfo 36 | 37 | # Output directory will effectively be GOPATH/src. 38 | outdir="." 39 | ${PROTOC} "--go_out=paths=source_relative:$outdir" "--gosrcinfo_out=paths=source_relative,debug:$outdir" -I. *.proto 40 | ${PROTOC} "--go_out=paths=source_relative:$outdir" "--gosrcinfo_out=paths=source_relative,debug:$outdir" -I. nopkg/*.proto 41 | ${PROTOC} "--go_out=paths=source_relative:$outdir" "--gosrcinfo_out=paths=source_relative,debug:$outdir" -I. pkg/*.proto 42 | ${PROTOC} "--go_out=paths=source_relative:$outdir" "--gosrcinfo_out=paths=source_relative,debug:$outdir" -I. proto3_optional/desc_test_proto3_optional.proto 43 | ${PROTOC} "--go_out=paths=source_relative:$outdir" "--go-grpc_out=paths=source_relative:$outdir" "--gosrcinfo_out=paths=source_relative,debug:$outdir" -I. grpc/*.proto 44 | 45 | # And make descriptor set (with source info) for several files 46 | ${PROTOC} --descriptor_set_out=./desc_test1.protoset --include_source_info --include_imports -I. desc_test1.proto 47 | ${PROTOC} --descriptor_set_out=./desc_test_comments.protoset --include_source_info --include_imports -I. desc_test_comments.proto 48 | ${PROTOC} --descriptor_set_out=./desc_test_complex.protoset -I. desc_test_complex.proto 49 | ${PROTOC} --descriptor_set_out=./desc_test_complex_source_info.protoset --include_source_info --include_imports -I. desc_test_complex.proto 50 | ${PROTOC} --descriptor_set_out=./desc_test_editions.protoset --include_source_info --include_imports -I. desc_test_editions.proto 51 | ${PROTOC} --descriptor_set_out=./desc_test_proto3.protoset --include_source_info --include_imports -I. desc_test_proto3.proto 52 | ${PROTOC} --descriptor_set_out=./descriptor.protoset --include_source_info --include_imports -I./protoc/include/ google/protobuf/descriptor.proto 53 | ${PROTOC} --descriptor_set_out=./duration.protoset -I./protoc/include/ google/protobuf/duration.proto 54 | ${PROTOC} --descriptor_set_out=./proto3_optional/desc_test_proto3_optional.protoset --include_source_info --include_imports -I. proto3_optional/desc_test_proto3_optional.proto 55 | 56 | -------------------------------------------------------------------------------- /internal/testprotos/nopkg/desc_test_nopkg.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.34.2 4 | // protoc v5.28.1 5 | // source: nopkg/desc_test_nopkg.proto 6 | 7 | package nopkg 8 | 9 | import ( 10 | reflect "reflect" 11 | 12 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 13 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 14 | ) 15 | 16 | const ( 17 | // Verify that this generated code is sufficiently up-to-date. 18 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 19 | // Verify that runtime/protoimpl is sufficiently up-to-date. 20 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 21 | ) 22 | 23 | var File_nopkg_desc_test_nopkg_proto protoreflect.FileDescriptor 24 | 25 | var file_nopkg_desc_test_nopkg_proto_rawDesc = []byte{ 26 | 0x0a, 0x1b, 0x6e, 0x6f, 0x70, 0x6b, 0x67, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x5f, 0x74, 0x65, 0x73, 27 | 0x74, 0x5f, 0x6e, 0x6f, 0x70, 0x6b, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x6e, 28 | 0x6f, 0x70, 0x6b, 0x67, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x6e, 29 | 0x6f, 0x70, 0x6b, 0x67, 0x5f, 0x6e, 0x65, 0x77, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x42, 0x42, 30 | 0x5a, 0x40, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6a, 0x68, 0x75, 31 | 0x6d, 0x70, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x72, 0x65, 0x66, 0x6c, 0x65, 0x63, 0x74, 0x2f, 32 | 0x76, 0x32, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 33 | 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x6e, 0x6f, 0x70, 0x6b, 0x67, 0x3b, 0x6e, 0x6f, 0x70, 34 | 0x6b, 0x67, 0x50, 0x00, 35 | } 36 | 37 | var file_nopkg_desc_test_nopkg_proto_goTypes = []any{} 38 | var file_nopkg_desc_test_nopkg_proto_depIdxs = []int32{ 39 | 0, // [0:0] is the sub-list for method output_type 40 | 0, // [0:0] is the sub-list for method input_type 41 | 0, // [0:0] is the sub-list for extension type_name 42 | 0, // [0:0] is the sub-list for extension extendee 43 | 0, // [0:0] is the sub-list for field type_name 44 | } 45 | 46 | func init() { file_nopkg_desc_test_nopkg_proto_init() } 47 | func file_nopkg_desc_test_nopkg_proto_init() { 48 | if File_nopkg_desc_test_nopkg_proto != nil { 49 | return 50 | } 51 | file_nopkg_desc_test_nopkg_new_proto_init() 52 | type x struct{} 53 | out := protoimpl.TypeBuilder{ 54 | File: protoimpl.DescBuilder{ 55 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 56 | RawDescriptor: file_nopkg_desc_test_nopkg_proto_rawDesc, 57 | NumEnums: 0, 58 | NumMessages: 0, 59 | NumExtensions: 0, 60 | NumServices: 0, 61 | }, 62 | GoTypes: file_nopkg_desc_test_nopkg_proto_goTypes, 63 | DependencyIndexes: file_nopkg_desc_test_nopkg_proto_depIdxs, 64 | }.Build() 65 | File_nopkg_desc_test_nopkg_proto = out.File 66 | file_nopkg_desc_test_nopkg_proto_rawDesc = nil 67 | file_nopkg_desc_test_nopkg_proto_goTypes = nil 68 | file_nopkg_desc_test_nopkg_proto_depIdxs = nil 69 | } 70 | -------------------------------------------------------------------------------- /internal/testprotos/nopkg/desc_test_nopkg.pb.srcinfo.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gosrcinfo. DO NOT EDIT. 2 | // source: nopkg/desc_test_nopkg.proto 3 | 4 | package nopkg 5 | 6 | import ( 7 | sourceinfo "github.com/jhump/protoreflect/v2/sourceinfo" 8 | ) 9 | 10 | func init() { 11 | srcInfo := []byte{ 12 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x3c, 0xc6, 0xb1, 0x15, 0x80, 0x40, 13 | 0x08, 0x03, 0xd0, 0x48, 0x78, 0x8a, 0x51, 0x9b, 0x4c, 0xc2, 0x36, 0xee, 0xbf, 0xc9, 0x3d, 0x9a, 14 | 0xeb, 0xbe, 0x4e, 0x27, 0x90, 0xad, 0xd2, 0xf1, 0x9a, 0x80, 0x47, 0x65, 0x06, 0x7e, 0xdd, 0x8a, 15 | 0x7a, 0x36, 0x09, 0x33, 0xd1, 0x43, 0x0d, 0xaf, 0x6f, 0x05, 0x00, 0x00, 0xff, 0xff, 0x35, 0x47, 16 | 0xf3, 0x8d, 0x3d, 0x00, 0x00, 0x00, 17 | } 18 | sourceinfo.Register("nopkg/desc_test_nopkg.proto", srcInfo) 19 | } 20 | -------------------------------------------------------------------------------- /internal/testprotos/nopkg/desc_test_nopkg.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos/nopkg;nopkg"; 4 | 5 | import public "nopkg/desc_test_nopkg_new.proto"; -------------------------------------------------------------------------------- /internal/testprotos/nopkg/desc_test_nopkg_new.pb.srcinfo.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gosrcinfo. DO NOT EDIT. 2 | // source: nopkg/desc_test_nopkg_new.proto 3 | 4 | package nopkg 5 | 6 | import ( 7 | sourceinfo "github.com/jhump/protoreflect/v2/sourceinfo" 8 | ) 9 | 10 | func init() { 11 | srcInfo := []byte{ 12 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x3c, 0xd4, 0xed, 0x72, 0xa3, 0x30, 13 | 0x0c, 0x85, 0x61, 0xc4, 0x91, 0xc0, 0xd8, 0x86, 0xc0, 0x61, 0x92, 0xb6, 0xf9, 0x6a, 0xf7, 0xaa, 14 | 0xf6, 0xfe, 0xef, 0x64, 0xc7, 0x5b, 0x4b, 0xff, 0x78, 0xc7, 0xe4, 0x19, 0x61, 0x43, 0xf2, 0x44, 15 | 0x1d, 0x86, 0x9b, 0xe4, 0x94, 0xa5, 0x12, 0xc3, 0xc0, 0x76, 0x95, 0x88, 0x71, 0xf8, 0x9b, 0x97, 16 | 0x3c, 0xa6, 0xf2, 0x7b, 0x99, 0xf3, 0xa8, 0x03, 0x55, 0xdb, 0xad, 0x39, 0x43, 0x07, 0x21, 0x34, 17 | 0xed, 0xb9, 0x64, 0xd5, 0x61, 0x1c, 0x08, 0x4b, 0xaf, 0x5c, 0xb3, 0xb5, 0xd0, 0x56, 0xbb, 0x97, 18 | 0x11, 0x76, 0xdc, 0xbc, 0x84, 0xb0, 0x8f, 0x4f, 0x2f, 0x10, 0xf6, 0x78, 0x76, 0x44, 0x88, 0x29, 19 | 0x10, 0xd1, 0x56, 0x8e, 0x88, 0x11, 0x53, 0x20, 0xd2, 0xee, 0x0c, 0x44, 0x40, 0x4c, 0x81, 0x8c, 20 | 0xc4, 0x9c, 0xde, 0x7d, 0x69, 0xd4, 0x56, 0x8e, 0x8c, 0x46, 0xcc, 0xc7, 0x87, 0x97, 0x10, 0xf3, 21 | 0xe7, 0x97, 0x17, 0x88, 0xf9, 0xf9, 0xea, 0x08, 0x88, 0x14, 0x08, 0xb4, 0x95, 0x23, 0x30, 0x22, 22 | 0x05, 0x02, 0x21, 0x52, 0x20, 0x68, 0xbf, 0x0b, 0x44, 0x89, 0x25, 0x10, 0xfd, 0x5f, 0x8e, 0xa8, 23 | 0x11, 0x4b, 0x20, 0x2a, 0xc4, 0x12, 0x88, 0x82, 0x58, 0x02, 0x31, 0x22, 0x07, 0x62, 0xda, 0xca, 24 | 0x11, 0x6b, 0x6b, 0x81, 0x98, 0x10, 0x39, 0x10, 0x03, 0x91, 0x03, 0x99, 0x88, 0x92, 0xbe, 0xfb, 25 | 0xd2, 0xa4, 0xad, 0x1c, 0x99, 0x8c, 0x28, 0x87, 0x6f, 0xe5, 0x24, 0x44, 0xf9, 0xba, 0x7b, 0x81, 26 | 0x28, 0xaf, 0x77, 0x47, 0x66, 0xa2, 0x06, 0x32, 0x6b, 0x2b, 0x47, 0x66, 0x23, 0x6a, 0x20, 0xb3, 27 | 0x10, 0x35, 0x90, 0x19, 0x44, 0x0d, 0x24, 0x11, 0x6b, 0xfa, 0xe9, 0x4b, 0x49, 0x5b, 0x39, 0x92, 28 | 0x8c, 0x58, 0x0f, 0x7f, 0x80, 0x24, 0xc4, 0x7a, 0x7f, 0x78, 0x81, 0x58, 0xdf, 0xdf, 0x1d, 0x59, 29 | 0x88, 0x2d, 0xfd, 0xe9, 0x4b, 0x8b, 0xb6, 0x72, 0x64, 0x31, 0x62, 0x0b, 0x64, 0x11, 0x62, 0x0b, 30 | 0x64, 0x01, 0xb1, 0xbd, 0x7f, 0x3a, 0x92, 0x89, 0x4b, 0x6c, 0x6c, 0xd6, 0x56, 0x8e, 0x64, 0x23, 31 | 0x2e, 0xf1, 0xb2, 0x65, 0x21, 0x2e, 0xf1, 0xb2, 0x65, 0x10, 0x97, 0x87, 0x6f, 0x6c, 0x21, 0xf6, 32 | 0xd8, 0x93, 0xa2, 0xad, 0x1c, 0x29, 0x46, 0xec, 0x71, 0x3a, 0x45, 0x88, 0x3d, 0x4e, 0xa7, 0x80, 33 | 0xd8, 0x9f, 0xbe, 0x27, 0x95, 0x38, 0x62, 0x92, 0xaa, 0xad, 0x1c, 0xa9, 0x46, 0x1c, 0x31, 0x49, 34 | 0x15, 0xe2, 0x88, 0x49, 0x2a, 0x88, 0x23, 0x26, 0x59, 0x09, 0xc6, 0x24, 0xab, 0xb6, 0x72, 0x64, 35 | 0x35, 0x82, 0x31, 0xc9, 0x2a, 0x04, 0x63, 0x92, 0x15, 0x04, 0x63, 0x92, 0x8d, 0x38, 0xe3, 0x03, 36 | 0xdc, 0xb4, 0x95, 0x23, 0x9b, 0x11, 0xe7, 0x71, 0xf5, 0x12, 0xe2, 0xbc, 0x39, 0xb9, 0x81, 0x38, 37 | 0xef, 0xcf, 0xdf, 0xbf, 0x05, 0x23, 0xae, 0xa9, 0x9f, 0x94, 0x0d, 0xc4, 0xf5, 0xec, 0x8f, 0x66, 38 | 0xed, 0xd3, 0xbf, 0x9e, 0x37, 0xaf, 0x91, 0xb8, 0xde, 0xdf, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 39 | 0x26, 0xbd, 0x0d, 0xa1, 0x7f, 0x04, 0x00, 0x00, 40 | } 41 | sourceinfo.Register("nopkg/desc_test_nopkg_new.proto", srcInfo) 42 | } 43 | -------------------------------------------------------------------------------- /internal/testprotos/nopkg/desc_test_nopkg_new.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos/nopkg;nopkg"; 4 | 5 | message TopLevel { 6 | optional int32 i = 1; 7 | optional int64 j = 2; 8 | optional sint32 k = 3; 9 | optional sint64 l = 4; 10 | optional uint32 m = 5; 11 | optional uint64 n = 6; 12 | optional fixed32 o = 7; 13 | optional fixed64 p = 8; 14 | optional sfixed32 q = 9; 15 | optional sfixed64 r = 10; 16 | optional float s = 11; 17 | optional double t = 12; 18 | optional bytes u = 13; 19 | optional string v = 14; 20 | optional bool w = 15; 21 | 22 | extensions 100 to 1000; 23 | } -------------------------------------------------------------------------------- /internal/testprotos/pkg/desc_test_pkg.pb.srcinfo.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gosrcinfo. DO NOT EDIT. 2 | // source: pkg/desc_test_pkg.proto 3 | 4 | package pkg 5 | 6 | import ( 7 | sourceinfo "github.com/jhump/protoreflect/v2/sourceinfo" 8 | ) 9 | 10 | func init() { 11 | srcInfo := []byte{ 12 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x3c, 0xd1, 0x51, 0x6e, 0xeb, 0x40, 13 | 0x08, 0x85, 0xe1, 0x81, 0xc3, 0x8c, 0x09, 0xe3, 0xd8, 0xb9, 0xc7, 0xb9, 0x52, 0xa5, 0xb6, 0x52, 14 | 0xf7, 0xd4, 0xfd, 0xef, 0xa5, 0x22, 0xed, 0xf0, 0xc6, 0x2f, 0x7f, 0xd8, 0x92, 0x89, 0x41, 0x6b, 15 | 0xed, 0x29, 0xe1, 0x21, 0x3b, 0xd1, 0x1a, 0x73, 0x72, 0x42, 0xdb, 0x77, 0xdc, 0x42, 0x7d, 0xfe, 16 | 0x8e, 0x1e, 0xa2, 0x84, 0xb5, 0xaf, 0x88, 0xd0, 0xde, 0x68, 0xa3, 0x3d, 0x24, 0x22, 0xd0, 0x9b, 17 | 0x10, 0xa3, 0x7b, 0xcc, 0xb0, 0xde, 0xb4, 0x11, 0x9b, 0x3f, 0x62, 0x8f, 0x9e, 0x21, 0x59, 0x73, 18 | 0x95, 0x12, 0xdb, 0x71, 0xfe, 0x41, 0x21, 0xbc, 0xa0, 0xbc, 0x6a, 0xc1, 0xfc, 0x92, 0x17, 0x54, 19 | 0xe2, 0x56, 0x30, 0xd7, 0x6e, 0x05, 0x5f, 0xcf, 0x0a, 0x82, 0x88, 0x82, 0x90, 0xac, 0x05, 0xa1, 20 | 0x44, 0x14, 0x34, 0x62, 0x16, 0x34, 0xc9, 0x5a, 0xd0, 0x94, 0x98, 0x05, 0x3b, 0xb1, 0x17, 0xec, 21 | 0x92, 0xb5, 0x60, 0x57, 0x62, 0x2f, 0x38, 0x88, 0x7b, 0xc1, 0x21, 0x59, 0x0b, 0x0e, 0x25, 0xee, 22 | 0x05, 0x37, 0xe2, 0x28, 0xb8, 0x49, 0xd6, 0x82, 0x9b, 0x12, 0x47, 0x41, 0x27, 0xce, 0x82, 0x2e, 23 | 0x59, 0x0b, 0xba, 0x12, 0xe7, 0x71, 0xe6, 0x21, 0xac, 0xd1, 0x98, 0xd7, 0x8b, 0x80, 0xe5, 0xdf, 24 | 0xa6, 0xcf, 0x7c, 0x81, 0xbd, 0x0e, 0x71, 0xf9, 0x67, 0xae, 0x64, 0x58, 0xd6, 0x63, 0xd5, 0x20, 25 | 0xae, 0x7f, 0xcf, 0x55, 0x42, 0x5c, 0xff, 0xdf, 0x56, 0x81, 0xb8, 0xde, 0x3f, 0x7e, 0x02, 0x00, 26 | 0x00, 0xff, 0xff, 0xd5, 0xdd, 0x55, 0x59, 0x17, 0x02, 0x00, 0x00, 27 | } 28 | sourceinfo.Register("pkg/desc_test_pkg.proto", srcInfo) 29 | } 30 | -------------------------------------------------------------------------------- /internal/testprotos/pkg/desc_test_pkg.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos/pkg;pkg"; 4 | 5 | package jhump.protoreflect.desc; 6 | 7 | enum Foo { 8 | ABC = 0; 9 | DEF = 1; 10 | GHI = 2; 11 | JKL = 3; 12 | MNO = 4; 13 | PQR = 5; 14 | STU = 6; 15 | VWX = 7; 16 | Y_Z = 8; 17 | } 18 | 19 | message Bar { 20 | repeated Foo baz = 1; 21 | } 22 | -------------------------------------------------------------------------------- /internal/testprotos/proto3_optional/desc_test_proto3_optional.pb.srcinfo.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gosrcinfo. DO NOT EDIT. 2 | // source: proto3_optional/desc_test_proto3_optional.proto 3 | 4 | package testprotos 5 | 6 | import ( 7 | sourceinfo "github.com/jhump/protoreflect/v2/sourceinfo" 8 | ) 9 | 10 | func init() { 11 | srcInfo := []byte{ 12 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x34, 0x8f, 0xc1, 0x4e, 0xc4, 0x30, 13 | 0x0c, 0x44, 0xed, 0x8c, 0xdb, 0xa4, 0xd3, 0xf4, 0x32, 0x5d, 0x81, 0xd8, 0xe5, 0xc2, 0x01, 0x21, 14 | 0xed, 0x05, 0xfe, 0x83, 0xff, 0xff, 0x9f, 0x95, 0x95, 0xe6, 0xf6, 0xde, 0xd8, 0x1a, 0xd9, 0x5c, 15 | 0x15, 0x66, 0x87, 0xb3, 0xd1, 0xbb, 0x60, 0x26, 0x6e, 0x2c, 0x30, 0xa1, 0xd8, 0x33, 0xc3, 0x26, 16 | 0x84, 0xfd, 0x67, 0xd8, 0xf6, 0x81, 0x64, 0x09, 0x53, 0xac, 0xb6, 0x39, 0x49, 0x84, 0xb9, 0xb0, 17 | 0xb6, 0x2f, 0xee, 0x8c, 0xb0, 0x62, 0x42, 0x8d, 0x4f, 0x76, 0x2e, 0x29, 0x91, 0xd6, 0xa7, 0x2d, 18 | 0x42, 0x3d, 0xce, 0x69, 0x2e, 0xd4, 0xdb, 0xfb, 0x34, 0x08, 0xf5, 0xfe, 0xb8, 0x4a, 0x5c, 0x68, 19 | 0xf1, 0xb8, 0x46, 0x1e, 0x69, 0xb3, 0xc4, 0x17, 0xa1, 0x1d, 0x9a, 0x96, 0x9b, 0xe7, 0xdb, 0x34, 20 | 0x08, 0xed, 0xe3, 0xce, 0x8d, 0x5e, 0x15, 0x7b, 0xbe, 0xb5, 0xb1, 0x54, 0x13, 0x7a, 0xfc, 0xe5, 21 | 0xad, 0xd5, 0x8a, 0xb0, 0xd7, 0xef, 0xc1, 0x91, 0x79, 0x1f, 0xbc, 0x08, 0xfd, 0x38, 0x07, 0xbb, 22 | 0xd0, 0x6f, 0x3f, 0x83, 0x21, 0xf4, 0xe7, 0xef, 0x2b, 0x00, 0x00, 0xff, 0xff, 0x94, 0x7a, 0xac, 23 | 0x27, 0x26, 0x01, 0x00, 0x00, 24 | } 25 | sourceinfo.Register("proto3_optional/desc_test_proto3_optional.proto", srcInfo) 26 | } 27 | -------------------------------------------------------------------------------- /internal/testprotos/proto3_optional/desc_test_proto3_optional.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/descriptor.proto"; 4 | 5 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 6 | 7 | message MessageWithOptionalFields { 8 | optional string foo = 1; 9 | optional int64 bar = 2; 10 | } 11 | 12 | extend google.protobuf.MessageOptions { 13 | optional string some_custom_options = 44444; 14 | } -------------------------------------------------------------------------------- /internal/testprotos/proto3_optional/desc_test_proto3_optional.protoset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jhump/protoreflect/170fc7af656126cb450190be2f9e43ab305e6f27/internal/testprotos/proto3_optional/desc_test_proto3_optional.protoset -------------------------------------------------------------------------------- /protodescs/edition.go: -------------------------------------------------------------------------------- 1 | package protodescs 2 | 3 | import ( 4 | "google.golang.org/protobuf/reflect/protodesc" 5 | "google.golang.org/protobuf/reflect/protoreflect" 6 | "google.golang.org/protobuf/types/descriptorpb" 7 | 8 | "github.com/jhump/protoreflect/v2/protoresolve" 9 | ) 10 | 11 | // GetEdition returns the edition for the given file. If it cannot be determined, 12 | // descriptorpb.Edition_EDITION_UNKNOWN is returned. 13 | // 14 | // The given protos value is optional. If non-nil, it will be consulted, if 15 | // necessary, to find the underlying file descriptor proto for the given fd, from 16 | // which the edition can be queried. 17 | func GetEdition(fd protoreflect.FileDescriptor, protos protoresolve.ProtoFileOracle) descriptorpb.Edition { 18 | switch fd.Syntax() { 19 | case protoreflect.Proto2: 20 | return descriptorpb.Edition_EDITION_PROTO2 21 | case protoreflect.Proto3: 22 | return descriptorpb.Edition_EDITION_PROTO3 23 | case protoreflect.Editions: 24 | break 25 | default: 26 | return descriptorpb.Edition_EDITION_UNKNOWN 27 | } 28 | type hasEdition interface{ Edition() int32 } 29 | if ed, ok := fd.(hasEdition); ok { 30 | return descriptorpb.Edition(ed.Edition()) 31 | } 32 | if protos != nil { 33 | fileProto, err := protos.ProtoFromFileDescriptor(fd) 34 | if err == nil { 35 | return fileProto.GetEdition() 36 | } 37 | } 38 | return protodesc.ToFileDescriptorProto(fd).GetEdition() 39 | } 40 | -------------------------------------------------------------------------------- /protodescs/sort.go: -------------------------------------------------------------------------------- 1 | package protodescs 2 | 3 | import ( 4 | "google.golang.org/protobuf/types/descriptorpb" 5 | 6 | "github.com/jhump/protoreflect/v2/internal/sort" 7 | ) 8 | 9 | // SortFiles topologically sorts the given file descriptor protos. It returns 10 | // an error if the given files include duplicates (more than one entry with the 11 | // same path) or if any of the files refer to imports which are not present in 12 | // the given files. 13 | func SortFiles(files []*descriptorpb.FileDescriptorProto) error { 14 | return sort.SortFiles(files) 15 | } 16 | -------------------------------------------------------------------------------- /protomessage/as.go: -------------------------------------------------------------------------------- 1 | package protomessage 2 | 3 | import ( 4 | "fmt" 5 | 6 | "google.golang.org/protobuf/proto" 7 | "google.golang.org/protobuf/reflect/protoreflect" 8 | "google.golang.org/protobuf/reflect/protoregistry" 9 | 10 | "github.com/jhump/protoreflect/v2/protoresolve" 11 | ) 12 | 13 | // PointerMessage is a pointer type that implements [proto.Message]. 14 | type PointerMessage[T any] interface { 15 | *T 16 | proto.Message 17 | } 18 | 19 | // As returns the given message as type M. If the given message is type M, 20 | // it is returned as-is. Otherwise (like if the given message is a dynamic 21 | // message), it will be marshalled to bytes and then unmarshalled into a 22 | // value of type M. If M and msg do not share the same message type (e.g. 23 | // same fully qualified message name), an error is returned. 24 | func As[M PointerMessage[T], T any](msg proto.Message) (M, error) { 25 | dest, ok := msg.(M) 26 | if ok { 27 | return dest, nil 28 | } 29 | if msg.ProtoReflect().Descriptor().FullName() != dest.ProtoReflect().Descriptor().FullName() { 30 | return nil, fmt.Errorf("cannot return type %q: given message is %q", dest.ProtoReflect().Descriptor().FullName(), msg.ProtoReflect().Descriptor().FullName()) 31 | } 32 | var exts *protoregistry.Types 33 | var err error 34 | msg.ProtoReflect().Range(func(fd protoreflect.FieldDescriptor, _ protoreflect.Value) bool { 35 | if fd.IsExtension() { 36 | if exts == nil { 37 | exts = &protoregistry.Types{} 38 | } 39 | err = exts.RegisterExtension(protoresolve.ExtensionType(fd)) 40 | return err == nil 41 | } 42 | return true 43 | }) 44 | if err != nil { 45 | return nil, err 46 | } 47 | dest = new(T) 48 | var opts proto.UnmarshalOptions 49 | if exts != nil { 50 | opts.Resolver = exts 51 | } 52 | if data, err := proto.Marshal(msg); err != nil { 53 | return nil, err 54 | } else if err = opts.Unmarshal(data, dest); err != nil { 55 | return nil, err 56 | } 57 | return dest, nil 58 | } 59 | -------------------------------------------------------------------------------- /protomessage/as_test.go: -------------------------------------------------------------------------------- 1 | package protomessage 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/require" 7 | "google.golang.org/protobuf/proto" 8 | "google.golang.org/protobuf/reflect/protoreflect" 9 | "google.golang.org/protobuf/types/dynamicpb" 10 | "google.golang.org/protobuf/types/known/anypb" 11 | "google.golang.org/protobuf/types/known/wrapperspb" 12 | ) 13 | 14 | func TestAs(t *testing.T) { 15 | var msg proto.Message 16 | // msg needs no conversion 17 | msg = &anypb.Any{TypeUrl: "abc/def.xyz"} 18 | asAny, err := As[*anypb.Any](msg) 19 | require.NoError(t, err) 20 | require.Same(t, msg, asAny) 21 | 22 | // msg needs conversion from dynamic message 23 | msg = dynamicpb.NewMessage((&anypb.Any{}).ProtoReflect().Descriptor()) 24 | fields := msg.ProtoReflect().Descriptor().Fields() 25 | msg.ProtoReflect().Set(fields.ByName("type_url"), protoreflect.ValueOfString("abc/def.xyz")) 26 | asAny, err = As[*anypb.Any](msg) 27 | require.NoError(t, err) 28 | // not the same instance, but equivalent data 29 | require.NotSame(t, msg, asAny) 30 | require.True(t, proto.Equal(msg, asAny)) 31 | 32 | // msg cannot be converted: wrong type 33 | _, err = As[*wrapperspb.StringValue](msg) 34 | require.ErrorContains(t, err, `cannot return type "google.protobuf.StringValue": given message is "google.protobuf.Any"`) 35 | } 36 | -------------------------------------------------------------------------------- /protomessage/reparse.go: -------------------------------------------------------------------------------- 1 | package protomessage 2 | 3 | import ( 4 | "google.golang.org/protobuf/proto" 5 | 6 | "github.com/jhump/protoreflect/v2/internal/reparse" 7 | "github.com/jhump/protoreflect/v2/protoresolve" 8 | ) 9 | 10 | // ReparseUnrecognized is a helper function for re-parsing unknown fields of a message, 11 | // resolving any extensions therein using the given resolver. This is particularly useful 12 | // for unmarshalling FileDescriptorProto and FileDescriptorSet messages. With these messages, 13 | // custom options may not be statically known by the unmarshalling program, but would be 14 | // defined in the descriptor protos. So when initially unmarshalling, custom options would 15 | // be left unrecognized. After unmarshalling, the resulting descriptor protos can be used 16 | // to create a resolver (like using [protoresolve.FromFileDescriptorSet]). That resolver can 17 | // in turn be supplied to this function, to re-parse the descriptor protos, thereby 18 | // recognizing and interpreting custom options therein. 19 | func ReparseUnrecognized(msg proto.Message, resolver protoresolve.SerializationResolver) bool { 20 | return reparse.ReparseUnrecognized(msg.ProtoReflect(), resolver) 21 | } 22 | -------------------------------------------------------------------------------- /protomessage/reparse_test.go: -------------------------------------------------------------------------------- 1 | package protomessage 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/require" 7 | "google.golang.org/protobuf/proto" 8 | "google.golang.org/protobuf/reflect/protodesc" 9 | "google.golang.org/protobuf/reflect/protoreflect" 10 | "google.golang.org/protobuf/reflect/protoregistry" 11 | 12 | "github.com/jhump/protoreflect/v2/internal" 13 | "github.com/jhump/protoreflect/v2/internal/testprotos" 14 | "github.com/jhump/protoreflect/v2/protoresolve" 15 | ) 16 | 17 | func TestReparse(t *testing.T) { 18 | fileDescriptor := protodesc.ToFileDescriptorProto(testprotos.File_desc_test_complex_proto) 19 | // serialize to bytes and back, but use empty resolver when 20 | // de-serializing so that custom options are unrecognized 21 | data, err := proto.Marshal(fileDescriptor) 22 | require.NoError(t, err) 23 | opts := proto.UnmarshalOptions{Resolver: (&protoresolve.Registry{}).AsTypeResolver()} 24 | err = opts.Unmarshal(data, fileDescriptor) 25 | require.NoError(t, err) 26 | 27 | msgDescriptor := protodesc.ToDescriptorProto((&testprotos.Another{}).ProtoReflect().Descriptor()) 28 | // same thing for this message descriptor 29 | data, err = proto.Marshal(msgDescriptor) 30 | require.NoError(t, err) 31 | err = opts.Unmarshal(data, msgDescriptor) 32 | require.NoError(t, err) 33 | 34 | // Now the above messages have unrecognized fields for custom options. 35 | require.True(t, hasUnrecognized(fileDescriptor.ProtoReflect())) 36 | require.True(t, hasUnrecognized(fileDescriptor.ProtoReflect())) 37 | require.False(t, proto.HasExtension(msgDescriptor.Options, testprotos.E_Rept)) 38 | 39 | // Unrecognized become recognized. 40 | require.True(t, ReparseUnrecognized(fileDescriptor, protoregistry.GlobalTypes)) 41 | require.False(t, hasUnrecognized(fileDescriptor.ProtoReflect())) 42 | require.False(t, ReparseUnrecognized(fileDescriptor, protoregistry.GlobalTypes)) // no-op this time 43 | 44 | require.True(t, ReparseUnrecognized(msgDescriptor, protoregistry.GlobalTypes)) 45 | require.False(t, hasUnrecognized(msgDescriptor.ProtoReflect())) 46 | require.True(t, proto.HasExtension(msgDescriptor.Options, testprotos.E_Rept)) 47 | } 48 | 49 | func hasUnrecognized(msg protoreflect.Message) bool { 50 | if len(msg.GetUnknown()) > 0 { 51 | return true 52 | } 53 | var foundUnrecognized bool 54 | msg.Range(func(fd protoreflect.FieldDescriptor, val protoreflect.Value) bool { 55 | switch { 56 | case fd.IsList() && internal.IsMessageKind(fd.Kind()): 57 | l := val.List() 58 | for i, length := 0, l.Len(); i < length; i++ { 59 | if hasUnrecognized(l.Get(i).Message()) { 60 | foundUnrecognized = true 61 | return false 62 | } 63 | } 64 | case fd.IsMap() && internal.IsMessageKind(fd.MapValue().Kind()): 65 | val.Map().Range(func(_ protoreflect.MapKey, val protoreflect.Value) bool { 66 | if hasUnrecognized(val.Message()) { 67 | foundUnrecognized = true 68 | return false 69 | } 70 | return true 71 | }) 72 | if foundUnrecognized { 73 | return false 74 | } 75 | case !fd.IsMap() && internal.IsMessageKind(fd.Kind()): 76 | if hasUnrecognized(val.Message()) { 77 | foundUnrecognized = true 78 | return false 79 | } 80 | } 81 | return true 82 | }) 83 | return foundUnrecognized 84 | } 85 | -------------------------------------------------------------------------------- /protomessage/walk.go: -------------------------------------------------------------------------------- 1 | package protomessage 2 | 3 | import ( 4 | "google.golang.org/protobuf/reflect/protoreflect" 5 | 6 | "github.com/jhump/protoreflect/v2/internal" 7 | ) 8 | 9 | // Walk traverses the given root messages, iterating through its fields and 10 | // through all values in maps and lists, calling the given action for all 11 | // message values encountered. The given action is called for root first 12 | // before being called for any contained message values. 13 | // 14 | // The path provided to the callback is the sequence of field numbers, 15 | // list indices, and map keys that identifies the location of the given 16 | // message. It is empty when called for the root message. The types of 17 | // values in the slice will be protoreflect.FieldNumber, int (an index 18 | // into a list field), or protoreflect.MapKey (indicating which entry 19 | // in a map field). 20 | // 21 | // If the callback returns false, the traversal is terminated and the 22 | // callback will not be invoked again. 23 | func Walk(root protoreflect.Message, action func(path []any, val protoreflect.Message) bool) { 24 | walk(root, make([]any, 0, 8), action) 25 | } 26 | 27 | func walk(root protoreflect.Message, path []any, action func(path []any, val protoreflect.Message) bool) bool { 28 | ok := action(path, root) 29 | root.Range(func(field protoreflect.FieldDescriptor, val protoreflect.Value) bool { 30 | path = append(path, field.Number()) 31 | switch { 32 | case field.IsList() && internal.IsMessageKind(field.Kind()): 33 | listVal := val.List() 34 | for i, length := 0, listVal.Len(); i < length; i++ { 35 | path = append(path, i) 36 | ok = walk(listVal.Get(i).Message(), path, action) 37 | path = path[:len(path)-1] // pop index 38 | if !ok { 39 | break 40 | } 41 | } 42 | case field.IsMap() && internal.IsMessageKind(field.MapValue().Kind()): 43 | mapVal := val.Map() 44 | mapVal.Range(func(key protoreflect.MapKey, val protoreflect.Value) bool { 45 | path = append(path, key) 46 | ok = walk(val.Message(), path, action) 47 | path = path[:len(path)-1] // pop entry key 48 | return ok 49 | }) 50 | case !field.IsMap() && internal.IsMessageKind(field.Kind()): 51 | ok = walk(val.Message(), path, action) 52 | } 53 | path = path[:len(path)-1] // pop field number 54 | return ok 55 | }) 56 | return ok 57 | } 58 | -------------------------------------------------------------------------------- /protomessage/walk_test.go: -------------------------------------------------------------------------------- 1 | package protomessage_test 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/bufbuild/protocompile/walk" 8 | "github.com/stretchr/testify/require" 9 | "google.golang.org/protobuf/proto" 10 | "google.golang.org/protobuf/reflect/protodesc" 11 | "google.golang.org/protobuf/reflect/protoreflect" 12 | "google.golang.org/protobuf/types/descriptorpb" 13 | 14 | prototesting "github.com/jhump/protoreflect/v2/internal/testing" 15 | "github.com/jhump/protoreflect/v2/protomessage" 16 | "github.com/jhump/protoreflect/v2/protoresolve" 17 | "github.com/jhump/protoreflect/v2/sourceloc" 18 | ) 19 | 20 | func TestWalk(t *testing.T) { 21 | fd, err := prototesting.LoadProtoset("../internal/testprotos/desc_test_complex_source_info.protoset") 22 | require.NoError(t, err) 23 | 24 | fdProto := protodesc.ToFileDescriptorProto(fd) 25 | protoOracle := protoresolve.NewProtoOracle(oracleForFile{fd, fdProto}) 26 | paths := map[proto.Message]protoreflect.SourcePath{} 27 | err = walk.Descriptors(fd, func(d protoreflect.Descriptor) error { 28 | msg, err := protoOracle.ProtoFromDescriptor(d) 29 | if err != nil { 30 | return err 31 | } 32 | paths[msg] = sourceloc.PathFor(d) 33 | return nil 34 | }) 35 | require.NoError(t, err) 36 | 37 | encountered := make(map[proto.Message]struct{}, len(paths)) 38 | protomessage.Walk(fdProto.ProtoReflect(), func(path []any, msg protoreflect.Message) bool { 39 | expectPath, ok := paths[msg.Interface()] 40 | if !ok { 41 | // skip 42 | return true 43 | } 44 | encountered[msg.Interface()] = struct{}{} 45 | actualPath := make(protoreflect.SourcePath, len(path)) 46 | for i := range path { 47 | switch p := path[i].(type) { 48 | case protoreflect.FieldNumber: 49 | actualPath[i] = int32(p) 50 | case int: // index into list field 51 | actualPath[i] = int32(p) 52 | default: 53 | t.Fatalf("unexpected element at path[i]: %T", p) 54 | } 55 | } 56 | require.Equal(t, expectPath, actualPath) 57 | return true 58 | }) 59 | require.Len(t, encountered, len(paths)) 60 | } 61 | 62 | type oracleForFile struct { 63 | fd protoreflect.FileDescriptor 64 | fdProto *descriptorpb.FileDescriptorProto 65 | } 66 | 67 | func (o oracleForFile) ProtoFromFileDescriptor(file protoreflect.FileDescriptor) (*descriptorpb.FileDescriptorProto, error) { 68 | if file == o.fd { 69 | return o.fdProto, nil 70 | } 71 | return nil, fmt.Errorf("unexpected file: %s", file.Path()) 72 | } 73 | -------------------------------------------------------------------------------- /protoprint/doc.go: -------------------------------------------------------------------------------- 1 | // Package protoprint provides a mechanism to generate protobuf source code 2 | // from descriptors. 3 | // 4 | // This can be useful to turn file descriptor sets (produced by a compiler like 5 | // protoc or buf) back into proto IDL code. Combined with the 6 | // [github.com/jhump/protoreflect/v2/protobuilder] package, it can also be used 7 | // to perform code generation of proto source code. 8 | package protoprint 9 | -------------------------------------------------------------------------------- /protoprint/source_locs.go: -------------------------------------------------------------------------------- 1 | package protoprint 2 | 3 | import ( 4 | "google.golang.org/protobuf/reflect/protoreflect" 5 | 6 | "github.com/jhump/protoreflect/v2/internal" 7 | "github.com/jhump/protoreflect/v2/sourceloc" 8 | ) 9 | 10 | type sourceLocations struct { 11 | protoreflect.SourceLocations 12 | extrasByPath map[string]*protoreflect.SourceLocation 13 | extras []protoreflect.SourceLocation 14 | } 15 | 16 | func (s *sourceLocations) Len() int { 17 | return s.SourceLocations.Len() + len(s.extras) 18 | } 19 | 20 | func (s *sourceLocations) Get(i int) protoreflect.SourceLocation { 21 | if i < s.SourceLocations.Len() { 22 | return s.SourceLocations.Get(i) 23 | } 24 | return s.extras[i-s.SourceLocations.Len()] 25 | } 26 | 27 | func (s *sourceLocations) ByPath(path protoreflect.SourcePath) protoreflect.SourceLocation { 28 | loc := s.SourceLocations.ByPath(path) 29 | if loc.Path != nil { 30 | return loc 31 | } 32 | k := internal.PathKey(path) 33 | pLoc := s.extrasByPath[k] 34 | if pLoc == nil { 35 | return protoreflect.SourceLocation{} 36 | } 37 | return *pLoc 38 | } 39 | 40 | func (s *sourceLocations) putIfAbsent(path protoreflect.SourcePath, loc protoreflect.SourceLocation) { 41 | if existing := s.ByPath(path); sourceloc.IsZero(existing) { 42 | k := internal.PathKey(path) 43 | s.extras = append(s.extras, loc) 44 | if s.extrasByPath == nil { 45 | s.extrasByPath = map[string]*protoreflect.SourceLocation{} 46 | } 47 | s.extrasByPath[k] = &s.extras[len(s.extras)-1] 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /protoprint/testfiles/check-protos.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | cd $(dirname $0) 6 | 7 | for f in *.proto; do 8 | echo -n "Checking $f..." 9 | ../../internal/testprotos/protoc/bin/protoc $f -o /dev/null -I . -I ../../internal/testprotos 10 | echo " good" 11 | done 12 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test1-compact.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 3 | package testprotos; 4 | // Comment for TestMessage 5 | message TestMessage { 6 | // Comment for NestedMessage 7 | message NestedMessage { 8 | // Comment for AnotherNestedMessage 9 | message AnotherNestedMessage { 10 | // Comment for AnotherTestMessage extensions (1) 11 | extend AnotherTestMessage { 12 | // Comment for flags 13 | repeated bool flags = 200 [packed = true]; 14 | } 15 | // Comment for YetAnotherNestedMessage 16 | message YetAnotherNestedMessage { 17 | // Comment for DeeplyNestedEnum 18 | enum DeeplyNestedEnum { 19 | // Comment for VALUE1 20 | VALUE1 = 1; 21 | // Comment for VALUE2 22 | VALUE2 = 2; 23 | } 24 | // Comment for foo 25 | optional string foo = 1; 26 | // Comment for bar 27 | optional int32 bar = 2; 28 | // Comment for baz 29 | optional bytes baz = 3; 30 | // Comment for dne 31 | optional DeeplyNestedEnum dne = 4; 32 | // Comment for anm 33 | optional AnotherNestedMessage anm = 5; 34 | // Comment for nm 35 | optional NestedMessage nm = 6; 36 | // Comment for tm 37 | optional TestMessage tm = 7; 38 | } 39 | // Comment for yanm 40 | repeated YetAnotherNestedMessage yanm = 1; 41 | } 42 | // Comment for anm 43 | optional AnotherNestedMessage anm = 1; 44 | // Comment for yanm 45 | optional AnotherNestedMessage.YetAnotherNestedMessage yanm = 2; 46 | } 47 | // Comment for NestedEnum 48 | enum NestedEnum { 49 | // Comment for VALUE1 50 | VALUE1 = 1; 51 | // Comment for VALUE2 52 | VALUE2 = 2; 53 | } 54 | // Comment for nm 55 | optional NestedMessage nm = 1; 56 | // Comment for anm 57 | optional NestedMessage.AnotherNestedMessage anm = 2; 58 | // Comment for yanm 59 | optional NestedMessage.AnotherNestedMessage.YetAnotherNestedMessage yanm = 3; 60 | // Comment for ne 61 | repeated NestedEnum ne = 4; 62 | } 63 | // Comment for AnotherTestMessage 64 | message AnotherTestMessage { 65 | // Comment for dne 66 | optional TestMessage.NestedMessage.AnotherNestedMessage.YetAnotherNestedMessage.DeeplyNestedEnum dne = 1; 67 | // Comment for map_field1 68 | map map_field1 = 2; 69 | // Comment for map_field2 70 | map map_field2 = 3; 71 | // Comment for map_field3 72 | map map_field3 = 4; 73 | // Comment for map_field4 74 | map map_field4 = 5; 75 | // Comment for RockNRoll 76 | optional group RockNRoll = 6 { 77 | // Comment for beatles 78 | optional string beatles = 1; 79 | // Comment for stones 80 | optional string stones = 2; 81 | // Comment for doors 82 | optional string doors = 3; 83 | } 84 | // Comment for atmoo 85 | oneof atmoo { 86 | // Comment for str 87 | string str = 7; 88 | // Comment for int 89 | int64 int = 8; 90 | } 91 | // Comment for WithOptions 92 | optional group WithOptions = 9 [deprecated = true] { 93 | } 94 | extensions 100 to 200; 95 | } 96 | // Comment for AnotherTestMessage extensions (2) 97 | extend AnotherTestMessage { 98 | // Comment for xtm 99 | optional TestMessage xtm = 100; 100 | // Comment for xs 101 | optional string xs = 101; 102 | } 103 | // Comment for AnotherTestMessage extensions (3) 104 | extend AnotherTestMessage { 105 | // Comment for xi 106 | optional int32 xi = 102; 107 | // Comment for xui 108 | optional uint64 xui = 103; 109 | } 110 | // Comment for SomeEnum 111 | enum SomeEnum { 112 | // Comment for SOME_VAL 113 | SOME_VAL = 0; 114 | // Comment for ANOTHER_VAL 115 | ANOTHER_VAL = 1; 116 | // Comment for YET_ANOTHER_VAL 117 | YET_ANOTHER_VAL = 2; 118 | } 119 | // Comment for SomeService 120 | service SomeService { 121 | // Comment for SomeMethod 122 | rpc SomeMethod ( TestMessage ) returns ( TestMessage ); 123 | // Comment for SomeOtherMethod 124 | rpc SomeOtherMethod ( AnotherTestMessage ) returns ( AnotherTestMessage ); 125 | } 126 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test1-custom-sort.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | // Comment for AnotherTestMessage extensions (3) 4 | extend AnotherTestMessage { 5 | // Comment for xui 6 | optional uint64 xui = 103; 7 | 8 | // Comment for xi 9 | optional int32 xi = 102; 10 | } 11 | 12 | // Comment for AnotherTestMessage extensions (2) 13 | extend AnotherTestMessage { 14 | // Comment for xtm 15 | optional TestMessage xtm = 100; 16 | 17 | // Comment for xs 18 | optional string xs = 101; 19 | } 20 | 21 | // Comment for SomeService 22 | service SomeService { 23 | // Comment for SomeOtherMethod 24 | rpc SomeOtherMethod ( AnotherTestMessage ) returns ( AnotherTestMessage ); 25 | 26 | // Comment for SomeMethod 27 | rpc SomeMethod ( TestMessage ) returns ( TestMessage ); 28 | } 29 | 30 | // Comment for SomeEnum 31 | enum SomeEnum { 32 | // Comment for YET_ANOTHER_VAL 33 | YET_ANOTHER_VAL = 2; 34 | 35 | // Comment for SOME_VAL 36 | SOME_VAL = 0; 37 | 38 | // Comment for ANOTHER_VAL 39 | ANOTHER_VAL = 1; 40 | } 41 | 42 | // Comment for TestMessage 43 | message TestMessage { 44 | // Comment for NestedEnum 45 | enum NestedEnum { 46 | // Comment for VALUE2 47 | VALUE2 = 2; 48 | 49 | // Comment for VALUE1 50 | VALUE1 = 1; 51 | } 52 | 53 | // Comment for NestedMessage 54 | message NestedMessage { 55 | // Comment for AnotherNestedMessage 56 | message AnotherNestedMessage { 57 | // Comment for AnotherTestMessage extensions (1) 58 | extend AnotherTestMessage { 59 | // Comment for flags 60 | repeated bool flags = 200 [packed = true]; 61 | } 62 | 63 | // Comment for YetAnotherNestedMessage 64 | message YetAnotherNestedMessage { 65 | // Comment for DeeplyNestedEnum 66 | enum DeeplyNestedEnum { 67 | // Comment for VALUE2 68 | VALUE2 = 2; 69 | 70 | // Comment for VALUE1 71 | VALUE1 = 1; 72 | } 73 | 74 | // Comment for tm 75 | optional TestMessage tm = 7; 76 | 77 | // Comment for nm 78 | optional NestedMessage nm = 6; 79 | 80 | // Comment for foo 81 | optional string foo = 1; 82 | 83 | // Comment for dne 84 | optional DeeplyNestedEnum dne = 4; 85 | 86 | // Comment for baz 87 | optional bytes baz = 3; 88 | 89 | // Comment for bar 90 | optional int32 bar = 2; 91 | 92 | // Comment for anm 93 | optional AnotherNestedMessage anm = 5; 94 | } 95 | 96 | // Comment for yanm 97 | repeated YetAnotherNestedMessage yanm = 1; 98 | } 99 | 100 | // Comment for yanm 101 | optional AnotherNestedMessage.YetAnotherNestedMessage yanm = 2; 102 | 103 | // Comment for anm 104 | optional AnotherNestedMessage anm = 1; 105 | } 106 | 107 | // Comment for yanm 108 | optional NestedMessage.AnotherNestedMessage.YetAnotherNestedMessage yanm = 3; 109 | 110 | // Comment for nm 111 | optional NestedMessage nm = 1; 112 | 113 | // Comment for ne 114 | repeated NestedEnum ne = 4; 115 | 116 | // Comment for anm 117 | optional NestedMessage.AnotherNestedMessage anm = 2; 118 | } 119 | 120 | // Comment for AnotherTestMessage 121 | message AnotherTestMessage { 122 | extensions 100 to 200; 123 | 124 | // Comment for WithOptions 125 | optional group WithOptions = 9 [deprecated = true] { 126 | } 127 | 128 | // Comment for atmoo 129 | oneof atmoo { 130 | // Comment for str 131 | string str = 7; 132 | 133 | // Comment for int 134 | int64 int = 8; 135 | } 136 | 137 | // Comment for RockNRoll 138 | optional group RockNRoll = 6 { 139 | // Comment for stones 140 | optional string stones = 2; 141 | 142 | // Comment for doors 143 | optional string doors = 3; 144 | 145 | // Comment for beatles 146 | optional string beatles = 1; 147 | } 148 | 149 | // Comment for map_field4 150 | map map_field4 = 5; 151 | 152 | // Comment for map_field3 153 | map map_field3 = 4; 154 | 155 | // Comment for map_field2 156 | map map_field2 = 3; 157 | 158 | // Comment for map_field1 159 | map map_field1 = 2; 160 | 161 | // Comment for dne 162 | optional TestMessage.NestedMessage.AnotherNestedMessage.YetAnotherNestedMessage.DeeplyNestedEnum dne = 1; 163 | } 164 | 165 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 166 | 167 | package testprotos; 168 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test1-default.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | 5 | package testprotos; 6 | 7 | // Comment for TestMessage 8 | message TestMessage { 9 | // Comment for NestedMessage 10 | message NestedMessage { 11 | // Comment for AnotherNestedMessage 12 | message AnotherNestedMessage { 13 | // Comment for AnotherTestMessage extensions (1) 14 | extend AnotherTestMessage { 15 | // Comment for flags 16 | repeated bool flags = 200 [packed = true]; 17 | } 18 | 19 | // Comment for YetAnotherNestedMessage 20 | message YetAnotherNestedMessage { 21 | // Comment for DeeplyNestedEnum 22 | enum DeeplyNestedEnum { 23 | // Comment for VALUE1 24 | VALUE1 = 1; 25 | 26 | // Comment for VALUE2 27 | VALUE2 = 2; 28 | } 29 | 30 | // Comment for foo 31 | optional string foo = 1; 32 | 33 | // Comment for bar 34 | optional int32 bar = 2; 35 | 36 | // Comment for baz 37 | optional bytes baz = 3; 38 | 39 | // Comment for dne 40 | optional DeeplyNestedEnum dne = 4; 41 | 42 | // Comment for anm 43 | optional AnotherNestedMessage anm = 5; 44 | 45 | // Comment for nm 46 | optional NestedMessage nm = 6; 47 | 48 | // Comment for tm 49 | optional TestMessage tm = 7; 50 | } 51 | 52 | // Comment for yanm 53 | repeated YetAnotherNestedMessage yanm = 1; 54 | } 55 | 56 | // Comment for anm 57 | optional AnotherNestedMessage anm = 1; 58 | 59 | // Comment for yanm 60 | optional AnotherNestedMessage.YetAnotherNestedMessage yanm = 2; 61 | } 62 | 63 | // Comment for NestedEnum 64 | enum NestedEnum { 65 | // Comment for VALUE1 66 | VALUE1 = 1; 67 | 68 | // Comment for VALUE2 69 | VALUE2 = 2; 70 | } 71 | 72 | // Comment for nm 73 | optional NestedMessage nm = 1; 74 | 75 | // Comment for anm 76 | optional NestedMessage.AnotherNestedMessage anm = 2; 77 | 78 | // Comment for yanm 79 | optional NestedMessage.AnotherNestedMessage.YetAnotherNestedMessage yanm = 3; 80 | 81 | // Comment for ne 82 | repeated NestedEnum ne = 4; 83 | } 84 | 85 | // Comment for AnotherTestMessage 86 | message AnotherTestMessage { 87 | // Comment for dne 88 | optional TestMessage.NestedMessage.AnotherNestedMessage.YetAnotherNestedMessage.DeeplyNestedEnum dne = 1; 89 | 90 | // Comment for map_field1 91 | map map_field1 = 2; 92 | 93 | // Comment for map_field2 94 | map map_field2 = 3; 95 | 96 | // Comment for map_field3 97 | map map_field3 = 4; 98 | 99 | // Comment for map_field4 100 | map map_field4 = 5; 101 | 102 | // Comment for RockNRoll 103 | optional group RockNRoll = 6 { 104 | // Comment for beatles 105 | optional string beatles = 1; 106 | 107 | // Comment for stones 108 | optional string stones = 2; 109 | 110 | // Comment for doors 111 | optional string doors = 3; 112 | } 113 | 114 | // Comment for atmoo 115 | oneof atmoo { 116 | // Comment for str 117 | string str = 7; 118 | 119 | // Comment for int 120 | int64 int = 8; 121 | } 122 | 123 | // Comment for WithOptions 124 | optional group WithOptions = 9 [deprecated = true] { 125 | } 126 | 127 | extensions 100 to 200; 128 | } 129 | 130 | // Comment for AnotherTestMessage extensions (2) 131 | extend AnotherTestMessage { 132 | // Comment for xtm 133 | optional TestMessage xtm = 100; 134 | 135 | // Comment for xs 136 | optional string xs = 101; 137 | } 138 | 139 | // Comment for AnotherTestMessage extensions (3) 140 | extend AnotherTestMessage { 141 | // Comment for xi 142 | optional int32 xi = 102; 143 | 144 | // Comment for xui 145 | optional uint64 xui = 103; 146 | } 147 | 148 | // Comment for SomeEnum 149 | enum SomeEnum { 150 | // Comment for SOME_VAL 151 | SOME_VAL = 0; 152 | 153 | // Comment for ANOTHER_VAL 154 | ANOTHER_VAL = 1; 155 | 156 | // Comment for YET_ANOTHER_VAL 157 | YET_ANOTHER_VAL = 2; 158 | } 159 | 160 | // Comment for SomeService 161 | service SomeService { 162 | // Comment for SomeMethod 163 | rpc SomeMethod ( TestMessage ) returns ( TestMessage ); 164 | 165 | // Comment for SomeOtherMethod 166 | rpc SomeOtherMethod ( AnotherTestMessage ) returns ( AnotherTestMessage ); 167 | } 168 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test1-multiline-style-comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | 5 | package testprotos; 6 | 7 | /* Comment for TestMessage */ 8 | message TestMessage { 9 | /* Comment for NestedMessage */ 10 | message NestedMessage { 11 | /* Comment for AnotherNestedMessage */ 12 | message AnotherNestedMessage { 13 | /* Comment for AnotherTestMessage extensions (1) */ 14 | extend AnotherTestMessage { 15 | /* Comment for flags */ 16 | repeated bool flags = 200 [packed = true]; 17 | } 18 | 19 | /* Comment for YetAnotherNestedMessage */ 20 | message YetAnotherNestedMessage { 21 | /* Comment for DeeplyNestedEnum */ 22 | enum DeeplyNestedEnum { 23 | /* Comment for VALUE1 */ 24 | VALUE1 = 1; 25 | 26 | /* Comment for VALUE2 */ 27 | VALUE2 = 2; 28 | } 29 | 30 | /* Comment for foo */ 31 | optional string foo = 1; 32 | 33 | /* Comment for bar */ 34 | optional int32 bar = 2; 35 | 36 | /* Comment for baz */ 37 | optional bytes baz = 3; 38 | 39 | /* Comment for dne */ 40 | optional DeeplyNestedEnum dne = 4; 41 | 42 | /* Comment for anm */ 43 | optional AnotherNestedMessage anm = 5; 44 | 45 | /* Comment for nm */ 46 | optional NestedMessage nm = 6; 47 | 48 | /* Comment for tm */ 49 | optional TestMessage tm = 7; 50 | } 51 | 52 | /* Comment for yanm */ 53 | repeated YetAnotherNestedMessage yanm = 1; 54 | } 55 | 56 | /* Comment for anm */ 57 | optional AnotherNestedMessage anm = 1; 58 | 59 | /* Comment for yanm */ 60 | optional AnotherNestedMessage.YetAnotherNestedMessage yanm = 2; 61 | } 62 | 63 | /* Comment for NestedEnum */ 64 | enum NestedEnum { 65 | /* Comment for VALUE1 */ 66 | VALUE1 = 1; 67 | 68 | /* Comment for VALUE2 */ 69 | VALUE2 = 2; 70 | } 71 | 72 | /* Comment for nm */ 73 | optional NestedMessage nm = 1; 74 | 75 | /* Comment for anm */ 76 | optional NestedMessage.AnotherNestedMessage anm = 2; 77 | 78 | /* Comment for yanm */ 79 | optional NestedMessage.AnotherNestedMessage.YetAnotherNestedMessage yanm = 3; 80 | 81 | /* Comment for ne */ 82 | repeated NestedEnum ne = 4; 83 | } 84 | 85 | /* Comment for AnotherTestMessage */ 86 | message AnotherTestMessage { 87 | /* Comment for dne */ 88 | optional TestMessage.NestedMessage.AnotherNestedMessage.YetAnotherNestedMessage.DeeplyNestedEnum dne = 1; 89 | 90 | /* Comment for map_field1 */ 91 | map map_field1 = 2; 92 | 93 | /* Comment for map_field2 */ 94 | map map_field2 = 3; 95 | 96 | /* Comment for map_field3 */ 97 | map map_field3 = 4; 98 | 99 | /* Comment for map_field4 */ 100 | map map_field4 = 5; 101 | 102 | /* Comment for RockNRoll */ 103 | optional group RockNRoll = 6 { 104 | /* Comment for beatles */ 105 | optional string beatles = 1; 106 | 107 | /* Comment for stones */ 108 | optional string stones = 2; 109 | 110 | /* Comment for doors */ 111 | optional string doors = 3; 112 | } 113 | 114 | /* Comment for atmoo */ 115 | oneof atmoo { 116 | /* Comment for str */ 117 | string str = 7; 118 | 119 | /* Comment for int */ 120 | int64 int = 8; 121 | } 122 | 123 | /* Comment for WithOptions */ 124 | optional group WithOptions = 9 [deprecated = true] { 125 | } 126 | 127 | extensions 100 to 200; 128 | } 129 | 130 | /* Comment for AnotherTestMessage extensions (2) */ 131 | extend AnotherTestMessage { 132 | /* Comment for xtm */ 133 | optional TestMessage xtm = 100; 134 | 135 | /* Comment for xs */ 136 | optional string xs = 101; 137 | } 138 | 139 | /* Comment for AnotherTestMessage extensions (3) */ 140 | extend AnotherTestMessage { 141 | /* Comment for xi */ 142 | optional int32 xi = 102; 143 | 144 | /* Comment for xui */ 145 | optional uint64 xui = 103; 146 | } 147 | 148 | /* Comment for SomeEnum */ 149 | enum SomeEnum { 150 | /* Comment for SOME_VAL */ 151 | SOME_VAL = 0; 152 | 153 | /* Comment for ANOTHER_VAL */ 154 | ANOTHER_VAL = 1; 155 | 156 | /* Comment for YET_ANOTHER_VAL */ 157 | YET_ANOTHER_VAL = 2; 158 | } 159 | 160 | /* Comment for SomeService */ 161 | service SomeService { 162 | /* Comment for SomeMethod */ 163 | rpc SomeMethod ( TestMessage ) returns ( TestMessage ); 164 | 165 | /* Comment for SomeOtherMethod */ 166 | rpc SomeOtherMethod ( AnotherTestMessage ) returns ( AnotherTestMessage ); 167 | } 168 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test1-no-trailing-comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | 5 | package testprotos; 6 | 7 | // Comment for TestMessage 8 | message TestMessage { 9 | // Comment for NestedMessage 10 | message NestedMessage { 11 | // Comment for AnotherNestedMessage 12 | message AnotherNestedMessage { 13 | // Comment for AnotherTestMessage extensions (1) 14 | extend AnotherTestMessage { 15 | // Comment for flags 16 | repeated bool flags = 200 [packed = true]; 17 | } 18 | 19 | // Comment for YetAnotherNestedMessage 20 | message YetAnotherNestedMessage { 21 | // Comment for DeeplyNestedEnum 22 | enum DeeplyNestedEnum { 23 | // Comment for VALUE1 24 | VALUE1 = 1; 25 | 26 | // Comment for VALUE2 27 | VALUE2 = 2; 28 | } 29 | 30 | // Comment for foo 31 | optional string foo = 1; 32 | 33 | // Comment for bar 34 | optional int32 bar = 2; 35 | 36 | // Comment for baz 37 | optional bytes baz = 3; 38 | 39 | // Comment for dne 40 | optional DeeplyNestedEnum dne = 4; 41 | 42 | // Comment for anm 43 | optional AnotherNestedMessage anm = 5; 44 | 45 | // Comment for nm 46 | optional NestedMessage nm = 6; 47 | 48 | // Comment for tm 49 | optional TestMessage tm = 7; 50 | } 51 | 52 | // Comment for yanm 53 | repeated YetAnotherNestedMessage yanm = 1; 54 | } 55 | 56 | // Comment for anm 57 | optional AnotherNestedMessage anm = 1; 58 | 59 | // Comment for yanm 60 | optional AnotherNestedMessage.YetAnotherNestedMessage yanm = 2; 61 | } 62 | 63 | // Comment for NestedEnum 64 | enum NestedEnum { 65 | // Comment for VALUE1 66 | VALUE1 = 1; 67 | 68 | // Comment for VALUE2 69 | VALUE2 = 2; 70 | } 71 | 72 | // Comment for nm 73 | optional NestedMessage nm = 1; 74 | 75 | // Comment for anm 76 | optional NestedMessage.AnotherNestedMessage anm = 2; 77 | 78 | // Comment for yanm 79 | optional NestedMessage.AnotherNestedMessage.YetAnotherNestedMessage yanm = 3; 80 | 81 | // Comment for ne 82 | repeated NestedEnum ne = 4; 83 | } 84 | 85 | // Comment for AnotherTestMessage 86 | message AnotherTestMessage { 87 | // Comment for dne 88 | optional TestMessage.NestedMessage.AnotherNestedMessage.YetAnotherNestedMessage.DeeplyNestedEnum dne = 1; 89 | 90 | // Comment for map_field1 91 | map map_field1 = 2; 92 | 93 | // Comment for map_field2 94 | map map_field2 = 3; 95 | 96 | // Comment for map_field3 97 | map map_field3 = 4; 98 | 99 | // Comment for map_field4 100 | map map_field4 = 5; 101 | 102 | // Comment for RockNRoll 103 | optional group RockNRoll = 6 { 104 | // Comment for beatles 105 | optional string beatles = 1; 106 | 107 | // Comment for stones 108 | optional string stones = 2; 109 | 110 | // Comment for doors 111 | optional string doors = 3; 112 | } 113 | 114 | // Comment for atmoo 115 | oneof atmoo { 116 | // Comment for str 117 | string str = 7; 118 | 119 | // Comment for int 120 | int64 int = 8; 121 | } 122 | 123 | // Comment for WithOptions 124 | optional group WithOptions = 9 [deprecated = true] { 125 | } 126 | 127 | extensions 100 to 200; 128 | } 129 | 130 | // Comment for AnotherTestMessage extensions (2) 131 | extend AnotherTestMessage { 132 | // Comment for xtm 133 | optional TestMessage xtm = 100; 134 | 135 | // Comment for xs 136 | optional string xs = 101; 137 | } 138 | 139 | // Comment for AnotherTestMessage extensions (3) 140 | extend AnotherTestMessage { 141 | // Comment for xi 142 | optional int32 xi = 102; 143 | 144 | // Comment for xui 145 | optional uint64 xui = 103; 146 | } 147 | 148 | // Comment for SomeEnum 149 | enum SomeEnum { 150 | // Comment for SOME_VAL 151 | SOME_VAL = 0; 152 | 153 | // Comment for ANOTHER_VAL 154 | ANOTHER_VAL = 1; 155 | 156 | // Comment for YET_ANOTHER_VAL 157 | YET_ANOTHER_VAL = 2; 158 | } 159 | 160 | // Comment for SomeService 161 | service SomeService { 162 | // Comment for SomeMethod 163 | rpc SomeMethod ( TestMessage ) returns ( TestMessage ); 164 | 165 | // Comment for SomeOtherMethod 166 | rpc SomeOtherMethod ( AnotherTestMessage ) returns ( AnotherTestMessage ); 167 | } 168 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test1-only-doc-comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | 5 | package testprotos; 6 | 7 | // Comment for TestMessage 8 | message TestMessage { 9 | // Comment for NestedMessage 10 | message NestedMessage { 11 | // Comment for AnotherNestedMessage 12 | message AnotherNestedMessage { 13 | // Comment for AnotherTestMessage extensions (1) 14 | extend AnotherTestMessage { 15 | // Comment for flags 16 | repeated bool flags = 200 [packed = true]; 17 | } 18 | 19 | // Comment for YetAnotherNestedMessage 20 | message YetAnotherNestedMessage { 21 | // Comment for DeeplyNestedEnum 22 | enum DeeplyNestedEnum { 23 | // Comment for VALUE1 24 | VALUE1 = 1; 25 | 26 | // Comment for VALUE2 27 | VALUE2 = 2; 28 | } 29 | 30 | // Comment for foo 31 | optional string foo = 1; 32 | 33 | // Comment for bar 34 | optional int32 bar = 2; 35 | 36 | // Comment for baz 37 | optional bytes baz = 3; 38 | 39 | // Comment for dne 40 | optional DeeplyNestedEnum dne = 4; 41 | 42 | // Comment for anm 43 | optional AnotherNestedMessage anm = 5; 44 | 45 | // Comment for nm 46 | optional NestedMessage nm = 6; 47 | 48 | // Comment for tm 49 | optional TestMessage tm = 7; 50 | } 51 | 52 | // Comment for yanm 53 | repeated YetAnotherNestedMessage yanm = 1; 54 | } 55 | 56 | // Comment for anm 57 | optional AnotherNestedMessage anm = 1; 58 | 59 | // Comment for yanm 60 | optional AnotherNestedMessage.YetAnotherNestedMessage yanm = 2; 61 | } 62 | 63 | // Comment for NestedEnum 64 | enum NestedEnum { 65 | // Comment for VALUE1 66 | VALUE1 = 1; 67 | 68 | // Comment for VALUE2 69 | VALUE2 = 2; 70 | } 71 | 72 | // Comment for nm 73 | optional NestedMessage nm = 1; 74 | 75 | // Comment for anm 76 | optional NestedMessage.AnotherNestedMessage anm = 2; 77 | 78 | // Comment for yanm 79 | optional NestedMessage.AnotherNestedMessage.YetAnotherNestedMessage yanm = 3; 80 | 81 | // Comment for ne 82 | repeated NestedEnum ne = 4; 83 | } 84 | 85 | // Comment for AnotherTestMessage 86 | message AnotherTestMessage { 87 | // Comment for dne 88 | optional TestMessage.NestedMessage.AnotherNestedMessage.YetAnotherNestedMessage.DeeplyNestedEnum dne = 1; 89 | 90 | // Comment for map_field1 91 | map map_field1 = 2; 92 | 93 | // Comment for map_field2 94 | map map_field2 = 3; 95 | 96 | // Comment for map_field3 97 | map map_field3 = 4; 98 | 99 | // Comment for map_field4 100 | map map_field4 = 5; 101 | 102 | // Comment for RockNRoll 103 | optional group RockNRoll = 6 { 104 | // Comment for beatles 105 | optional string beatles = 1; 106 | 107 | // Comment for stones 108 | optional string stones = 2; 109 | 110 | // Comment for doors 111 | optional string doors = 3; 112 | } 113 | 114 | // Comment for atmoo 115 | oneof atmoo { 116 | // Comment for str 117 | string str = 7; 118 | 119 | // Comment for int 120 | int64 int = 8; 121 | } 122 | 123 | // Comment for WithOptions 124 | optional group WithOptions = 9 [deprecated = true] { 125 | } 126 | 127 | extensions 100 to 200; 128 | } 129 | 130 | // Comment for AnotherTestMessage extensions (2) 131 | extend AnotherTestMessage { 132 | // Comment for xtm 133 | optional TestMessage xtm = 100; 134 | 135 | // Comment for xs 136 | optional string xs = 101; 137 | } 138 | 139 | // Comment for AnotherTestMessage extensions (3) 140 | extend AnotherTestMessage { 141 | // Comment for xi 142 | optional int32 xi = 102; 143 | 144 | // Comment for xui 145 | optional uint64 xui = 103; 146 | } 147 | 148 | // Comment for SomeEnum 149 | enum SomeEnum { 150 | // Comment for SOME_VAL 151 | SOME_VAL = 0; 152 | 153 | // Comment for ANOTHER_VAL 154 | ANOTHER_VAL = 1; 155 | 156 | // Comment for YET_ANOTHER_VAL 157 | YET_ANOTHER_VAL = 2; 158 | } 159 | 160 | // Comment for SomeService 161 | service SomeService { 162 | // Comment for SomeMethod 163 | rpc SomeMethod ( TestMessage ) returns ( TestMessage ); 164 | 165 | // Comment for SomeOtherMethod 166 | rpc SomeOtherMethod ( AnotherTestMessage ) returns ( AnotherTestMessage ); 167 | } 168 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test1-trailing-on-next-line.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | 5 | package testprotos; 6 | 7 | // Comment for TestMessage 8 | message TestMessage { 9 | // Comment for NestedMessage 10 | message NestedMessage { 11 | // Comment for AnotherNestedMessage 12 | message AnotherNestedMessage { 13 | // Comment for AnotherTestMessage extensions (1) 14 | extend AnotherTestMessage { 15 | // Comment for flags 16 | repeated bool flags = 200 [packed = true]; 17 | } 18 | 19 | // Comment for YetAnotherNestedMessage 20 | message YetAnotherNestedMessage { 21 | // Comment for DeeplyNestedEnum 22 | enum DeeplyNestedEnum { 23 | // Comment for VALUE1 24 | VALUE1 = 1; 25 | 26 | // Comment for VALUE2 27 | VALUE2 = 2; 28 | } 29 | 30 | // Comment for foo 31 | optional string foo = 1; 32 | 33 | // Comment for bar 34 | optional int32 bar = 2; 35 | 36 | // Comment for baz 37 | optional bytes baz = 3; 38 | 39 | // Comment for dne 40 | optional DeeplyNestedEnum dne = 4; 41 | 42 | // Comment for anm 43 | optional AnotherNestedMessage anm = 5; 44 | 45 | // Comment for nm 46 | optional NestedMessage nm = 6; 47 | 48 | // Comment for tm 49 | optional TestMessage tm = 7; 50 | } 51 | 52 | // Comment for yanm 53 | repeated YetAnotherNestedMessage yanm = 1; 54 | } 55 | 56 | // Comment for anm 57 | optional AnotherNestedMessage anm = 1; 58 | 59 | // Comment for yanm 60 | optional AnotherNestedMessage.YetAnotherNestedMessage yanm = 2; 61 | } 62 | 63 | // Comment for NestedEnum 64 | enum NestedEnum { 65 | // Comment for VALUE1 66 | VALUE1 = 1; 67 | 68 | // Comment for VALUE2 69 | VALUE2 = 2; 70 | } 71 | 72 | // Comment for nm 73 | optional NestedMessage nm = 1; 74 | 75 | // Comment for anm 76 | optional NestedMessage.AnotherNestedMessage anm = 2; 77 | 78 | // Comment for yanm 79 | optional NestedMessage.AnotherNestedMessage.YetAnotherNestedMessage yanm = 3; 80 | 81 | // Comment for ne 82 | repeated NestedEnum ne = 4; 83 | } 84 | 85 | // Comment for AnotherTestMessage 86 | message AnotherTestMessage { 87 | // Comment for dne 88 | optional TestMessage.NestedMessage.AnotherNestedMessage.YetAnotherNestedMessage.DeeplyNestedEnum dne = 1; 89 | 90 | // Comment for map_field1 91 | map map_field1 = 2; 92 | 93 | // Comment for map_field2 94 | map map_field2 = 3; 95 | 96 | // Comment for map_field3 97 | map map_field3 = 4; 98 | 99 | // Comment for map_field4 100 | map map_field4 = 5; 101 | 102 | // Comment for RockNRoll 103 | optional group RockNRoll = 6 { 104 | // Comment for beatles 105 | optional string beatles = 1; 106 | 107 | // Comment for stones 108 | optional string stones = 2; 109 | 110 | // Comment for doors 111 | optional string doors = 3; 112 | } 113 | 114 | // Comment for atmoo 115 | oneof atmoo { 116 | // Comment for str 117 | string str = 7; 118 | 119 | // Comment for int 120 | int64 int = 8; 121 | } 122 | 123 | // Comment for WithOptions 124 | optional group WithOptions = 9 [deprecated = true] { 125 | } 126 | 127 | extensions 100 to 200; 128 | } 129 | 130 | // Comment for AnotherTestMessage extensions (2) 131 | extend AnotherTestMessage { 132 | // Comment for xtm 133 | optional TestMessage xtm = 100; 134 | 135 | // Comment for xs 136 | optional string xs = 101; 137 | } 138 | 139 | // Comment for AnotherTestMessage extensions (3) 140 | extend AnotherTestMessage { 141 | // Comment for xi 142 | optional int32 xi = 102; 143 | 144 | // Comment for xui 145 | optional uint64 xui = 103; 146 | } 147 | 148 | // Comment for SomeEnum 149 | enum SomeEnum { 150 | // Comment for SOME_VAL 151 | SOME_VAL = 0; 152 | 153 | // Comment for ANOTHER_VAL 154 | ANOTHER_VAL = 1; 155 | 156 | // Comment for YET_ANOTHER_VAL 157 | YET_ANOTHER_VAL = 2; 158 | } 159 | 160 | // Comment for SomeService 161 | service SomeService { 162 | // Comment for SomeMethod 163 | rpc SomeMethod ( TestMessage ) returns ( TestMessage ); 164 | 165 | // Comment for SomeOtherMethod 166 | rpc SomeOtherMethod ( AnotherTestMessage ) returns ( AnotherTestMessage ); 167 | } 168 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test2-compact.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package testprotos; 3 | import "desc_test1.proto"; 4 | import "pkg/desc_test_pkg.proto"; 5 | import "nopkg/desc_test_nopkg.proto"; 6 | option cc_enable_arenas = true; 7 | option csharp_namespace = "jhump.protoreflect.testprotos"; 8 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 9 | option java_generate_equals_and_hash = true; 10 | option java_multiple_files = true; 11 | option java_package = "com.github.jhump.protoreflect.internal.testprotos"; 12 | option ruby_package = "protoreflect-testprotos"; 13 | message Frobnitz { 14 | optional TestMessage a = 1; 15 | optional AnotherTestMessage b = 2; 16 | oneof abc { 17 | TestMessage.NestedMessage c1 = 3; 18 | TestMessage.NestedEnum c2 = 4; 19 | } 20 | optional TestMessage.NestedMessage d = 5; 21 | optional TestMessage.NestedEnum e = 6 [default = VALUE2]; 22 | repeated string f = 7 [deprecated = true]; 23 | oneof def { 24 | int32 g1 = 8; 25 | sint32 g2 = 9; 26 | uint32 g3 = 10; 27 | } 28 | } 29 | message Whatchamacallit { 30 | required jhump.protoreflect.desc.Foo foos = 1; 31 | } 32 | message Whatzit { 33 | repeated jhump.protoreflect.desc.Bar gyzmeau = 1; 34 | } 35 | extend TopLevel { 36 | optional TopLevel otl = 100; 37 | optional group GroupX = 104 { 38 | optional int64 groupxi = 1041; 39 | optional string groupxs = 1042; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test2-custom-sort.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | extend TopLevel { 4 | optional TopLevel otl = 100; 5 | 6 | optional group GroupX = 104 { 7 | optional string groupxs = 1042; 8 | 9 | optional int64 groupxi = 1041; 10 | } 11 | } 12 | 13 | message Whatzit { 14 | repeated jhump.protoreflect.desc.Bar gyzmeau = 1; 15 | } 16 | 17 | message Whatchamacallit { 18 | required jhump.protoreflect.desc.Foo foos = 1; 19 | } 20 | 21 | message Frobnitz { 22 | oneof def { 23 | uint32 g3 = 10; 24 | 25 | sint32 g2 = 9; 26 | 27 | int32 g1 = 8; 28 | } 29 | 30 | repeated string f = 7 [deprecated = true]; 31 | 32 | optional TestMessage.NestedEnum e = 6 [default = VALUE2]; 33 | 34 | optional TestMessage.NestedMessage d = 5; 35 | 36 | oneof abc { 37 | TestMessage.NestedEnum c2 = 4; 38 | 39 | TestMessage.NestedMessage c1 = 3; 40 | } 41 | 42 | optional AnotherTestMessage b = 2; 43 | 44 | optional TestMessage a = 1; 45 | } 46 | 47 | option ruby_package = "protoreflect-testprotos"; 48 | 49 | option java_package = "com.github.jhump.protoreflect.internal.testprotos"; 50 | 51 | option java_multiple_files = true; 52 | 53 | option java_generate_equals_and_hash = true; 54 | 55 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 56 | 57 | option csharp_namespace = "jhump.protoreflect.testprotos"; 58 | 59 | option cc_enable_arenas = true; 60 | 61 | import "pkg/desc_test_pkg.proto"; 62 | 63 | import "nopkg/desc_test_nopkg.proto"; 64 | 65 | import "desc_test1.proto"; 66 | 67 | package testprotos; 68 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test2-default.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package testprotos; 4 | 5 | import "desc_test1.proto"; 6 | 7 | import "pkg/desc_test_pkg.proto"; 8 | 9 | import "nopkg/desc_test_nopkg.proto"; 10 | 11 | option cc_enable_arenas = true; 12 | 13 | option csharp_namespace = "jhump.protoreflect.testprotos"; 14 | 15 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 16 | 17 | option java_generate_equals_and_hash = true; 18 | 19 | option java_multiple_files = true; 20 | 21 | option java_package = "com.github.jhump.protoreflect.internal.testprotos"; 22 | 23 | option ruby_package = "protoreflect-testprotos"; 24 | 25 | message Frobnitz { 26 | optional TestMessage a = 1; 27 | 28 | optional AnotherTestMessage b = 2; 29 | 30 | oneof abc { 31 | TestMessage.NestedMessage c1 = 3; 32 | 33 | TestMessage.NestedEnum c2 = 4; 34 | } 35 | 36 | optional TestMessage.NestedMessage d = 5; 37 | 38 | optional TestMessage.NestedEnum e = 6 [default = VALUE2]; 39 | 40 | repeated string f = 7 [deprecated = true]; 41 | 42 | oneof def { 43 | int32 g1 = 8; 44 | 45 | sint32 g2 = 9; 46 | 47 | uint32 g3 = 10; 48 | } 49 | } 50 | 51 | message Whatchamacallit { 52 | required jhump.protoreflect.desc.Foo foos = 1; 53 | } 54 | 55 | message Whatzit { 56 | repeated jhump.protoreflect.desc.Bar gyzmeau = 1; 57 | } 58 | 59 | extend TopLevel { 60 | optional TopLevel otl = 100; 61 | 62 | optional group GroupX = 104 { 63 | optional int64 groupxi = 1041; 64 | 65 | optional string groupxs = 1042; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test2-multiline-style-comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package testprotos; 4 | 5 | import "desc_test1.proto"; 6 | 7 | import "pkg/desc_test_pkg.proto"; 8 | 9 | import "nopkg/desc_test_nopkg.proto"; 10 | 11 | option cc_enable_arenas = true; 12 | 13 | option csharp_namespace = "jhump.protoreflect.testprotos"; 14 | 15 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 16 | 17 | option java_generate_equals_and_hash = true; 18 | 19 | option java_multiple_files = true; 20 | 21 | option java_package = "com.github.jhump.protoreflect.internal.testprotos"; 22 | 23 | option ruby_package = "protoreflect-testprotos"; 24 | 25 | message Frobnitz { 26 | optional TestMessage a = 1; 27 | 28 | optional AnotherTestMessage b = 2; 29 | 30 | oneof abc { 31 | TestMessage.NestedMessage c1 = 3; 32 | 33 | TestMessage.NestedEnum c2 = 4; 34 | } 35 | 36 | optional TestMessage.NestedMessage d = 5; 37 | 38 | optional TestMessage.NestedEnum e = 6 [default = VALUE2]; 39 | 40 | repeated string f = 7 [deprecated = true]; 41 | 42 | oneof def { 43 | int32 g1 = 8; 44 | 45 | sint32 g2 = 9; 46 | 47 | uint32 g3 = 10; 48 | } 49 | } 50 | 51 | message Whatchamacallit { 52 | required jhump.protoreflect.desc.Foo foos = 1; 53 | } 54 | 55 | message Whatzit { 56 | repeated jhump.protoreflect.desc.Bar gyzmeau = 1; 57 | } 58 | 59 | extend TopLevel { 60 | optional TopLevel otl = 100; 61 | 62 | optional group GroupX = 104 { 63 | optional int64 groupxi = 1041; 64 | 65 | optional string groupxs = 1042; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test2-no-trailing-comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package testprotos; 4 | 5 | import "desc_test1.proto"; 6 | 7 | import "pkg/desc_test_pkg.proto"; 8 | 9 | import "nopkg/desc_test_nopkg.proto"; 10 | 11 | option cc_enable_arenas = true; 12 | 13 | option csharp_namespace = "jhump.protoreflect.testprotos"; 14 | 15 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 16 | 17 | option java_generate_equals_and_hash = true; 18 | 19 | option java_multiple_files = true; 20 | 21 | option java_package = "com.github.jhump.protoreflect.internal.testprotos"; 22 | 23 | option ruby_package = "protoreflect-testprotos"; 24 | 25 | message Frobnitz { 26 | optional TestMessage a = 1; 27 | 28 | optional AnotherTestMessage b = 2; 29 | 30 | oneof abc { 31 | TestMessage.NestedMessage c1 = 3; 32 | 33 | TestMessage.NestedEnum c2 = 4; 34 | } 35 | 36 | optional TestMessage.NestedMessage d = 5; 37 | 38 | optional TestMessage.NestedEnum e = 6 [default = VALUE2]; 39 | 40 | repeated string f = 7 [deprecated = true]; 41 | 42 | oneof def { 43 | int32 g1 = 8; 44 | 45 | sint32 g2 = 9; 46 | 47 | uint32 g3 = 10; 48 | } 49 | } 50 | 51 | message Whatchamacallit { 52 | required jhump.protoreflect.desc.Foo foos = 1; 53 | } 54 | 55 | message Whatzit { 56 | repeated jhump.protoreflect.desc.Bar gyzmeau = 1; 57 | } 58 | 59 | extend TopLevel { 60 | optional TopLevel otl = 100; 61 | 62 | optional group GroupX = 104 { 63 | optional int64 groupxi = 1041; 64 | 65 | optional string groupxs = 1042; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test2-only-doc-comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package testprotos; 4 | 5 | import "desc_test1.proto"; 6 | 7 | import "pkg/desc_test_pkg.proto"; 8 | 9 | import "nopkg/desc_test_nopkg.proto"; 10 | 11 | option cc_enable_arenas = true; 12 | 13 | option csharp_namespace = "jhump.protoreflect.testprotos"; 14 | 15 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 16 | 17 | option java_generate_equals_and_hash = true; 18 | 19 | option java_multiple_files = true; 20 | 21 | option java_package = "com.github.jhump.protoreflect.internal.testprotos"; 22 | 23 | option ruby_package = "protoreflect-testprotos"; 24 | 25 | message Frobnitz { 26 | optional TestMessage a = 1; 27 | 28 | optional AnotherTestMessage b = 2; 29 | 30 | oneof abc { 31 | TestMessage.NestedMessage c1 = 3; 32 | 33 | TestMessage.NestedEnum c2 = 4; 34 | } 35 | 36 | optional TestMessage.NestedMessage d = 5; 37 | 38 | optional TestMessage.NestedEnum e = 6 [default = VALUE2]; 39 | 40 | repeated string f = 7 [deprecated = true]; 41 | 42 | oneof def { 43 | int32 g1 = 8; 44 | 45 | sint32 g2 = 9; 46 | 47 | uint32 g3 = 10; 48 | } 49 | } 50 | 51 | message Whatchamacallit { 52 | required jhump.protoreflect.desc.Foo foos = 1; 53 | } 54 | 55 | message Whatzit { 56 | repeated jhump.protoreflect.desc.Bar gyzmeau = 1; 57 | } 58 | 59 | extend TopLevel { 60 | optional TopLevel otl = 100; 61 | 62 | optional group GroupX = 104 { 63 | optional int64 groupxi = 1041; 64 | 65 | optional string groupxs = 1042; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test2-sorted-AND-multiline-style-comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package testprotos; 4 | 5 | import "desc_test1.proto"; 6 | 7 | import "nopkg/desc_test_nopkg.proto"; 8 | 9 | import "pkg/desc_test_pkg.proto"; 10 | 11 | option cc_enable_arenas = true; 12 | 13 | option csharp_namespace = "jhump.protoreflect.testprotos"; 14 | 15 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 16 | 17 | option java_generate_equals_and_hash = true; 18 | 19 | option java_multiple_files = true; 20 | 21 | option java_package = "com.github.jhump.protoreflect.internal.testprotos"; 22 | 23 | option ruby_package = "protoreflect-testprotos"; 24 | 25 | message Frobnitz { 26 | optional TestMessage a = 1; 27 | 28 | optional AnotherTestMessage b = 2; 29 | 30 | oneof abc { 31 | TestMessage.NestedMessage c1 = 3; 32 | 33 | TestMessage.NestedEnum c2 = 4; 34 | } 35 | 36 | optional TestMessage.NestedMessage d = 5; 37 | 38 | optional TestMessage.NestedEnum e = 6 [default = VALUE2]; 39 | 40 | repeated string f = 7 [deprecated = true]; 41 | 42 | oneof def { 43 | int32 g1 = 8; 44 | 45 | sint32 g2 = 9; 46 | 47 | uint32 g3 = 10; 48 | } 49 | } 50 | 51 | message Whatchamacallit { 52 | required jhump.protoreflect.desc.Foo foos = 1; 53 | } 54 | 55 | message Whatzit { 56 | repeated jhump.protoreflect.desc.Bar gyzmeau = 1; 57 | } 58 | 59 | extend TopLevel { 60 | optional TopLevel otl = 100; 61 | 62 | optional group GroupX = 104 { 63 | optional int64 groupxi = 1041; 64 | 65 | optional string groupxs = 1042; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test2-sorted.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package testprotos; 4 | 5 | import "desc_test1.proto"; 6 | 7 | import "nopkg/desc_test_nopkg.proto"; 8 | 9 | import "pkg/desc_test_pkg.proto"; 10 | 11 | option cc_enable_arenas = true; 12 | 13 | option csharp_namespace = "jhump.protoreflect.testprotos"; 14 | 15 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 16 | 17 | option java_generate_equals_and_hash = true; 18 | 19 | option java_multiple_files = true; 20 | 21 | option java_package = "com.github.jhump.protoreflect.internal.testprotos"; 22 | 23 | option ruby_package = "protoreflect-testprotos"; 24 | 25 | message Frobnitz { 26 | optional TestMessage a = 1; 27 | 28 | optional AnotherTestMessage b = 2; 29 | 30 | oneof abc { 31 | TestMessage.NestedMessage c1 = 3; 32 | 33 | TestMessage.NestedEnum c2 = 4; 34 | } 35 | 36 | optional TestMessage.NestedMessage d = 5; 37 | 38 | optional TestMessage.NestedEnum e = 6 [default = VALUE2]; 39 | 40 | repeated string f = 7 [deprecated = true]; 41 | 42 | oneof def { 43 | int32 g1 = 8; 44 | 45 | sint32 g2 = 9; 46 | 47 | uint32 g3 = 10; 48 | } 49 | } 50 | 51 | message Whatchamacallit { 52 | required jhump.protoreflect.desc.Foo foos = 1; 53 | } 54 | 55 | message Whatzit { 56 | repeated jhump.protoreflect.desc.Bar gyzmeau = 1; 57 | } 58 | 59 | extend TopLevel { 60 | optional TopLevel otl = 100; 61 | 62 | optional group GroupX = 104 { 63 | optional int64 groupxi = 1041; 64 | 65 | optional string groupxs = 1042; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test2-trailing-on-next-line.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package testprotos; 4 | 5 | import "desc_test1.proto"; 6 | 7 | import "pkg/desc_test_pkg.proto"; 8 | 9 | import "nopkg/desc_test_nopkg.proto"; 10 | 11 | option cc_enable_arenas = true; 12 | 13 | option csharp_namespace = "jhump.protoreflect.testprotos"; 14 | 15 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 16 | 17 | option java_generate_equals_and_hash = true; 18 | 19 | option java_multiple_files = true; 20 | 21 | option java_package = "com.github.jhump.protoreflect.internal.testprotos"; 22 | 23 | option ruby_package = "protoreflect-testprotos"; 24 | 25 | message Frobnitz { 26 | optional TestMessage a = 1; 27 | 28 | optional AnotherTestMessage b = 2; 29 | 30 | oneof abc { 31 | TestMessage.NestedMessage c1 = 3; 32 | 33 | TestMessage.NestedEnum c2 = 4; 34 | } 35 | 36 | optional TestMessage.NestedMessage d = 5; 37 | 38 | optional TestMessage.NestedEnum e = 6 [default = VALUE2]; 39 | 40 | repeated string f = 7 [deprecated = true]; 41 | 42 | oneof def { 43 | int32 g1 = 8; 44 | 45 | sint32 g2 = 9; 46 | 47 | uint32 g3 = 10; 48 | } 49 | } 50 | 51 | message Whatchamacallit { 52 | required jhump.protoreflect.desc.Foo foos = 1; 53 | } 54 | 55 | message Whatzit { 56 | repeated jhump.protoreflect.desc.Bar gyzmeau = 1; 57 | } 58 | 59 | extend TopLevel { 60 | optional TopLevel otl = 100; 61 | 62 | optional group GroupX = 104 { 63 | optional int64 groupxi = 1041; 64 | 65 | optional string groupxs = 1042; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_comments-compact.proto: -------------------------------------------------------------------------------- 1 | // This is the first detached comment for the syntax. 2 | // This is a second detached comment. 3 | // This is a third. 4 | // Syntax comment... 5 | syntax = "proto2"; // Syntax trailer. 6 | // And now the package declaration 7 | package foo.bar; 8 | // option comments FTW!!! 9 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 10 | import public "google/protobuf/empty.proto"; 11 | import "desc_test_options.proto"; 12 | // Multiple white space lines (like above) cannot 13 | // be preserved... 14 | // We need a request for our RPC service below. 15 | message Request { 16 | option deprecated = true; // deprecated! 17 | // A field comment 18 | repeated int32 ids = 1 [packed = true, json_name = "|foo|", (testprotos.ffubar) = "abc", (testprotos.ffubarb) = "xyz"]; // field trailer #1... 19 | // lead mfubar 20 | option (testprotos.mfubar) = true; // trailing mfubar 21 | // some detached comments 22 | // some detached comments with unicode 这个是值 23 | // Another field comment 24 | // label comment 25 | optional string name = 2 [default = "fubar"]; 26 | extensions 100 to 200; 27 | extensions 201 to 250 [(testprotos.exfubarb) = "\000\001\002\003\004\005\006\007", (testprotos.exfubar) = "splat!"]; 28 | reserved 10 to 20, 30 to 50; 29 | reserved "foo", "bar", "baz"; 30 | // Group comment with emoji 😀 😍 👻 ❤ 💯 💥 🐶 🦂 🥑 🍻 🌍 🚕 🪐 31 | optional group Extras = 3 { 32 | // trailer for Extras 33 | // this is a custom option 34 | option (testprotos.mfubar) = false; 35 | optional double dbl = 1; 36 | optional float flt = 2; 37 | option no_standard_descriptor_accessor = false; 38 | // Leading comment... 39 | optional string str = 3; // Trailing comment... 40 | } 41 | enum MarioCharacters { 42 | // trailer for enum 43 | // allow_alias comments! 44 | option allow_alias = true; 45 | MARIO = 1 [(testprotos.evfubars) = -314, (testprotos.evfubar) = 278]; 46 | LUIGI = 2 [(testprotos.evfubaruf) = 100, (testprotos.evfubaru) = 200]; 47 | PEACH = 3; 48 | BOWSER = 4; 49 | option (testprotos.efubars) = -321; 50 | WARIO = 5; 51 | WALUIGI = 6; 52 | SHY_GUY = 7 [(testprotos.evfubarsf) = 10101]; 53 | HEY_HO = 7; 54 | MAGIKOOPA = 8; 55 | KAMEK = 8; 56 | SNIFIT = -101; 57 | option (testprotos.efubar) = 123; 58 | } 59 | // can be this or that 60 | oneof abc { 61 | // trailer for oneof abc 62 | string this = 4; 63 | int32 that = 5; 64 | } 65 | // can be these or those 66 | oneof xyz { 67 | // whoops? 68 | option (testprotos.oofubar) = "whoops, this has invalid UTF8! \274\377"; 69 | string these = 6; 70 | int32 those = 7; 71 | } 72 | // map field 73 | map things = 8; 74 | } 75 | // And next we'll need some extensions... 76 | extend Request { 77 | // trailer for extend block 78 | // comment for guid1 79 | optional uint64 guid1 = 123; 80 | // ... and a comment for guid2 81 | optional uint64 guid2 = 124; 82 | } 83 | message AnEmptyMessage { 84 | } 85 | // Service comment 86 | service RpcService { 87 | // service trailer 88 | // that spans multiple lines 89 | // option that sets field 90 | option (testprotos.sfubar) = { id: 100, name: "bob" }; 91 | option deprecated = false; // DEPRECATED! 92 | option (testprotos.sfubare) = VALUE; 93 | // Method comment 94 | rpc StreamingRpc ( stream Request ) returns ( Request ); // compact method trailer 95 | rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) { 96 | // trailer for method 97 | // this RPC is deprecated! 98 | option deprecated = true; 99 | option (testprotos.mtfubar) = 12.340000; 100 | option (testprotos.mtfubard) = 123.456000; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_comments-custom-sort.proto: -------------------------------------------------------------------------------- 1 | // This is the first detached comment for the syntax. 2 | 3 | // This is a second detached comment. 4 | 5 | // This is a third. 6 | 7 | // Syntax comment... 8 | syntax = "proto2"; // Syntax trailer. 9 | 10 | // And next we'll need some extensions... 11 | 12 | extend Request { 13 | // trailer for extend block 14 | 15 | // ... and a comment for guid2 16 | optional uint64 guid2 = 124; 17 | 18 | // comment for guid1 19 | optional uint64 guid1 = 123; 20 | } 21 | 22 | // Service comment 23 | service RpcService { 24 | // service trailer 25 | // that spans multiple lines 26 | 27 | rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) { 28 | // trailer for method 29 | 30 | option (testprotos.mtfubard) = 123.456000; 31 | 32 | option (testprotos.mtfubar) = 12.340000; 33 | 34 | // this RPC is deprecated! 35 | option deprecated = true; 36 | } 37 | 38 | // Method comment 39 | rpc StreamingRpc ( stream Request ) returns ( Request ); // compact method trailer 40 | 41 | option (testprotos.sfubare) = VALUE; 42 | 43 | // option that sets field 44 | option (testprotos.sfubar) = { id: 100, name: "bob" }; 45 | 46 | option deprecated = false; // DEPRECATED! 47 | } 48 | 49 | // Multiple white space lines (like above) cannot 50 | // be preserved... 51 | 52 | // We need a request for our RPC service below. 53 | message Request { 54 | reserved "foo", "baz", "bar"; 55 | 56 | reserved 30 to 50, 10 to 20; 57 | 58 | extensions 201 to 250 [ 59 | (testprotos.exfubarb) = "\000\001\002\003\004\005\006\007", 60 | (testprotos.exfubar) = "splat!" 61 | ]; 62 | 63 | extensions 100 to 200; 64 | 65 | enum MarioCharacters { 66 | // trailer for enum 67 | 68 | WARIO = 5; 69 | 70 | WALUIGI = 6; 71 | 72 | SNIFIT = -101; 73 | 74 | SHY_GUY = 7 [(testprotos.evfubarsf) = 10101]; 75 | 76 | PEACH = 3; 77 | 78 | MARIO = 1 [ 79 | (testprotos.evfubars) = -314, 80 | (testprotos.evfubar) = 278 81 | ]; 82 | 83 | MAGIKOOPA = 8; 84 | 85 | LUIGI = 2 [ 86 | (testprotos.evfubaruf) = 100, 87 | (testprotos.evfubaru) = 200 88 | ]; 89 | 90 | KAMEK = 8; 91 | 92 | HEY_HO = 7; 93 | 94 | BOWSER = 4; 95 | 96 | option (testprotos.efubars) = -321; 97 | 98 | option (testprotos.efubar) = 123; 99 | 100 | // allow_alias comments! 101 | option allow_alias = true; 102 | } 103 | 104 | // can be these or those 105 | oneof xyz { 106 | int32 those = 7; 107 | 108 | string these = 6; 109 | 110 | // whoops? 111 | option (testprotos.oofubar) = "whoops, this has invalid UTF8! \274\377"; 112 | } 113 | 114 | // can be this or that 115 | oneof abc { 116 | // trailer for oneof abc 117 | 118 | string this = 4; 119 | 120 | int32 that = 5; 121 | } 122 | 123 | // map field 124 | map things = 8; 125 | 126 | // some detached comments 127 | 128 | // some detached comments with unicode 这个是值 129 | 130 | // Another field comment 131 | 132 | // label comment 133 | optional string name = 2 [default = "fubar"]; 134 | 135 | // A field comment 136 | repeated int32 ids = 1 [ 137 | (testprotos.ffubarb) = "xyz", 138 | (testprotos.ffubar) = "abc", 139 | packed = true, 140 | json_name = "|foo|" 141 | ]; // field trailer #1... 142 | 143 | // Group comment with emoji 😀 😍 👻 ❤ 💯 💥 🐶 🦂 🥑 🍻 🌍 🚕 🪐 144 | optional group Extras = 3 { 145 | // trailer for Extras 146 | 147 | // Leading comment... 148 | optional string str = 3; // Trailing comment... 149 | 150 | optional float flt = 2; 151 | 152 | optional double dbl = 1; 153 | 154 | // this is a custom option 155 | option (testprotos.mfubar) = false; 156 | 157 | option no_standard_descriptor_accessor = false; 158 | } 159 | 160 | // lead mfubar 161 | option (testprotos.mfubar) = true; // trailing mfubar 162 | 163 | option deprecated = true; // deprecated! 164 | } 165 | 166 | message AnEmptyMessage { 167 | } 168 | 169 | // option comments FTW!!! 170 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 171 | 172 | import public "google/protobuf/empty.proto"; 173 | 174 | import "desc_test_options.proto"; 175 | 176 | // And now the package declaration 177 | package foo.bar; 178 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_comments-default.proto: -------------------------------------------------------------------------------- 1 | // This is the first detached comment for the syntax. 2 | 3 | // This is a second detached comment. 4 | 5 | // This is a third. 6 | 7 | // Syntax comment... 8 | syntax = "proto2"; // Syntax trailer. 9 | 10 | // And now the package declaration 11 | package foo.bar; 12 | 13 | // option comments FTW!!! 14 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 15 | 16 | import public "google/protobuf/empty.proto"; 17 | 18 | import "desc_test_options.proto"; 19 | 20 | // Multiple white space lines (like above) cannot 21 | // be preserved... 22 | 23 | // We need a request for our RPC service below. 24 | message Request { 25 | option deprecated = true; // deprecated! 26 | 27 | // A field comment 28 | repeated int32 ids = 1 [ 29 | packed = true, 30 | json_name = "|foo|", 31 | (testprotos.ffubar) = "abc", 32 | (testprotos.ffubarb) = "xyz" 33 | ]; // field trailer #1... 34 | 35 | // lead mfubar 36 | option (testprotos.mfubar) = true; // trailing mfubar 37 | 38 | // some detached comments 39 | 40 | // some detached comments with unicode 这个是值 41 | 42 | // Another field comment 43 | 44 | // label comment 45 | optional string name = 2 [default = "fubar"]; 46 | 47 | extensions 100 to 200; 48 | 49 | extensions 201 to 250 [ 50 | (testprotos.exfubarb) = "\000\001\002\003\004\005\006\007", 51 | (testprotos.exfubar) = "splat!" 52 | ]; 53 | 54 | reserved 10 to 20, 30 to 50; 55 | 56 | reserved "foo", "bar", "baz"; 57 | 58 | // Group comment with emoji 😀 😍 👻 ❤ 💯 💥 🐶 🦂 🥑 🍻 🌍 🚕 🪐 59 | optional group Extras = 3 { 60 | // trailer for Extras 61 | 62 | // this is a custom option 63 | option (testprotos.mfubar) = false; 64 | 65 | optional double dbl = 1; 66 | 67 | optional float flt = 2; 68 | 69 | option no_standard_descriptor_accessor = false; 70 | 71 | // Leading comment... 72 | optional string str = 3; // Trailing comment... 73 | } 74 | 75 | enum MarioCharacters { 76 | // trailer for enum 77 | 78 | // allow_alias comments! 79 | option allow_alias = true; 80 | 81 | MARIO = 1 [ 82 | (testprotos.evfubars) = -314, 83 | (testprotos.evfubar) = 278 84 | ]; 85 | 86 | LUIGI = 2 [ 87 | (testprotos.evfubaruf) = 100, 88 | (testprotos.evfubaru) = 200 89 | ]; 90 | 91 | PEACH = 3; 92 | 93 | BOWSER = 4; 94 | 95 | option (testprotos.efubars) = -321; 96 | 97 | WARIO = 5; 98 | 99 | WALUIGI = 6; 100 | 101 | SHY_GUY = 7 [(testprotos.evfubarsf) = 10101]; 102 | 103 | HEY_HO = 7; 104 | 105 | MAGIKOOPA = 8; 106 | 107 | KAMEK = 8; 108 | 109 | SNIFIT = -101; 110 | 111 | option (testprotos.efubar) = 123; 112 | } 113 | 114 | // can be this or that 115 | oneof abc { 116 | // trailer for oneof abc 117 | 118 | string this = 4; 119 | 120 | int32 that = 5; 121 | } 122 | 123 | // can be these or those 124 | oneof xyz { 125 | // whoops? 126 | option (testprotos.oofubar) = "whoops, this has invalid UTF8! \274\377"; 127 | 128 | string these = 6; 129 | 130 | int32 those = 7; 131 | } 132 | 133 | // map field 134 | map things = 8; 135 | } 136 | 137 | // And next we'll need some extensions... 138 | 139 | extend Request { 140 | // trailer for extend block 141 | 142 | // comment for guid1 143 | optional uint64 guid1 = 123; 144 | 145 | // ... and a comment for guid2 146 | optional uint64 guid2 = 124; 147 | } 148 | 149 | message AnEmptyMessage { 150 | } 151 | 152 | // Service comment 153 | service RpcService { 154 | // service trailer 155 | // that spans multiple lines 156 | 157 | // option that sets field 158 | option (testprotos.sfubar) = { id: 100, name: "bob" }; 159 | 160 | option deprecated = false; // DEPRECATED! 161 | 162 | option (testprotos.sfubare) = VALUE; 163 | 164 | // Method comment 165 | rpc StreamingRpc ( stream Request ) returns ( Request ); // compact method trailer 166 | 167 | rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) { 168 | // trailer for method 169 | 170 | // this RPC is deprecated! 171 | option deprecated = true; 172 | 173 | option (testprotos.mtfubar) = 12.340000; 174 | 175 | option (testprotos.mtfubard) = 123.456000; 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_comments-multiline-style-comments.proto: -------------------------------------------------------------------------------- 1 | /* This is the first detached comment for the syntax. */ 2 | 3 | /* This is a second detached comment. */ 4 | 5 | /* This is a third. */ 6 | 7 | /* Syntax comment... */ 8 | syntax = "proto2"; /* Syntax trailer. */ 9 | 10 | /* And now the package declaration */ 11 | package foo.bar; 12 | 13 | /* option comments FTW!!! */ 14 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 15 | 16 | import public "google/protobuf/empty.proto"; 17 | 18 | import "desc_test_options.proto"; 19 | 20 | /* 21 | * Multiple white space lines (like above) cannot 22 | * be preserved... 23 | */ 24 | 25 | /* We need a request for our RPC service below. */ 26 | message Request { 27 | option deprecated = true; /* deprecated! */ 28 | 29 | /* A field comment */ 30 | repeated int32 ids = 1 [ 31 | packed = true, 32 | json_name = "|foo|", 33 | (testprotos.ffubar) = "abc", 34 | (testprotos.ffubarb) = "xyz" 35 | ]; /* field trailer #1... */ 36 | 37 | /* lead mfubar */ 38 | option (testprotos.mfubar) = true; /* trailing mfubar */ 39 | 40 | /* some detached comments */ 41 | 42 | /* some detached comments with unicode 这个是值 */ 43 | 44 | /* Another field comment */ 45 | 46 | /* label comment */ 47 | optional string name = 2 [default = "fubar"]; 48 | 49 | extensions 100 to 200; 50 | 51 | extensions 201 to 250 [ 52 | (testprotos.exfubarb) = "\000\001\002\003\004\005\006\007", 53 | (testprotos.exfubar) = "splat!" 54 | ]; 55 | 56 | reserved 10 to 20, 30 to 50; 57 | 58 | reserved "foo", "bar", "baz"; 59 | 60 | /* Group comment with emoji 😀 😍 👻 ❤ 💯 💥 🐶 🦂 🥑 🍻 🌍 🚕 🪐 */ 61 | optional group Extras = 3 { 62 | /* trailer for Extras */ 63 | 64 | /* this is a custom option */ 65 | option (testprotos.mfubar) = false; 66 | 67 | optional double dbl = 1; 68 | 69 | optional float flt = 2; 70 | 71 | option no_standard_descriptor_accessor = false; 72 | 73 | /* Leading comment... */ 74 | optional string str = 3; /* Trailing comment... */ 75 | } 76 | 77 | enum MarioCharacters { 78 | /* trailer for enum */ 79 | 80 | /* allow_alias comments! */ 81 | option allow_alias = true; 82 | 83 | MARIO = 1 [ 84 | (testprotos.evfubars) = -314, 85 | (testprotos.evfubar) = 278 86 | ]; 87 | 88 | LUIGI = 2 [ 89 | (testprotos.evfubaruf) = 100, 90 | (testprotos.evfubaru) = 200 91 | ]; 92 | 93 | PEACH = 3; 94 | 95 | BOWSER = 4; 96 | 97 | option (testprotos.efubars) = -321; 98 | 99 | WARIO = 5; 100 | 101 | WALUIGI = 6; 102 | 103 | SHY_GUY = 7 [(testprotos.evfubarsf) = 10101]; 104 | 105 | HEY_HO = 7; 106 | 107 | MAGIKOOPA = 8; 108 | 109 | KAMEK = 8; 110 | 111 | SNIFIT = -101; 112 | 113 | option (testprotos.efubar) = 123; 114 | } 115 | 116 | /* can be this or that */ 117 | oneof abc { 118 | /* trailer for oneof abc */ 119 | 120 | string this = 4; 121 | 122 | int32 that = 5; 123 | } 124 | 125 | /* can be these or those */ 126 | oneof xyz { 127 | /* whoops? */ 128 | option (testprotos.oofubar) = "whoops, this has invalid UTF8! \274\377"; 129 | 130 | string these = 6; 131 | 132 | int32 those = 7; 133 | } 134 | 135 | /* map field */ 136 | map things = 8; 137 | } 138 | 139 | /* And next we'll need some extensions... */ 140 | 141 | extend Request { 142 | /* trailer for extend block */ 143 | 144 | /* comment for guid1 */ 145 | optional uint64 guid1 = 123; 146 | 147 | /* ... and a comment for guid2 */ 148 | optional uint64 guid2 = 124; 149 | } 150 | 151 | message AnEmptyMessage { 152 | } 153 | 154 | /* Service comment */ 155 | service RpcService { 156 | /* 157 | * service trailer 158 | * that spans multiple lines 159 | */ 160 | 161 | /* option that sets field */ 162 | option (testprotos.sfubar) = { id: 100, name: "bob" }; 163 | 164 | option deprecated = false; /* DEPRECATED! */ 165 | 166 | option (testprotos.sfubare) = VALUE; 167 | 168 | /* Method comment */ 169 | rpc StreamingRpc ( stream Request ) returns ( Request ); /* compact method trailer */ 170 | 171 | rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) { 172 | /* trailer for method */ 173 | 174 | /* this RPC is deprecated! */ 175 | option deprecated = true; 176 | 177 | option (testprotos.mtfubar) = 12.340000; 178 | 179 | option (testprotos.mtfubard) = 123.456000; 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_comments-no-trailing-comments.proto: -------------------------------------------------------------------------------- 1 | // This is the first detached comment for the syntax. 2 | 3 | // This is a second detached comment. 4 | 5 | // This is a third. 6 | 7 | // Syntax comment... 8 | syntax = "proto2"; 9 | 10 | // And now the package declaration 11 | package foo.bar; 12 | 13 | // option comments FTW!!! 14 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 15 | 16 | import public "google/protobuf/empty.proto"; 17 | 18 | import "desc_test_options.proto"; 19 | 20 | // Multiple white space lines (like above) cannot 21 | // be preserved... 22 | 23 | // We need a request for our RPC service below. 24 | message Request { 25 | option deprecated = true; 26 | 27 | // A field comment 28 | repeated int32 ids = 1 [ 29 | packed = true, 30 | json_name = "|foo|", 31 | (testprotos.ffubar) = "abc", 32 | (testprotos.ffubarb) = "xyz" 33 | ]; 34 | 35 | // lead mfubar 36 | option (testprotos.mfubar) = true; 37 | 38 | // some detached comments 39 | 40 | // some detached comments with unicode 这个是值 41 | 42 | // Another field comment 43 | 44 | // label comment 45 | optional string name = 2 [default = "fubar"]; 46 | 47 | extensions 100 to 200; 48 | 49 | extensions 201 to 250 [ 50 | (testprotos.exfubarb) = "\000\001\002\003\004\005\006\007", 51 | (testprotos.exfubar) = "splat!" 52 | ]; 53 | 54 | reserved 10 to 20, 30 to 50; 55 | 56 | reserved "foo", "bar", "baz"; 57 | 58 | // Group comment with emoji 😀 😍 👻 ❤ 💯 💥 🐶 🦂 🥑 🍻 🌍 🚕 🪐 59 | optional group Extras = 3 { 60 | // this is a custom option 61 | option (testprotos.mfubar) = false; 62 | 63 | optional double dbl = 1; 64 | 65 | optional float flt = 2; 66 | 67 | option no_standard_descriptor_accessor = false; 68 | 69 | // Leading comment... 70 | optional string str = 3; 71 | } 72 | 73 | enum MarioCharacters { 74 | // allow_alias comments! 75 | option allow_alias = true; 76 | 77 | MARIO = 1 [ 78 | (testprotos.evfubars) = -314, 79 | (testprotos.evfubar) = 278 80 | ]; 81 | 82 | LUIGI = 2 [ 83 | (testprotos.evfubaruf) = 100, 84 | (testprotos.evfubaru) = 200 85 | ]; 86 | 87 | PEACH = 3; 88 | 89 | BOWSER = 4; 90 | 91 | option (testprotos.efubars) = -321; 92 | 93 | WARIO = 5; 94 | 95 | WALUIGI = 6; 96 | 97 | SHY_GUY = 7 [(testprotos.evfubarsf) = 10101]; 98 | 99 | HEY_HO = 7; 100 | 101 | MAGIKOOPA = 8; 102 | 103 | KAMEK = 8; 104 | 105 | SNIFIT = -101; 106 | 107 | option (testprotos.efubar) = 123; 108 | } 109 | 110 | // can be this or that 111 | oneof abc { 112 | string this = 4; 113 | 114 | int32 that = 5; 115 | } 116 | 117 | // can be these or those 118 | oneof xyz { 119 | // whoops? 120 | option (testprotos.oofubar) = "whoops, this has invalid UTF8! \274\377"; 121 | 122 | string these = 6; 123 | 124 | int32 those = 7; 125 | } 126 | 127 | // map field 128 | map things = 8; 129 | } 130 | 131 | // And next we'll need some extensions... 132 | 133 | extend Request { 134 | // comment for guid1 135 | optional uint64 guid1 = 123; 136 | 137 | // ... and a comment for guid2 138 | optional uint64 guid2 = 124; 139 | } 140 | 141 | message AnEmptyMessage { 142 | } 143 | 144 | // Service comment 145 | service RpcService { 146 | // option that sets field 147 | option (testprotos.sfubar) = { id: 100, name: "bob" }; 148 | 149 | option deprecated = false; 150 | 151 | option (testprotos.sfubare) = VALUE; 152 | 153 | // Method comment 154 | rpc StreamingRpc ( stream Request ) returns ( Request ); 155 | 156 | rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) { 157 | // this RPC is deprecated! 158 | option deprecated = true; 159 | 160 | option (testprotos.mtfubar) = 12.340000; 161 | 162 | option (testprotos.mtfubard) = 123.456000; 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_comments-only-doc-comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package foo.bar; 4 | 5 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 6 | 7 | import public "google/protobuf/empty.proto"; 8 | 9 | import "desc_test_options.proto"; 10 | 11 | // We need a request for our RPC service below. 12 | message Request { 13 | option deprecated = true; 14 | 15 | // A field comment 16 | repeated int32 ids = 1 [ 17 | packed = true, 18 | json_name = "|foo|", 19 | (testprotos.ffubar) = "abc", 20 | (testprotos.ffubarb) = "xyz" 21 | ]; 22 | 23 | option (testprotos.mfubar) = true; 24 | 25 | // label comment 26 | optional string name = 2 [default = "fubar"]; 27 | 28 | extensions 100 to 200; 29 | 30 | extensions 201 to 250 [ 31 | (testprotos.exfubarb) = "\000\001\002\003\004\005\006\007", 32 | (testprotos.exfubar) = "splat!" 33 | ]; 34 | 35 | reserved 10 to 20, 30 to 50; 36 | 37 | reserved "foo", "bar", "baz"; 38 | 39 | // Group comment with emoji 😀 😍 👻 ❤ 💯 💥 🐶 🦂 🥑 🍻 🌍 🚕 🪐 40 | optional group Extras = 3 { 41 | option (testprotos.mfubar) = false; 42 | 43 | optional double dbl = 1; 44 | 45 | optional float flt = 2; 46 | 47 | option no_standard_descriptor_accessor = false; 48 | 49 | // Leading comment... 50 | optional string str = 3; 51 | } 52 | 53 | enum MarioCharacters { 54 | option allow_alias = true; 55 | 56 | MARIO = 1 [ 57 | (testprotos.evfubars) = -314, 58 | (testprotos.evfubar) = 278 59 | ]; 60 | 61 | LUIGI = 2 [ 62 | (testprotos.evfubaruf) = 100, 63 | (testprotos.evfubaru) = 200 64 | ]; 65 | 66 | PEACH = 3; 67 | 68 | BOWSER = 4; 69 | 70 | option (testprotos.efubars) = -321; 71 | 72 | WARIO = 5; 73 | 74 | WALUIGI = 6; 75 | 76 | SHY_GUY = 7 [(testprotos.evfubarsf) = 10101]; 77 | 78 | HEY_HO = 7; 79 | 80 | MAGIKOOPA = 8; 81 | 82 | KAMEK = 8; 83 | 84 | SNIFIT = -101; 85 | 86 | option (testprotos.efubar) = 123; 87 | } 88 | 89 | // can be this or that 90 | oneof abc { 91 | string this = 4; 92 | 93 | int32 that = 5; 94 | } 95 | 96 | // can be these or those 97 | oneof xyz { 98 | option (testprotos.oofubar) = "whoops, this has invalid UTF8! \274\377"; 99 | 100 | string these = 6; 101 | 102 | int32 those = 7; 103 | } 104 | 105 | // map field 106 | map things = 8; 107 | } 108 | 109 | extend Request { 110 | // comment for guid1 111 | optional uint64 guid1 = 123; 112 | 113 | // ... and a comment for guid2 114 | optional uint64 guid2 = 124; 115 | } 116 | 117 | message AnEmptyMessage { 118 | } 119 | 120 | // Service comment 121 | service RpcService { 122 | option (testprotos.sfubar) = { id: 100, name: "bob" }; 123 | 124 | option deprecated = false; 125 | 126 | option (testprotos.sfubare) = VALUE; 127 | 128 | // Method comment 129 | rpc StreamingRpc ( stream Request ) returns ( Request ); 130 | 131 | rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) { 132 | option deprecated = true; 133 | 134 | option (testprotos.mtfubar) = 12.340000; 135 | 136 | option (testprotos.mtfubard) = 123.456000; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_comments-sorted-AND-multiline-style-comments.proto: -------------------------------------------------------------------------------- 1 | /* This is the first detached comment for the syntax. */ 2 | 3 | /* This is a second detached comment. */ 4 | 5 | /* This is a third. */ 6 | 7 | /* Syntax comment... */ 8 | syntax = "proto2"; /* Syntax trailer. */ 9 | 10 | /* And now the package declaration */ 11 | package foo.bar; 12 | 13 | import "desc_test_options.proto"; 14 | 15 | import public "google/protobuf/empty.proto"; 16 | 17 | /* option comments FTW!!! */ 18 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 19 | 20 | message AnEmptyMessage { 21 | } 22 | 23 | /* 24 | * Multiple white space lines (like above) cannot 25 | * be preserved... 26 | */ 27 | 28 | /* We need a request for our RPC service below. */ 29 | message Request { 30 | option deprecated = true; /* deprecated! */ 31 | 32 | /* lead mfubar */ 33 | option (testprotos.mfubar) = true; /* trailing mfubar */ 34 | 35 | /* A field comment */ 36 | repeated int32 ids = 1 [ 37 | json_name = "|foo|", 38 | packed = true, 39 | (testprotos.ffubar) = "abc", 40 | (testprotos.ffubarb) = "xyz" 41 | ]; /* field trailer #1... */ 42 | 43 | /* some detached comments */ 44 | 45 | /* some detached comments with unicode 这个是值 */ 46 | 47 | /* Another field comment */ 48 | 49 | /* label comment */ 50 | optional string name = 2 [default = "fubar"]; 51 | 52 | /* Group comment with emoji 😀 😍 👻 ❤ 💯 💥 🐶 🦂 🥑 🍻 🌍 🚕 🪐 */ 53 | optional group Extras = 3 { 54 | /* trailer for Extras */ 55 | 56 | option no_standard_descriptor_accessor = false; 57 | 58 | /* this is a custom option */ 59 | option (testprotos.mfubar) = false; 60 | 61 | optional double dbl = 1; 62 | 63 | optional float flt = 2; 64 | 65 | /* Leading comment... */ 66 | optional string str = 3; /* Trailing comment... */ 67 | } 68 | 69 | /* can be this or that */ 70 | oneof abc { 71 | /* trailer for oneof abc */ 72 | 73 | string this = 4; 74 | 75 | int32 that = 5; 76 | } 77 | 78 | /* can be these or those */ 79 | oneof xyz { 80 | /* whoops? */ 81 | option (testprotos.oofubar) = "whoops, this has invalid UTF8! \274\377"; 82 | 83 | string these = 6; 84 | 85 | int32 those = 7; 86 | } 87 | 88 | /* map field */ 89 | map things = 8; 90 | 91 | enum MarioCharacters { 92 | /* trailer for enum */ 93 | 94 | /* allow_alias comments! */ 95 | option allow_alias = true; 96 | 97 | option (testprotos.efubar) = 123; 98 | 99 | option (testprotos.efubars) = -321; 100 | 101 | SNIFIT = -101; 102 | 103 | MARIO = 1 [ 104 | (testprotos.evfubar) = 278, 105 | (testprotos.evfubars) = -314 106 | ]; 107 | 108 | LUIGI = 2 [ 109 | (testprotos.evfubaru) = 200, 110 | (testprotos.evfubaruf) = 100 111 | ]; 112 | 113 | PEACH = 3; 114 | 115 | BOWSER = 4; 116 | 117 | WARIO = 5; 118 | 119 | WALUIGI = 6; 120 | 121 | HEY_HO = 7; 122 | 123 | SHY_GUY = 7 [(testprotos.evfubarsf) = 10101]; 124 | 125 | KAMEK = 8; 126 | 127 | MAGIKOOPA = 8; 128 | } 129 | 130 | extensions 100 to 200; 131 | 132 | extensions 201 to 250 [ 133 | (testprotos.exfubar) = "splat!", 134 | (testprotos.exfubarb) = "\000\001\002\003\004\005\006\007" 135 | ]; 136 | 137 | reserved 10 to 20, 30 to 50; 138 | 139 | reserved "bar", "baz", "foo"; 140 | } 141 | 142 | /* Service comment */ 143 | service RpcService { 144 | /* 145 | * service trailer 146 | * that spans multiple lines 147 | */ 148 | 149 | option deprecated = false; /* DEPRECATED! */ 150 | 151 | /* option that sets field */ 152 | option (testprotos.sfubar) = { id: 100, name: "bob" }; 153 | 154 | option (testprotos.sfubare) = VALUE; 155 | 156 | /* Method comment */ 157 | rpc StreamingRpc ( stream Request ) returns ( Request ); /* compact method trailer */ 158 | 159 | rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) { 160 | /* trailer for method */ 161 | 162 | /* this RPC is deprecated! */ 163 | option deprecated = true; 164 | 165 | option (testprotos.mtfubar) = 12.340000; 166 | 167 | option (testprotos.mtfubard) = 123.456000; 168 | } 169 | } 170 | 171 | /* And next we'll need some extensions... */ 172 | 173 | extend Request { 174 | /* trailer for extend block */ 175 | 176 | /* comment for guid1 */ 177 | optional uint64 guid1 = 123; 178 | 179 | /* ... and a comment for guid2 */ 180 | optional uint64 guid2 = 124; 181 | } 182 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_comments-sorted.proto: -------------------------------------------------------------------------------- 1 | // Syntax comment... 2 | syntax = "proto2"; // Syntax trailer. 3 | 4 | // And now the package declaration 5 | package foo.bar; 6 | 7 | import "desc_test_options.proto"; 8 | 9 | import public "google/protobuf/empty.proto"; 10 | 11 | // option comments FTW!!! 12 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 13 | 14 | message AnEmptyMessage { 15 | } 16 | 17 | // We need a request for our RPC service below. 18 | message Request { 19 | option deprecated = true; // deprecated! 20 | 21 | // lead mfubar 22 | option (testprotos.mfubar) = true; // trailing mfubar 23 | 24 | // A field comment 25 | repeated int32 ids = 1 [ 26 | json_name = "|foo|", 27 | packed = true, 28 | (testprotos.ffubar) = "abc", 29 | (testprotos.ffubarb) = "xyz" 30 | ]; // field trailer #1... 31 | 32 | // label comment 33 | optional string name = 2 [default = "fubar"]; 34 | 35 | // Group comment with emoji 😀 😍 👻 ❤ 💯 💥 🐶 🦂 🥑 🍻 🌍 🚕 🪐 36 | optional group Extras = 3 { 37 | // trailer for Extras 38 | 39 | option no_standard_descriptor_accessor = false; 40 | 41 | // this is a custom option 42 | option (testprotos.mfubar) = false; 43 | 44 | optional double dbl = 1; 45 | 46 | optional float flt = 2; 47 | 48 | // Leading comment... 49 | optional string str = 3; // Trailing comment... 50 | } 51 | 52 | // can be this or that 53 | oneof abc { 54 | // trailer for oneof abc 55 | 56 | string this = 4; 57 | 58 | int32 that = 5; 59 | } 60 | 61 | // can be these or those 62 | oneof xyz { 63 | // whoops? 64 | option (testprotos.oofubar) = "whoops, this has invalid UTF8! \274\377"; 65 | 66 | string these = 6; 67 | 68 | int32 those = 7; 69 | } 70 | 71 | // map field 72 | map things = 8; 73 | 74 | enum MarioCharacters { 75 | // trailer for enum 76 | 77 | // allow_alias comments! 78 | option allow_alias = true; 79 | 80 | option (testprotos.efubar) = 123; 81 | 82 | option (testprotos.efubars) = -321; 83 | 84 | SNIFIT = -101; 85 | 86 | MARIO = 1 [ 87 | (testprotos.evfubar) = 278, 88 | (testprotos.evfubars) = -314 89 | ]; 90 | 91 | LUIGI = 2 [ 92 | (testprotos.evfubaru) = 200, 93 | (testprotos.evfubaruf) = 100 94 | ]; 95 | 96 | PEACH = 3; 97 | 98 | BOWSER = 4; 99 | 100 | WARIO = 5; 101 | 102 | WALUIGI = 6; 103 | 104 | HEY_HO = 7; 105 | 106 | SHY_GUY = 7 [(testprotos.evfubarsf) = 10101]; 107 | 108 | KAMEK = 8; 109 | 110 | MAGIKOOPA = 8; 111 | } 112 | 113 | extensions 100 to 200; 114 | 115 | extensions 201 to 250 [ 116 | (testprotos.exfubar) = "splat!", 117 | (testprotos.exfubarb) = "\000\001\002\003\004\005\006\007" 118 | ]; 119 | 120 | reserved 10 to 20, 30 to 50; 121 | 122 | reserved "bar", "baz", "foo"; 123 | } 124 | 125 | // Service comment 126 | service RpcService { 127 | // service trailer 128 | // that spans multiple lines 129 | 130 | option deprecated = false; // DEPRECATED! 131 | 132 | // option that sets field 133 | option (testprotos.sfubar) = { id: 100, name: "bob" }; 134 | 135 | option (testprotos.sfubare) = VALUE; 136 | 137 | // Method comment 138 | rpc StreamingRpc ( stream Request ) returns ( Request ); // compact method trailer 139 | 140 | rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) { 141 | // trailer for method 142 | 143 | // this RPC is deprecated! 144 | option deprecated = true; 145 | 146 | option (testprotos.mtfubar) = 12.340000; 147 | 148 | option (testprotos.mtfubard) = 123.456000; 149 | } 150 | } 151 | 152 | extend Request { 153 | // trailer for extend block 154 | 155 | // comment for guid1 156 | optional uint64 guid1 = 123; 157 | 158 | // ... and a comment for guid2 159 | optional uint64 guid2 = 124; 160 | } 161 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_comments-trailing-on-next-line.proto: -------------------------------------------------------------------------------- 1 | // This is the first detached comment for the syntax. 2 | 3 | // This is a second detached comment. 4 | 5 | // This is a third. 6 | 7 | // Syntax comment... 8 | syntax = "proto2"; 9 | // Syntax trailer. 10 | 11 | // And now the package declaration 12 | package foo.bar; 13 | 14 | // option comments FTW!!! 15 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 16 | 17 | import public "google/protobuf/empty.proto"; 18 | 19 | import "desc_test_options.proto"; 20 | 21 | // Multiple white space lines (like above) cannot 22 | // be preserved... 23 | 24 | // We need a request for our RPC service below. 25 | message Request { 26 | option deprecated = true; 27 | // deprecated! 28 | 29 | // A field comment 30 | repeated int32 ids = 1 [ 31 | packed = true, 32 | json_name = "|foo|", 33 | (testprotos.ffubar) = "abc", 34 | (testprotos.ffubarb) = "xyz" 35 | ]; 36 | // field trailer #1... 37 | 38 | // lead mfubar 39 | option (testprotos.mfubar) = true; 40 | // trailing mfubar 41 | 42 | // some detached comments 43 | 44 | // some detached comments with unicode 这个是值 45 | 46 | // Another field comment 47 | 48 | // label comment 49 | optional string name = 2 [default = "fubar"]; 50 | 51 | extensions 100 to 200; 52 | 53 | extensions 201 to 250 [ 54 | (testprotos.exfubarb) = "\000\001\002\003\004\005\006\007", 55 | (testprotos.exfubar) = "splat!" 56 | ]; 57 | 58 | reserved 10 to 20, 30 to 50; 59 | 60 | reserved "foo", "bar", "baz"; 61 | 62 | // Group comment with emoji 😀 😍 👻 ❤ 💯 💥 🐶 🦂 🥑 🍻 🌍 🚕 🪐 63 | optional group Extras = 3 { 64 | // trailer for Extras 65 | 66 | // this is a custom option 67 | option (testprotos.mfubar) = false; 68 | 69 | optional double dbl = 1; 70 | 71 | optional float flt = 2; 72 | 73 | option no_standard_descriptor_accessor = false; 74 | 75 | // Leading comment... 76 | optional string str = 3; 77 | // Trailing comment... 78 | } 79 | 80 | enum MarioCharacters { 81 | // trailer for enum 82 | 83 | // allow_alias comments! 84 | option allow_alias = true; 85 | 86 | MARIO = 1 [ 87 | (testprotos.evfubars) = -314, 88 | (testprotos.evfubar) = 278 89 | ]; 90 | 91 | LUIGI = 2 [ 92 | (testprotos.evfubaruf) = 100, 93 | (testprotos.evfubaru) = 200 94 | ]; 95 | 96 | PEACH = 3; 97 | 98 | BOWSER = 4; 99 | 100 | option (testprotos.efubars) = -321; 101 | 102 | WARIO = 5; 103 | 104 | WALUIGI = 6; 105 | 106 | SHY_GUY = 7 [(testprotos.evfubarsf) = 10101]; 107 | 108 | HEY_HO = 7; 109 | 110 | MAGIKOOPA = 8; 111 | 112 | KAMEK = 8; 113 | 114 | SNIFIT = -101; 115 | 116 | option (testprotos.efubar) = 123; 117 | } 118 | 119 | // can be this or that 120 | oneof abc { 121 | // trailer for oneof abc 122 | 123 | string this = 4; 124 | 125 | int32 that = 5; 126 | } 127 | 128 | // can be these or those 129 | oneof xyz { 130 | // whoops? 131 | option (testprotos.oofubar) = "whoops, this has invalid UTF8! \274\377"; 132 | 133 | string these = 6; 134 | 135 | int32 those = 7; 136 | } 137 | 138 | // map field 139 | map things = 8; 140 | } 141 | 142 | // And next we'll need some extensions... 143 | 144 | extend Request { 145 | // trailer for extend block 146 | 147 | // comment for guid1 148 | optional uint64 guid1 = 123; 149 | 150 | // ... and a comment for guid2 151 | optional uint64 guid2 = 124; 152 | } 153 | 154 | message AnEmptyMessage { 155 | } 156 | 157 | // Service comment 158 | service RpcService { 159 | // service trailer 160 | // that spans multiple lines 161 | 162 | // option that sets field 163 | option (testprotos.sfubar) = { id: 100, name: "bob" }; 164 | 165 | option deprecated = false; 166 | // DEPRECATED! 167 | 168 | option (testprotos.sfubare) = VALUE; 169 | 170 | // Method comment 171 | rpc StreamingRpc ( stream Request ) returns ( Request ); 172 | // compact method trailer 173 | 174 | rpc UnaryRpc ( Request ) returns ( google.protobuf.Empty ) { 175 | // trailer for method 176 | 177 | // this RPC is deprecated! 178 | option deprecated = true; 179 | 180 | option (testprotos.mtfubar) = 12.340000; 181 | 182 | option (testprotos.mtfubard) = 123.456000; 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_editions-compact.proto: -------------------------------------------------------------------------------- 1 | edition = "2023"; 2 | package testprotos; 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | option features = { enum_type: CLOSED }; 5 | message Foo { 6 | reserved reserved_field; 7 | int32 a = 1; 8 | int32 required_field = 2 [features = { field_presence: LEGACY_REQUIRED }]; 9 | int32 default_field = 3 [default = 99]; 10 | DelimitedField delimitedfield = 4 [features = { message_encoding: DELIMITED }]; 11 | message DelimitedField { 12 | int32 b = 1; 13 | } 14 | } 15 | enum Closed { 16 | CLOSED_C = 1; 17 | CLOSED_A = 2; 18 | reserved CLOSED_E, CLOSED_F; 19 | } 20 | enum Open { 21 | option features = { enum_type: OPEN }; 22 | OPEN_B = 0; 23 | OPEN_C = -1; 24 | OPEN_A = 2; 25 | } 26 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_editions-custom-sort.proto: -------------------------------------------------------------------------------- 1 | edition = "2023"; 2 | 3 | enum Open { 4 | OPEN_B = 0; 5 | 6 | OPEN_C = -1; 7 | 8 | OPEN_A = 2; 9 | 10 | option features = { enum_type: OPEN }; 11 | } 12 | 13 | enum Closed { 14 | CLOSED_C = 1; 15 | 16 | CLOSED_A = 2; 17 | 18 | reserved CLOSED_F, CLOSED_E; 19 | } 20 | 21 | message Foo { 22 | reserved reserved_field; 23 | 24 | message DelimitedField { 25 | int32 b = 1; 26 | } 27 | 28 | int32 required_field = 2 [features = { field_presence: LEGACY_REQUIRED }]; 29 | 30 | DelimitedField delimitedfield = 4 [features = { message_encoding: DELIMITED }]; 31 | 32 | int32 default_field = 3 [default = 99]; 33 | 34 | int32 a = 1; 35 | } 36 | 37 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 38 | 39 | option features = { enum_type: CLOSED }; 40 | 41 | package testprotos; 42 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_editions-default.proto: -------------------------------------------------------------------------------- 1 | edition = "2023"; 2 | 3 | package testprotos; 4 | 5 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 6 | 7 | option features = { enum_type: CLOSED }; 8 | 9 | message Foo { 10 | reserved reserved_field; 11 | 12 | int32 a = 1; 13 | 14 | int32 required_field = 2 [features = { field_presence: LEGACY_REQUIRED }]; 15 | 16 | int32 default_field = 3 [default = 99]; 17 | 18 | DelimitedField delimitedfield = 4 [features = { message_encoding: DELIMITED }]; 19 | 20 | message DelimitedField { 21 | int32 b = 1; 22 | } 23 | } 24 | 25 | enum Closed { 26 | CLOSED_C = 1; 27 | 28 | CLOSED_A = 2; 29 | 30 | reserved CLOSED_E, CLOSED_F; 31 | } 32 | 33 | enum Open { 34 | option features = { enum_type: OPEN }; 35 | 36 | OPEN_B = 0; 37 | 38 | OPEN_C = -1; 39 | 40 | OPEN_A = 2; 41 | } 42 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_editions-multiline-style-comments.proto: -------------------------------------------------------------------------------- 1 | edition = "2023"; 2 | 3 | package testprotos; 4 | 5 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 6 | 7 | option features = { enum_type: CLOSED }; 8 | 9 | message Foo { 10 | reserved reserved_field; 11 | 12 | int32 a = 1; 13 | 14 | int32 required_field = 2 [features = { field_presence: LEGACY_REQUIRED }]; 15 | 16 | int32 default_field = 3 [default = 99]; 17 | 18 | DelimitedField delimitedfield = 4 [features = { message_encoding: DELIMITED }]; 19 | 20 | message DelimitedField { 21 | int32 b = 1; 22 | } 23 | } 24 | 25 | enum Closed { 26 | CLOSED_C = 1; 27 | 28 | CLOSED_A = 2; 29 | 30 | reserved CLOSED_E, CLOSED_F; 31 | } 32 | 33 | enum Open { 34 | option features = { enum_type: OPEN }; 35 | 36 | OPEN_B = 0; 37 | 38 | OPEN_C = -1; 39 | 40 | OPEN_A = 2; 41 | } 42 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_editions-no-trailing-comments.proto: -------------------------------------------------------------------------------- 1 | edition = "2023"; 2 | 3 | package testprotos; 4 | 5 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 6 | 7 | option features = { enum_type: CLOSED }; 8 | 9 | message Foo { 10 | reserved reserved_field; 11 | 12 | int32 a = 1; 13 | 14 | int32 required_field = 2 [features = { field_presence: LEGACY_REQUIRED }]; 15 | 16 | int32 default_field = 3 [default = 99]; 17 | 18 | DelimitedField delimitedfield = 4 [features = { message_encoding: DELIMITED }]; 19 | 20 | message DelimitedField { 21 | int32 b = 1; 22 | } 23 | } 24 | 25 | enum Closed { 26 | CLOSED_C = 1; 27 | 28 | CLOSED_A = 2; 29 | 30 | reserved CLOSED_E, CLOSED_F; 31 | } 32 | 33 | enum Open { 34 | option features = { enum_type: OPEN }; 35 | 36 | OPEN_B = 0; 37 | 38 | OPEN_C = -1; 39 | 40 | OPEN_A = 2; 41 | } 42 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_editions-only-doc-comments.proto: -------------------------------------------------------------------------------- 1 | edition = "2023"; 2 | 3 | package testprotos; 4 | 5 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 6 | 7 | option features = { enum_type: CLOSED }; 8 | 9 | message Foo { 10 | reserved reserved_field; 11 | 12 | int32 a = 1; 13 | 14 | int32 required_field = 2 [features = { field_presence: LEGACY_REQUIRED }]; 15 | 16 | int32 default_field = 3 [default = 99]; 17 | 18 | DelimitedField delimitedfield = 4 [features = { message_encoding: DELIMITED }]; 19 | 20 | message DelimitedField { 21 | int32 b = 1; 22 | } 23 | } 24 | 25 | enum Closed { 26 | CLOSED_C = 1; 27 | 28 | CLOSED_A = 2; 29 | 30 | reserved CLOSED_E, CLOSED_F; 31 | } 32 | 33 | enum Open { 34 | option features = { enum_type: OPEN }; 35 | 36 | OPEN_B = 0; 37 | 38 | OPEN_C = -1; 39 | 40 | OPEN_A = 2; 41 | } 42 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_editions-sorted-AND-multiline-style-comments.proto: -------------------------------------------------------------------------------- 1 | edition = "2023"; 2 | 3 | package testprotos; 4 | 5 | option features = { enum_type: CLOSED }; 6 | 7 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 8 | 9 | message Foo { 10 | int32 a = 1; 11 | 12 | int32 required_field = 2 [features = { field_presence: LEGACY_REQUIRED }]; 13 | 14 | int32 default_field = 3 [default = 99]; 15 | 16 | DelimitedField delimitedfield = 4 [features = { message_encoding: DELIMITED }]; 17 | 18 | message DelimitedField { 19 | int32 b = 1; 20 | } 21 | 22 | reserved reserved_field; 23 | } 24 | 25 | enum Closed { 26 | CLOSED_C = 1; 27 | 28 | CLOSED_A = 2; 29 | 30 | reserved CLOSED_E, CLOSED_F; 31 | } 32 | 33 | enum Open { 34 | option features = { enum_type: OPEN }; 35 | 36 | OPEN_B = 0; 37 | 38 | OPEN_C = -1; 39 | 40 | OPEN_A = 2; 41 | } 42 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_editions-sorted.proto: -------------------------------------------------------------------------------- 1 | edition = "2023"; 2 | 3 | package testprotos; 4 | 5 | option features = { enum_type: CLOSED }; 6 | 7 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 8 | 9 | message Foo { 10 | int32 a = 1; 11 | 12 | int32 required_field = 2 [features = { field_presence: LEGACY_REQUIRED }]; 13 | 14 | int32 default_field = 3 [default = 99]; 15 | 16 | DelimitedField delimitedfield = 4 [features = { message_encoding: DELIMITED }]; 17 | 18 | message DelimitedField { 19 | int32 b = 1; 20 | } 21 | 22 | reserved reserved_field; 23 | } 24 | 25 | enum Closed { 26 | CLOSED_C = 1; 27 | 28 | CLOSED_A = 2; 29 | 30 | reserved CLOSED_E, CLOSED_F; 31 | } 32 | 33 | enum Open { 34 | option features = { enum_type: OPEN }; 35 | 36 | OPEN_B = 0; 37 | 38 | OPEN_C = -1; 39 | 40 | OPEN_A = 2; 41 | } 42 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_editions-trailing-on-next-line.proto: -------------------------------------------------------------------------------- 1 | edition = "2023"; 2 | 3 | package testprotos; 4 | 5 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 6 | 7 | option features = { enum_type: CLOSED }; 8 | 9 | message Foo { 10 | reserved reserved_field; 11 | 12 | int32 a = 1; 13 | 14 | int32 required_field = 2 [features = { field_presence: LEGACY_REQUIRED }]; 15 | 16 | int32 default_field = 3 [default = 99]; 17 | 18 | DelimitedField delimitedfield = 4 [features = { message_encoding: DELIMITED }]; 19 | 20 | message DelimitedField { 21 | int32 b = 1; 22 | } 23 | } 24 | 25 | enum Closed { 26 | CLOSED_C = 1; 27 | 28 | CLOSED_A = 2; 29 | 30 | reserved CLOSED_E, CLOSED_F; 31 | } 32 | 33 | enum Open { 34 | option features = { enum_type: OPEN }; 35 | 36 | OPEN_B = 0; 37 | 38 | OPEN_C = -1; 39 | 40 | OPEN_A = 2; 41 | } 42 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3-compact.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 3 | package testprotos; 4 | import "desc_test1.proto"; 5 | import "pkg/desc_test_pkg.proto"; 6 | enum Proto3Enum { 7 | UNKNOWN = 0; 8 | VALUE_NEG1 = -1; 9 | VALUE1 = 1; 10 | VALUE2 = 2; 11 | } 12 | message TestRequest { 13 | repeated Proto3Enum foo = 1; 14 | string bar = 2; 15 | TestMessage baz = 3; 16 | TestMessage.NestedMessage.AnotherNestedMessage snafu = 4; 17 | map flags = 5; 18 | map others = 6; 19 | } 20 | message TestResponse { 21 | AnotherTestMessage atm = 1; 22 | repeated int32 vs = 2; 23 | } 24 | service TestService { 25 | rpc DoSomething ( TestRequest ) returns ( jhump.protoreflect.desc.Bar ); 26 | rpc DoSomethingElse ( stream TestMessage ) returns ( TestResponse ); 27 | rpc DoSomethingAgain ( jhump.protoreflect.desc.Bar ) returns ( stream AnotherTestMessage ); 28 | rpc DoSomethingForever ( stream TestRequest ) returns ( stream TestResponse ); 29 | } 30 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3-custom-sort.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | service TestService { 4 | rpc DoSomethingForever ( stream TestRequest ) returns ( stream TestResponse ); 5 | 6 | rpc DoSomethingElse ( stream TestMessage ) returns ( TestResponse ); 7 | 8 | rpc DoSomethingAgain ( jhump.protoreflect.desc.Bar ) returns ( stream AnotherTestMessage ); 9 | 10 | rpc DoSomething ( TestRequest ) returns ( jhump.protoreflect.desc.Bar ); 11 | } 12 | 13 | enum Proto3Enum { 14 | UNKNOWN = 0; 15 | 16 | VALUE_NEG1 = -1; 17 | 18 | VALUE2 = 2; 19 | 20 | VALUE1 = 1; 21 | } 22 | 23 | message TestResponse { 24 | repeated int32 vs = 2; 25 | 26 | AnotherTestMessage atm = 1; 27 | } 28 | 29 | message TestRequest { 30 | 31 | TestMessage.NestedMessage.AnotherNestedMessage snafu = 4; 32 | 33 | map others = 6; 34 | 35 | repeated Proto3Enum foo = 1; 36 | 37 | map flags = 5; 38 | 39 | TestMessage baz = 3; 40 | 41 | string bar = 2; 42 | } 43 | 44 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 45 | 46 | import "pkg/desc_test_pkg.proto"; 47 | 48 | import "desc_test1.proto"; 49 | 50 | package testprotos; 51 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3-default.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | 5 | package testprotos; 6 | 7 | import "desc_test1.proto"; 8 | 9 | import "pkg/desc_test_pkg.proto"; 10 | 11 | enum Proto3Enum { 12 | UNKNOWN = 0; 13 | 14 | VALUE_NEG1 = -1; 15 | 16 | VALUE1 = 1; 17 | 18 | VALUE2 = 2; 19 | } 20 | 21 | message TestRequest { 22 | repeated Proto3Enum foo = 1; 23 | 24 | string bar = 2; 25 | 26 | TestMessage baz = 3; 27 | 28 | TestMessage.NestedMessage.AnotherNestedMessage snafu = 4; 29 | 30 | map flags = 5; 31 | 32 | map others = 6; 33 | } 34 | 35 | message TestResponse { 36 | AnotherTestMessage atm = 1; 37 | 38 | repeated int32 vs = 2; 39 | } 40 | 41 | service TestService { 42 | rpc DoSomething ( TestRequest ) returns ( jhump.protoreflect.desc.Bar ); 43 | 44 | rpc DoSomethingElse ( stream TestMessage ) returns ( TestResponse ); 45 | 46 | rpc DoSomethingAgain ( jhump.protoreflect.desc.Bar ) returns ( stream AnotherTestMessage ); 47 | 48 | rpc DoSomethingForever ( stream TestRequest ) returns ( stream TestResponse ); 49 | } 50 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3-multiline-style-comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | 5 | package testprotos; 6 | 7 | import "desc_test1.proto"; 8 | 9 | import "pkg/desc_test_pkg.proto"; 10 | 11 | enum Proto3Enum { 12 | UNKNOWN = 0; 13 | 14 | VALUE_NEG1 = -1; 15 | 16 | VALUE1 = 1; 17 | 18 | VALUE2 = 2; 19 | } 20 | 21 | message TestRequest { 22 | repeated Proto3Enum foo = 1; 23 | 24 | string bar = 2; 25 | 26 | TestMessage baz = 3; 27 | 28 | TestMessage.NestedMessage.AnotherNestedMessage snafu = 4; 29 | 30 | map flags = 5; 31 | 32 | map others = 6; 33 | } 34 | 35 | message TestResponse { 36 | AnotherTestMessage atm = 1; 37 | 38 | repeated int32 vs = 2; 39 | } 40 | 41 | service TestService { 42 | rpc DoSomething ( TestRequest ) returns ( jhump.protoreflect.desc.Bar ); 43 | 44 | rpc DoSomethingElse ( stream TestMessage ) returns ( TestResponse ); 45 | 46 | rpc DoSomethingAgain ( jhump.protoreflect.desc.Bar ) returns ( stream AnotherTestMessage ); 47 | 48 | rpc DoSomethingForever ( stream TestRequest ) returns ( stream TestResponse ); 49 | } 50 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3-no-trailing-comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | 5 | package testprotos; 6 | 7 | import "desc_test1.proto"; 8 | 9 | import "pkg/desc_test_pkg.proto"; 10 | 11 | enum Proto3Enum { 12 | UNKNOWN = 0; 13 | 14 | VALUE_NEG1 = -1; 15 | 16 | VALUE1 = 1; 17 | 18 | VALUE2 = 2; 19 | } 20 | 21 | message TestRequest { 22 | repeated Proto3Enum foo = 1; 23 | 24 | string bar = 2; 25 | 26 | TestMessage baz = 3; 27 | 28 | TestMessage.NestedMessage.AnotherNestedMessage snafu = 4; 29 | 30 | map flags = 5; 31 | 32 | map others = 6; 33 | } 34 | 35 | message TestResponse { 36 | AnotherTestMessage atm = 1; 37 | 38 | repeated int32 vs = 2; 39 | } 40 | 41 | service TestService { 42 | rpc DoSomething ( TestRequest ) returns ( jhump.protoreflect.desc.Bar ); 43 | 44 | rpc DoSomethingElse ( stream TestMessage ) returns ( TestResponse ); 45 | 46 | rpc DoSomethingAgain ( jhump.protoreflect.desc.Bar ) returns ( stream AnotherTestMessage ); 47 | 48 | rpc DoSomethingForever ( stream TestRequest ) returns ( stream TestResponse ); 49 | } 50 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3-only-doc-comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | 5 | package testprotos; 6 | 7 | import "desc_test1.proto"; 8 | 9 | import "pkg/desc_test_pkg.proto"; 10 | 11 | enum Proto3Enum { 12 | UNKNOWN = 0; 13 | 14 | VALUE_NEG1 = -1; 15 | 16 | VALUE1 = 1; 17 | 18 | VALUE2 = 2; 19 | } 20 | 21 | message TestRequest { 22 | repeated Proto3Enum foo = 1; 23 | 24 | string bar = 2; 25 | 26 | TestMessage baz = 3; 27 | 28 | TestMessage.NestedMessage.AnotherNestedMessage snafu = 4; 29 | 30 | map flags = 5; 31 | 32 | map others = 6; 33 | } 34 | 35 | message TestResponse { 36 | AnotherTestMessage atm = 1; 37 | 38 | repeated int32 vs = 2; 39 | } 40 | 41 | service TestService { 42 | rpc DoSomething ( TestRequest ) returns ( jhump.protoreflect.desc.Bar ); 43 | 44 | rpc DoSomethingElse ( stream TestMessage ) returns ( TestResponse ); 45 | 46 | rpc DoSomethingAgain ( jhump.protoreflect.desc.Bar ) returns ( stream AnotherTestMessage ); 47 | 48 | rpc DoSomethingForever ( stream TestRequest ) returns ( stream TestResponse ); 49 | } 50 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3-sorted-AND-multiline-style-comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package testprotos; 4 | 5 | import "desc_test1.proto"; 6 | 7 | import "pkg/desc_test_pkg.proto"; 8 | 9 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 10 | 11 | message TestRequest { 12 | repeated Proto3Enum foo = 1; 13 | 14 | string bar = 2; 15 | 16 | TestMessage baz = 3; 17 | 18 | TestMessage.NestedMessage.AnotherNestedMessage snafu = 4; 19 | 20 | map flags = 5; 21 | 22 | map others = 6; 23 | } 24 | 25 | message TestResponse { 26 | AnotherTestMessage atm = 1; 27 | 28 | repeated int32 vs = 2; 29 | } 30 | 31 | enum Proto3Enum { 32 | UNKNOWN = 0; 33 | 34 | VALUE_NEG1 = -1; 35 | 36 | VALUE1 = 1; 37 | 38 | VALUE2 = 2; 39 | } 40 | 41 | service TestService { 42 | rpc DoSomething ( TestRequest ) returns ( jhump.protoreflect.desc.Bar ); 43 | 44 | rpc DoSomethingAgain ( jhump.protoreflect.desc.Bar ) returns ( stream AnotherTestMessage ); 45 | 46 | rpc DoSomethingElse ( stream TestMessage ) returns ( TestResponse ); 47 | 48 | rpc DoSomethingForever ( stream TestRequest ) returns ( stream TestResponse ); 49 | } 50 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3-sorted.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package testprotos; 4 | 5 | import "desc_test1.proto"; 6 | 7 | import "pkg/desc_test_pkg.proto"; 8 | 9 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 10 | 11 | message TestRequest { 12 | repeated Proto3Enum foo = 1; 13 | 14 | string bar = 2; 15 | 16 | TestMessage baz = 3; 17 | 18 | TestMessage.NestedMessage.AnotherNestedMessage snafu = 4; 19 | 20 | map flags = 5; 21 | 22 | map others = 6; 23 | } 24 | 25 | message TestResponse { 26 | AnotherTestMessage atm = 1; 27 | 28 | repeated int32 vs = 2; 29 | } 30 | 31 | enum Proto3Enum { 32 | UNKNOWN = 0; 33 | 34 | VALUE_NEG1 = -1; 35 | 36 | VALUE1 = 1; 37 | 38 | VALUE2 = 2; 39 | } 40 | 41 | service TestService { 42 | rpc DoSomething ( TestRequest ) returns ( jhump.protoreflect.desc.Bar ); 43 | 44 | rpc DoSomethingAgain ( jhump.protoreflect.desc.Bar ) returns ( stream AnotherTestMessage ); 45 | 46 | rpc DoSomethingElse ( stream TestMessage ) returns ( TestResponse ); 47 | 48 | rpc DoSomethingForever ( stream TestRequest ) returns ( stream TestResponse ); 49 | } 50 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3-trailing-on-next-line.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | 5 | package testprotos; 6 | 7 | import "desc_test1.proto"; 8 | 9 | import "pkg/desc_test_pkg.proto"; 10 | 11 | enum Proto3Enum { 12 | UNKNOWN = 0; 13 | 14 | VALUE_NEG1 = -1; 15 | 16 | VALUE1 = 1; 17 | 18 | VALUE2 = 2; 19 | } 20 | 21 | message TestRequest { 22 | repeated Proto3Enum foo = 1; 23 | 24 | string bar = 2; 25 | 26 | TestMessage baz = 3; 27 | 28 | TestMessage.NestedMessage.AnotherNestedMessage snafu = 4; 29 | 30 | map flags = 5; 31 | 32 | map others = 6; 33 | } 34 | 35 | message TestResponse { 36 | AnotherTestMessage atm = 1; 37 | 38 | repeated int32 vs = 2; 39 | } 40 | 41 | service TestService { 42 | rpc DoSomething ( TestRequest ) returns ( jhump.protoreflect.desc.Bar ); 43 | 44 | rpc DoSomethingElse ( stream TestMessage ) returns ( TestResponse ); 45 | 46 | rpc DoSomethingAgain ( jhump.protoreflect.desc.Bar ) returns ( stream AnotherTestMessage ); 47 | 48 | rpc DoSomethingForever ( stream TestRequest ) returns ( stream TestResponse ); 49 | } 50 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3_optional-compact.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | import "google/protobuf/descriptor.proto"; 3 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 4 | message MessageWithOptionalFields { 5 | optional string foo = 1; 6 | optional int64 bar = 2; 7 | } 8 | extend google.protobuf.MessageOptions { 9 | string some_custom_options = 44444; 10 | } 11 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3_optional-custom-sort.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | extend google.protobuf.MessageOptions { 4 | string some_custom_options = 44444; 5 | } 6 | 7 | message MessageWithOptionalFields { 8 | optional string foo = 1; 9 | 10 | optional int64 bar = 2; 11 | } 12 | 13 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 14 | 15 | import "google/protobuf/descriptor.proto"; 16 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3_optional-default.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/descriptor.proto"; 4 | 5 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 6 | 7 | message MessageWithOptionalFields { 8 | optional string foo = 1; 9 | 10 | optional int64 bar = 2; 11 | } 12 | 13 | extend google.protobuf.MessageOptions { 14 | string some_custom_options = 44444; 15 | } 16 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3_optional-multiline-style-comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/descriptor.proto"; 4 | 5 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 6 | 7 | message MessageWithOptionalFields { 8 | optional string foo = 1; 9 | 10 | optional int64 bar = 2; 11 | } 12 | 13 | extend google.protobuf.MessageOptions { 14 | string some_custom_options = 44444; 15 | } 16 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3_optional-no-trailing-comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/descriptor.proto"; 4 | 5 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 6 | 7 | message MessageWithOptionalFields { 8 | optional string foo = 1; 9 | 10 | optional int64 bar = 2; 11 | } 12 | 13 | extend google.protobuf.MessageOptions { 14 | string some_custom_options = 44444; 15 | } 16 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3_optional-only-doc-comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/descriptor.proto"; 4 | 5 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 6 | 7 | message MessageWithOptionalFields { 8 | optional string foo = 1; 9 | 10 | optional int64 bar = 2; 11 | } 12 | 13 | extend google.protobuf.MessageOptions { 14 | string some_custom_options = 44444; 15 | } 16 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3_optional-sorted-AND-multiline-style-comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/descriptor.proto"; 4 | 5 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 6 | 7 | message MessageWithOptionalFields { 8 | optional string foo = 1; 9 | 10 | optional int64 bar = 2; 11 | } 12 | 13 | extend google.protobuf.MessageOptions { 14 | string some_custom_options = 44444; 15 | } 16 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3_optional-sorted.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/descriptor.proto"; 4 | 5 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 6 | 7 | message MessageWithOptionalFields { 8 | optional string foo = 1; 9 | 10 | optional int64 bar = 2; 11 | } 12 | 13 | extend google.protobuf.MessageOptions { 14 | string some_custom_options = 44444; 15 | } 16 | -------------------------------------------------------------------------------- /protoprint/testfiles/desc_test_proto3_optional-trailing-on-next-line.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/descriptor.proto"; 4 | 5 | option go_package = "github.com/jhump/protoreflect/v2/internal/testprotos"; 6 | 7 | message MessageWithOptionalFields { 8 | optional string foo = 1; 9 | 10 | optional int64 bar = 2; 11 | } 12 | 13 | extend google.protobuf.MessageOptions { 14 | string some_custom_options = 44444; 15 | } 16 | -------------------------------------------------------------------------------- /protoprint/testfiles/test-uninterpreted-options.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package pkg; 4 | 5 | import "google/protobuf/descriptor.proto"; 6 | 7 | option go_package = "some.pkg"; 8 | 9 | message Options { 10 | optional bool some_option_value = 1; 11 | } 12 | 13 | message SomeMessage { 14 | option (.pkg.my_some_option) = { some_option_value : true }; 15 | } 16 | 17 | extend google.protobuf.MessageOptions { 18 | optional Options my_some_option = 11964; 19 | } 20 | -------------------------------------------------------------------------------- /protoprint/testfiles/test-unrecognized-options.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/descriptor.proto"; 4 | 5 | message Test { 6 | } 7 | 8 | message Foo { 9 | repeated Bar bar = 1; 10 | 11 | message Bar { 12 | Baz baz = 1; 13 | 14 | string name = 2; 15 | } 16 | 17 | enum Baz { 18 | ZERO = 0; 19 | 20 | FROB = 1; 21 | 22 | NITZ = 2; 23 | } 24 | } 25 | 26 | service TestService { 27 | rpc Get ( Test ) returns ( Test ) { 28 | option (foo) = { 29 | bar: [ 30 | { baz: FROB, name: "abc" }, 31 | { baz: NITZ, name: "xyz" } 32 | ] 33 | }; 34 | } 35 | } 36 | 37 | extend google.protobuf.MethodOptions { 38 | Foo foo = 54321; 39 | } 40 | -------------------------------------------------------------------------------- /protoresolve/errors.go: -------------------------------------------------------------------------------- 1 | package protoresolve 2 | 3 | import ( 4 | "fmt" 5 | 6 | "google.golang.org/protobuf/reflect/protoreflect" 7 | "google.golang.org/protobuf/reflect/protoregistry" 8 | ) 9 | 10 | var ( 11 | // ErrNotFound is a sentinel error that is returned from resolvers to indicate that the named 12 | // element is not known to the registry. It is the same as protoregistry.NotFound. 13 | ErrNotFound = protoregistry.NotFound 14 | ) 15 | 16 | // NewNotFoundError returns an error that wraps ErrNotFound with context 17 | // indicating the given name as the element that could not be found. 18 | // 19 | // The parameter is generic so that it will accept both plain strings 20 | // and named string types like protoreflect.FullName. 21 | func NewNotFoundError[T ~string](name T) error { 22 | return fmt.Errorf("%s: %w", name, ErrNotFound) 23 | } 24 | 25 | // ErrUnexpectedType is an error that indicates a descriptor was resolved for 26 | // a given URL or name, but it is of the wrong type. So a query may have been 27 | // expecting a service descriptor, for example, but instead the queried name 28 | // resolved to an extension descriptor. 29 | // 30 | // See NewUnexpectedTypeError. 31 | type ErrUnexpectedType struct { 32 | // Only one of URL or Name will be set, depending on whether 33 | // the type was looked up by URL or name. These fields indicate 34 | // the query that resulted in a descriptor of the wrong type. 35 | URL string 36 | Name protoreflect.FullName 37 | // The kind of descriptor that was expected. 38 | Expecting DescriptorKind 39 | // The kind of descriptor that was actually found. 40 | Actual DescriptorKind 41 | // Optional: the descriptor that was actually found. This may 42 | // be nil. If non-nil, this is the descriptor instance that 43 | // was resolved whose kind is Actual instead of Expecting. 44 | Descriptor protoreflect.Descriptor 45 | } 46 | 47 | // NewUnexpectedTypeError constructs a new *ErrUnexpectedType based 48 | // on the given properties. The last parameter, url, is optional. If 49 | // empty, the returned error will indicate that the given descriptor's 50 | // full name as the query. 51 | func NewUnexpectedTypeError(expecting DescriptorKind, got protoreflect.Descriptor, url string) *ErrUnexpectedType { 52 | var name protoreflect.FullName 53 | if url == "" { 54 | name = got.FullName() 55 | } 56 | return &ErrUnexpectedType{ 57 | URL: url, 58 | Name: name, 59 | Expecting: expecting, 60 | Descriptor: got, 61 | } 62 | } 63 | 64 | // Error implements the error interface. 65 | func (e *ErrUnexpectedType) Error() string { 66 | var queryKind, query string 67 | if e.URL != "" { 68 | queryKind = "URL" 69 | query = e.URL 70 | } else { 71 | queryKind = "name" 72 | query = string(e.Name) 73 | } 74 | return fmt.Sprintf("wrong kind of descriptor for %s %q: expected %s, got %s", queryKind, query, e.Expecting.withArticle(), e.Actual.withArticle()) 75 | } 76 | -------------------------------------------------------------------------------- /protoresolve/kind.go: -------------------------------------------------------------------------------- 1 | package protoresolve 2 | 3 | import ( 4 | "fmt" 5 | 6 | "google.golang.org/protobuf/reflect/protoreflect" 7 | ) 8 | 9 | // DescriptorKind represents the kind of a descriptor. Unlike other 10 | // descriptor-related APIs, DescriptorKind distinguishes between 11 | // extension fields (DescriptorKindExtension) and "regular", non-extension 12 | // fields (DescriptorKindField). 13 | type DescriptorKind int 14 | 15 | // The various supported DescriptorKind values. 16 | const ( 17 | DescriptorKindUnknown = DescriptorKind(iota) 18 | DescriptorKindFile 19 | DescriptorKindMessage 20 | DescriptorKindField 21 | DescriptorKindOneof 22 | DescriptorKindEnum 23 | DescriptorKindEnumValue 24 | DescriptorKindExtension 25 | DescriptorKindService 26 | DescriptorKindMethod 27 | ) 28 | 29 | // KindOf returns the DescriptorKind of the given descriptor d. 30 | func KindOf(d protoreflect.Descriptor) DescriptorKind { 31 | switch d := d.(type) { 32 | case protoreflect.FileDescriptor: 33 | return DescriptorKindFile 34 | case protoreflect.MessageDescriptor: 35 | return DescriptorKindMessage 36 | case protoreflect.FieldDescriptor: 37 | if d.IsExtension() { 38 | return DescriptorKindExtension 39 | } 40 | return DescriptorKindField 41 | case protoreflect.OneofDescriptor: 42 | return DescriptorKindOneof 43 | case protoreflect.EnumDescriptor: 44 | return DescriptorKindEnum 45 | case protoreflect.EnumValueDescriptor: 46 | return DescriptorKindEnumValue 47 | case protoreflect.ServiceDescriptor: 48 | return DescriptorKindService 49 | case protoreflect.MethodDescriptor: 50 | return DescriptorKindMethod 51 | default: 52 | return DescriptorKindUnknown 53 | } 54 | } 55 | 56 | // String returns a textual representation of k. 57 | func (k DescriptorKind) String() string { 58 | switch k { 59 | case DescriptorKindFile: 60 | return "file" 61 | case DescriptorKindMessage: 62 | return "message" 63 | case DescriptorKindField: 64 | return "field" 65 | case DescriptorKindOneof: 66 | return "oneof" 67 | case DescriptorKindEnum: 68 | return "enum" 69 | case DescriptorKindEnumValue: 70 | return "enum value" 71 | case DescriptorKindExtension: 72 | return "extension" 73 | case DescriptorKindService: 74 | return "service" 75 | case DescriptorKindMethod: 76 | return "method" 77 | case DescriptorKindUnknown: 78 | return "unknown" 79 | default: 80 | return fmt.Sprintf("unknown kind (%d)", k) 81 | } 82 | } 83 | 84 | func (k DescriptorKind) withArticle() string { 85 | switch k { 86 | case DescriptorKindFile: 87 | return "a file" 88 | case DescriptorKindMessage: 89 | return "a message" 90 | case DescriptorKindField: 91 | return "a field" 92 | case DescriptorKindOneof: 93 | return "a oneof" 94 | case DescriptorKindEnum: 95 | return "an enum" 96 | case DescriptorKindEnumValue: 97 | return "an enum value" 98 | case DescriptorKindExtension: 99 | return "an extension" 100 | case DescriptorKindService: 101 | return "a service" 102 | case DescriptorKindMethod: 103 | return "a method" 104 | case DescriptorKindUnknown: 105 | return "unknown" 106 | default: 107 | return fmt.Sprintf("unknown kind (%d)", k) 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /protoresolve/registry_test.go: -------------------------------------------------------------------------------- 1 | package protoresolve_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/require" 7 | "google.golang.org/protobuf/reflect/protoregistry" 8 | 9 | "github.com/jhump/protoreflect/v2/protoresolve" 10 | ) 11 | 12 | func TestRegistry(t *testing.T) { 13 | // TODO 14 | testResolver(t, &protoresolve.Registry{}) 15 | } 16 | 17 | func TestFromFiles(t *testing.T) { 18 | // TODO 19 | reg, err := protoresolve.FromFiles(protoregistry.GlobalFiles) 20 | require.NoError(t, err) 21 | testResolver(t, reg) 22 | 23 | reg, err = protoresolve.FromFiles(&protoregistry.Files{}) 24 | require.NoError(t, err) 25 | testResolver(t, reg) 26 | } 27 | -------------------------------------------------------------------------------- /protoresolve/resolver_test.go: -------------------------------------------------------------------------------- 1 | package protoresolve_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/jhump/protoreflect/v2/protoresolve" 7 | ) 8 | 9 | func testResolver(t *testing.T, res protoresolve.Resolver) { 10 | // TODO 11 | } 12 | -------------------------------------------------------------------------------- /sourceinfo/cmd/protoc-gen-gosrcinfo/main.go: -------------------------------------------------------------------------------- 1 | // Command protoc-gen-gosrcinfo is a protoc plugin. It emits Go code, into files 2 | // named ".pb.srcinfo.go". These source files include source code info for 3 | // processed proto files and register that info with the srcinfo package. 4 | package main 5 | 6 | import ( 7 | "bytes" 8 | "compress/gzip" 9 | "fmt" 10 | 11 | "google.golang.org/protobuf/compiler/protogen" 12 | "google.golang.org/protobuf/proto" 13 | "google.golang.org/protobuf/types/descriptorpb" 14 | "google.golang.org/protobuf/types/pluginpb" 15 | ) 16 | 17 | func main() { 18 | protogen.Options{}.Run(genSourceInfo) 19 | } 20 | 21 | func genSourceInfo(plugin *protogen.Plugin) error { 22 | plugin.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL | 23 | pluginpb.CodeGeneratorResponse_FEATURE_SUPPORTS_EDITIONS) 24 | plugin.SupportedEditionsMinimum = descriptorpb.Edition_EDITION_2023 25 | plugin.SupportedEditionsMaximum = descriptorpb.Edition_EDITION_2023 26 | for _, f := range plugin.Files { 27 | if f.Generate { 28 | if err := generateSourceInfo(f, plugin); err != nil { 29 | return fmt.Errorf("%s: %v", f.Desc.Path(), err) 30 | } 31 | } 32 | } 33 | return nil 34 | } 35 | 36 | func generateSourceInfo(f *protogen.File, plugin *protogen.Plugin) error { 37 | si := f.Proto.GetSourceCodeInfo() 38 | if len(si.GetLocation()) == 0 { 39 | return nil 40 | } 41 | out := plugin.NewGeneratedFile(f.GeneratedFilenamePrefix+".pb.srcinfo.go", f.GoImportPath) 42 | out.P("// Code generated by protoc-gen-gosrcinfo. DO NOT EDIT.") 43 | out.P("// source: ", f.Desc.Path()) 44 | out.P() 45 | out.P("package ", f.GoPackageName) 46 | out.P() 47 | 48 | siBytes, err := proto.Marshal(si) 49 | if err != nil { 50 | return fmt.Errorf("failed to serialize source code info: %w", err) 51 | } 52 | // Source code info has lots of repeated sequences of bytes in the 'path' field 53 | // of locations, and the comments tend to be text that is reasonably well 54 | // compressed. So we can make binaries a little smaller by gzipping first. 55 | var encodedBuf bytes.Buffer 56 | zipWriter := gzip.NewWriter(&encodedBuf) 57 | if _, err := zipWriter.Write(siBytes); err != nil { 58 | return fmt.Errorf("failed to compress source code info: %w", err) 59 | } 60 | if err := zipWriter.Close(); err != nil { 61 | return fmt.Errorf("failed to compress source code info: %w", err) 62 | } 63 | 64 | srcInfoPkg := protogen.GoImportPath("github.com/jhump/protoreflect/v2/sourceinfo") 65 | 66 | out.P("func init() {") 67 | out.P(" srcInfo := []byte{") 68 | encodedBytes := encodedBuf.Bytes() 69 | var buf bytes.Buffer 70 | for len(encodedBytes) > 0 { 71 | var chunk []byte 72 | if len(encodedBytes) < 16 { 73 | chunk = encodedBytes 74 | encodedBytes = nil 75 | } else { 76 | chunk = encodedBytes[:16] 77 | encodedBytes = encodedBytes[16:] 78 | } 79 | buf.Reset() 80 | for _, b := range chunk { 81 | _, _ = fmt.Fprintf(&buf, " 0x%02x,", b) 82 | } 83 | out.P(buf.String()) 84 | } 85 | out.P(" }") 86 | out.P(" ", srcInfoPkg.Ident("Register"), "(", fmt.Sprintf("%q", f.Desc.Path()), ", srcInfo)") 87 | out.P("}") 88 | return nil 89 | } 90 | -------------------------------------------------------------------------------- /sourceinfo/doc.go: -------------------------------------------------------------------------------- 1 | // Package sourceinfo provides the ability to register and query source code info 2 | // for file descriptors that are compiled into the binary. This data is registered 3 | // by code generated from the protoc-gen-gosrcinfo plugin. 4 | // 5 | // The standard descriptors bundled into the compiled binary are stripped of source 6 | // code info, to reduce binary size and reduce runtime memory footprint. However, 7 | // the source code info can be very handy and worth the size cost when used with 8 | // gRPC services and the server reflection service. Without source code info, the 9 | // descriptors that a client downloads from the reflection service have no comments. 10 | // But the presence of comments, and the ability to show them to humans, can greatly 11 | // improve the utility of user agents that use the reflection service. 12 | // 13 | // In order to make the reflection service use this functionality, you will need to 14 | // be using v1.45 or higher of the Go runtime for gRPC (google.golang.org/grpc). The 15 | // following snippet demonstrates how to do this in your server. Do this instead of 16 | // using the reflection.Register function: 17 | // 18 | // refSvr := reflection.NewServer(reflection.ServerOptions{ 19 | // Services: grpcServer, 20 | // DescriptorResolver: sourceinfo.Files, 21 | // ExtensionResolver: sourceinfo.Types, 22 | // }) 23 | // grpc_reflection_v1alpha.RegisterServerReflectionServer(grpcServer, refSvr) 24 | package sourceinfo 25 | -------------------------------------------------------------------------------- /sourceinfo/export_test.go: -------------------------------------------------------------------------------- 1 | package sourceinfo 2 | 3 | import "google.golang.org/protobuf/reflect/protoreflect" 4 | 5 | // exported for tests 6 | 7 | func CanUpgrade(d protoreflect.Descriptor) bool { 8 | return canUpgrade(d) 9 | } 10 | 11 | func UpdateDescriptor[D protoreflect.Descriptor](d D) (D, error) { 12 | return updateDescriptor(d) 13 | } 14 | 15 | func UpdateField(fld protoreflect.FieldDescriptor) (protoreflect.FieldDescriptor, error) { 16 | return updateField(fld) 17 | } 18 | --------------------------------------------------------------------------------