├── .github └── workflows │ ├── go_release.yml │ ├── ruby_release.yml │ └── tests.yml ├── .gitignore ├── .ruby-version ├── CONTRIBUTING.md ├── Gemfile ├── LICENSE ├── README.md ├── RELEASE_NOTES.md ├── Rakefile ├── example ├── .ruby-version ├── Gemfile ├── Gemfile.lock ├── README.md ├── hello_world │ ├── service.proto │ ├── service_pb.rb │ └── service_twirp.rb ├── hello_world_client.rb └── hello_world_server.rb ├── example_rack2 ├── Gemfile ├── Gemfile.lock ├── README.md ├── hello_world_client.rb └── hello_world_server.rb ├── gemfiles ├── faraday-0.gemfile ├── faraday-1.gemfile ├── faraday-2.gemfile ├── rack-2.gemfile └── rack-3.gemfile ├── go.mod ├── go.sum ├── internal └── gen │ └── typemap │ ├── testdata │ ├── fileset.pb │ ├── gen.go │ ├── importer.proto │ ├── public_importer.proto │ ├── public_reimporter.proto │ ├── root_pkg.proto │ └── service.proto │ ├── typemap.go │ └── typemap_test.go ├── lib ├── twirp.rb └── twirp │ ├── client.rb │ ├── client_json.rb │ ├── client_resp.rb │ ├── encoding.rb │ ├── error.rb │ ├── service.rb │ ├── service_dsl.rb │ └── version.rb ├── protoc-gen-twirp_ruby ├── main.go ├── main_test.go ├── testdata │ ├── fileset.pb │ ├── gen.go │ └── rubytypes.proto └── version.go ├── test ├── client_json_test.rb ├── client_test.rb ├── error_test.rb ├── fake_services.rb ├── license_header_test.rb └── service_test.rb ├── twirp.gemspec └── vendor ├── github.com ├── davecgh │ └── go-spew │ │ ├── LICENSE │ │ └── spew │ │ ├── bypass.go │ │ ├── bypasssafe.go │ │ ├── common.go │ │ ├── config.go │ │ ├── doc.go │ │ ├── dump.go │ │ ├── format.go │ │ └── spew.go ├── pkg │ └── errors │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README.md │ │ ├── appveyor.yml │ │ ├── errors.go │ │ ├── go113.go │ │ └── stack.go ├── pmezard │ └── go-difflib │ │ ├── LICENSE │ │ └── difflib │ │ └── difflib.go └── stretchr │ └── testify │ ├── LICENSE │ ├── assert │ ├── assertion_format.go │ ├── assertion_format.go.tmpl │ ├── assertion_forward.go │ ├── assertion_forward.go.tmpl │ ├── assertions.go │ ├── doc.go │ ├── errors.go │ ├── forward_assertions.go │ └── http_assertions.go │ └── require │ ├── doc.go │ ├── forward_requirements.go │ ├── require.go │ ├── require.go.tmpl │ ├── require_forward.go │ ├── require_forward.go.tmpl │ └── requirements.go ├── google.golang.org └── protobuf │ ├── LICENSE │ ├── PATENTS │ ├── encoding │ ├── prototext │ │ ├── decode.go │ │ ├── doc.go │ │ └── encode.go │ └── protowire │ │ └── wire.go │ ├── internal │ ├── descfmt │ │ └── stringer.go │ ├── descopts │ │ └── options.go │ ├── detrand │ │ └── rand.go │ ├── editiondefaults │ │ ├── defaults.go │ │ └── editions_defaults.binpb │ ├── encoding │ │ ├── defval │ │ │ └── default.go │ │ ├── messageset │ │ │ └── messageset.go │ │ ├── tag │ │ │ └── tag.go │ │ └── text │ │ │ ├── decode.go │ │ │ ├── decode_number.go │ │ │ ├── decode_string.go │ │ │ ├── decode_token.go │ │ │ ├── doc.go │ │ │ └── encode.go │ ├── errors │ │ └── errors.go │ ├── filedesc │ │ ├── build.go │ │ ├── desc.go │ │ ├── desc_init.go │ │ ├── desc_lazy.go │ │ ├── desc_list.go │ │ ├── desc_list_gen.go │ │ ├── editions.go │ │ └── placeholder.go │ ├── filetype │ │ └── build.go │ ├── flags │ │ ├── flags.go │ │ ├── proto_legacy_disable.go │ │ └── proto_legacy_enable.go │ ├── genid │ │ ├── any_gen.go │ │ ├── api_gen.go │ │ ├── descriptor_gen.go │ │ ├── doc.go │ │ ├── duration_gen.go │ │ ├── empty_gen.go │ │ ├── field_mask_gen.go │ │ ├── go_features_gen.go │ │ ├── goname.go │ │ ├── map_entry.go │ │ ├── name.go │ │ ├── source_context_gen.go │ │ ├── struct_gen.go │ │ ├── timestamp_gen.go │ │ ├── type_gen.go │ │ ├── wrappers.go │ │ └── wrappers_gen.go │ ├── impl │ │ ├── api_export.go │ │ ├── api_export_opaque.go │ │ ├── bitmap.go │ │ ├── bitmap_race.go │ │ ├── checkinit.go │ │ ├── codec_extension.go │ │ ├── codec_field.go │ │ ├── codec_field_opaque.go │ │ ├── codec_gen.go │ │ ├── codec_map.go │ │ ├── codec_message.go │ │ ├── codec_message_opaque.go │ │ ├── codec_messageset.go │ │ ├── codec_tables.go │ │ ├── codec_unsafe.go │ │ ├── convert.go │ │ ├── convert_list.go │ │ ├── convert_map.go │ │ ├── decode.go │ │ ├── encode.go │ │ ├── enum.go │ │ ├── equal.go │ │ ├── extension.go │ │ ├── lazy.go │ │ ├── legacy_enum.go │ │ ├── legacy_export.go │ │ ├── legacy_extension.go │ │ ├── legacy_file.go │ │ ├── legacy_message.go │ │ ├── merge.go │ │ ├── merge_gen.go │ │ ├── message.go │ │ ├── message_opaque.go │ │ ├── message_opaque_gen.go │ │ ├── message_reflect.go │ │ ├── message_reflect_field.go │ │ ├── message_reflect_field_gen.go │ │ ├── message_reflect_gen.go │ │ ├── pointer_unsafe.go │ │ ├── pointer_unsafe_opaque.go │ │ ├── presence.go │ │ └── validate.go │ ├── order │ │ ├── order.go │ │ └── range.go │ ├── pragma │ │ └── pragma.go │ ├── protolazy │ │ ├── bufferreader.go │ │ ├── lazy.go │ │ └── pointer_unsafe.go │ ├── set │ │ └── ints.go │ ├── strs │ │ ├── strings.go │ │ └── strings_unsafe.go │ └── version │ │ └── version.go │ ├── proto │ ├── checkinit.go │ ├── decode.go │ ├── decode_gen.go │ ├── doc.go │ ├── encode.go │ ├── encode_gen.go │ ├── equal.go │ ├── extension.go │ ├── merge.go │ ├── messageset.go │ ├── proto.go │ ├── proto_methods.go │ ├── proto_reflect.go │ ├── reset.go │ ├── size.go │ ├── size_gen.go │ ├── wrapperopaque.go │ └── wrappers.go │ ├── reflect │ ├── protoreflect │ │ ├── methods.go │ │ ├── proto.go │ │ ├── source.go │ │ ├── source_gen.go │ │ ├── type.go │ │ ├── value.go │ │ ├── value_equal.go │ │ ├── value_union.go │ │ └── value_unsafe.go │ └── protoregistry │ │ └── registry.go │ ├── runtime │ ├── protoiface │ │ ├── legacy.go │ │ └── methods.go │ └── protoimpl │ │ ├── impl.go │ │ └── version.go │ └── types │ ├── descriptorpb │ └── descriptor.pb.go │ └── pluginpb │ └── plugin.pb.go └── modules.txt /.github/workflows/go_release.yml: -------------------------------------------------------------------------------- 1 | name: Go Release 2 | run-name: "Release Go v${{ github.event.inputs.version }}" 3 | 4 | on: 5 | workflow_dispatch: 6 | inputs: 7 | version: 8 | description: 'Go version to release (e.g., 1.13.0)' 9 | required: true 10 | 11 | jobs: 12 | run-tests: 13 | name: Run Tests 14 | uses: ./.github/workflows/tests.yml 15 | 16 | release: 17 | runs-on: ubuntu-latest 18 | needs: run-tests 19 | steps: 20 | - name: Checkout code 21 | uses: actions/checkout@v4 22 | 23 | - name: Configure Git 24 | run: | 25 | git config user.name "${GITHUB_ACTOR}" 26 | git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" 27 | 28 | - name: Tag and push 29 | run: | 30 | # Create and push both tags 31 | git tag go-v${{ github.event.inputs.version }} 32 | git push origin go-v${{ github.event.inputs.version }} 33 | 34 | # Also create standard Go module version tag 35 | git tag v${{ github.event.inputs.version }} 36 | git push origin v${{ github.event.inputs.version }} 37 | 38 | - name: Create GitHub Release 39 | uses: softprops/action-gh-release@v2 40 | with: 41 | tag_name: v${{ github.event.inputs.version }} 42 | name: Go v${{ github.event.inputs.version }} 43 | body: | 44 | Go Release v${{ github.event.inputs.version }} 45 | 46 | See RELEASE_NOTES.md for details. 47 | draft: false 48 | env: 49 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 50 | -------------------------------------------------------------------------------- /.github/workflows/ruby_release.yml: -------------------------------------------------------------------------------- 1 | name: Ruby Release 2 | run-name: "Release Ruby v${{ github.event.inputs.version }}" 3 | 4 | on: 5 | workflow_dispatch: 6 | inputs: 7 | version: 8 | description: 'Ruby version to release (e.g., 1.13.0)' 9 | required: true 10 | 11 | jobs: 12 | run-tests: 13 | name: Run Tests 14 | uses: ./.github/workflows/tests.yml 15 | 16 | release: 17 | runs-on: ubuntu-latest 18 | needs: run-tests 19 | steps: 20 | - name: Checkout code 21 | uses: actions/checkout@v4 22 | 23 | - name: Set up Ruby 24 | uses: ruby/setup-ruby@v1 25 | with: 26 | ruby-version: '3.1' 27 | bundler-cache: true 28 | 29 | - name: Configure Git 30 | run: | 31 | git config user.name "${GITHUB_ACTOR}" 32 | git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" 33 | 34 | - name: Create GitHub Release 35 | uses: softprops/action-gh-release@v2 36 | with: 37 | tag_name: ruby-v${{ github.event.inputs.version }} 38 | name: Ruby v${{ github.event.inputs.version }} 39 | body: | 40 | Ruby Release v${{ github.event.inputs.version }} 41 | https://rubygems.org/gems/twirp/versions/${{ github.event.inputs.version }} 42 | 43 | See RELEASE_NOTES.md for details. 44 | draft: false 45 | env: 46 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 47 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Run Tests 2 | 3 | on: 4 | workflow_call: {} # This makes the workflow reusable 5 | push: 6 | branches: [ main ] 7 | pull_request: 8 | branches: [ main ] 9 | 10 | jobs: 11 | ruby-test: 12 | runs-on: ubuntu-latest 13 | name: Ruby ${{ matrix.ruby_version }} with ${{ matrix.gemfile }} 14 | env: 15 | BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile 16 | 17 | strategy: 18 | matrix: 19 | ruby_version: 20 | - "3.0" 21 | - "3.1" 22 | - "head" 23 | gemfile: 24 | - "faraday-0" 25 | - "faraday-1" 26 | - "faraday-2" 27 | - "rack-2" 28 | - "rack-3" 29 | 30 | steps: 31 | - uses: actions/checkout@v4 32 | 33 | - name: Set up Ruby 34 | uses: ruby/setup-ruby@v1 35 | with: 36 | ruby-version: ${{ matrix.ruby_version }} 37 | bundler-cache: true 38 | 39 | - name: Run Tests 40 | run: bundle exec rake test 41 | go-tests: 42 | runs-on: ubuntu-latest 43 | steps: 44 | - uses: actions/checkout@v4 45 | 46 | - name: Set up Go 47 | uses: actions/setup-go@v4 48 | with: 49 | go-version: '1.22' 50 | 51 | - name: Run Go tests 52 | run: go test ./protoc-gen-twirp_ruby/... ./internal/gen/typemap/... 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | 3 | *.gem 4 | 5 | /Gemfile.lock 6 | /gemfiles/*.lock 7 | 8 | vendor/ruby 9 | example/vendor 10 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 3.1.0 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribute to Twirp-Ruby 2 | 3 | ## Issues and Pull Requests 4 | 5 | Features and bugfixes are managed through [GitHub's Issues and Pull Requests](https://github.com/arthurnn/twirp-ruby/issues). Contributions are welcome and once approved, they are merged into master. 6 | 7 | ## Run tests and example code 8 | 9 | * Install gems: `bundle install` 10 | * Run Ruby tests: `rake` 11 | * Run Go tests (test code generation): `go test ./protoc-gen-twirp_ruby/... ./internal/gen/typemap/...` 12 | * Run example code (see [example/README.md](example/README.md)). 13 | 14 | ## Release Process 15 | 16 | The Ruby and Go components now have separate release processes. They are no longer coupled in terms of versioning. 17 | 18 | * Ruby library follows [Semantic Versioning (SemVer)](https://semver.org/), using tags like `ruby-v1.13.0` 19 | * Go library follows [Go module versioning conventions](https://go.dev/doc/modules/version-numbers) 20 | 21 | Both components can be released using GitHub Actions workflows. 22 | 23 | ### Ruby Release Process 24 | 25 | 1. Update the version in [`lib/twirp/version.rb`](lib/twirp/version.rb) following semantic versioning. 26 | 2. Commit and push these changes to the main branch: 27 | 28 | ```bash 29 | git commit -am "Bump Ruby version to vX.Y.Z" 30 | git push origin main 31 | ``` 32 | 33 | 3. Go to the Actions tab in the GitHub repository and select the "Ruby Release" workflow. 34 | 4. Click "Run workflow" and provide: 35 | * Version: The version number without the 'v' prefix (e.g., "1.13.0") 36 | 5. Click "Run workflow" to start the release process. 37 | 38 | The workflow will: 39 | 40 | * Run all Ruby tests 41 | * Create a Git tag with format `ruby-vX.Y.Z` 42 | * Create a GitHub Release 43 | 44 | 6. Run `bundle exec rake release` locally to push the gem 45 | 46 | 7. Verify the gem is available at [https://rubygems.org/gems/twirp](https://rubygems.org/gems/twirp) 47 | 48 | ### Go Release Process 49 | 50 | 1. Update the version in [`protoc-gen-twirp_ruby/version.go`](protoc-gen-twirp_ruby/version.go) following semantic versioning. 51 | 2. Commit and push these changes to the main branch: 52 | 53 | ```bash 54 | git commit -am "Bump Go version to vX.Y.Z" 55 | git push origin main 56 | ``` 57 | 58 | 3. Go to the Actions tab in the GitHub repository and select the "Go Release" workflow. 59 | 4. Click "Run workflow" and provide: 60 | * Version: The version number without the 'v' prefix (e.g., "1.13.0") 61 | 5. Click "Run workflow" to start the release process. 62 | 63 | The workflow will: 64 | 65 | * Run all Go tests 66 | * Create Git tags with formats `go-vX.Y.Z` and `vX.Y.Z` (for Go modules compatibility) 67 | * Create a GitHub Release 68 | 69 | 6. Verify the release is visible on the [GitHub Releases page](https://github.com/arthurnn/twirp-ruby/releases) 70 | 71 | 72 | ## General Notes 73 | 74 | * The two components can be released independently according to their own development schedules 75 | * Always test both Ruby and Go components before releasing either one 76 | * Update the [`RELEASE_NOTES.md`](RELEASE_NOTES.md) file with significant changes for both Ruby and Go releases 77 | * The GitHub workflows automate most of the release process but still require manual version updates 78 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gemspec 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Twirp-Ruby 2 | 3 | [![Run Tests](https://github.com/arthurnn/twirp-ruby/actions/workflows/tests.yml/badge.svg)](https://github.com/arthurnn/twirp-ruby/actions/workflows/tests.yml) 4 | 5 | [Twirp is a protocol](https://twitchtv.github.io/twirp/docs/spec_v5.html) for routing and serialization of services defined in a [.proto file](https://developers.google.com/protocol-buffers/docs/proto3), allowing easy implementation of RPC services with auto-generated clients in different languages. 6 | 7 | The [canonical implementation](https://github.com/twitchtv/twirp) is in Golang. The Twirp-Ruby project is the official implementation in Ruby for both server and clients. 8 | 9 | 10 | ## Install 11 | 12 | Add `gem "twirp"` to your Gemfile, or install with `gem install twirp`. 13 | 14 | To auto-generate Ruby code from a proto file, use the `protoc` plugin and the `--ruby_out` option ([see Wiki page](https://github.com/arthurnn/twirp-ruby/wiki/Code-Generation)). 15 | 16 | ### No backwards compatible breaking changes, between minor versions(1.10.0) 17 | 18 | When upgrading from version 1.9.0 to 1.10.0, note that there is a breaking change in the `Twirp::ClientResp#initialize` method. The method now accepts keyword arguments. For more details, refer to this [comparison](https://github.com/arthurnn/twirp-ruby/compare/v1.9.0...v1.10.0#diff-b3c497150f4ae769df1a5d90e43142983cfd4d780392cbaa218d74912fa3a174) and this [issue](https://github.com/arthurnn/twirp-ruby/issues/99). 19 | 20 | ## Documentation 21 | 22 | [On the wiki](https://github.com/arthurnn/twirp-ruby/wiki). 23 | 24 | ## Contributing 25 | 26 | [On the CONTRIBUTING file](CONTRIBUTING.md). 27 | 28 | ## Releases and changes 29 | 30 | See the [releases](https://github.com/arthurnn/twirp-ruby/releases) page for latest information about released versions. 31 | -------------------------------------------------------------------------------- /RELEASE_NOTES.md: -------------------------------------------------------------------------------- 1 | # Twirp-Ruby: Release notes 2 | 3 | ## Important: Separate Release Cycles 4 | 5 | **Since v1.10.0, Go and Ruby components have different release cycles and version numbers.** 6 | 7 | Releases are tagged in git with the `ruby-` and `go-` prefixes. To follow [Go module versioning conventions](https://go.dev/doc/modules/version-numbers) the Go releases are also tagged as `vX.Y.Z`. 8 | 9 | ## Go 10 | 11 | ### 1.14.1 12 | 13 | https://github.com/arthurnn/twirp-ruby/compare/go-v1.14.0...go-v1.14.1 14 | 15 | Bumping version to fix tag 16 | 17 | ### 1.14.0 18 | 19 | https://github.com/arthurnn/twirp-ruby/compare/v1.13.0...go-v1.14.0 20 | 21 | - Update `google.golang.org/protobuf`(v1.36.6) and drop `github.com/golang/protobuf` dependency [#131](https://github.com/arthurnn/twirp-ruby/pull/131) 22 | 23 | ### 1.13.0 & 1.12.0 & 1.11.0 24 | 25 | No changes to go files: 26 | https://github.com/arthurnn/twirp-ruby/compare/v1.10.0...v1.13.0 27 | 28 | ## Ruby 29 | 30 | ### 1.13.1 31 | 32 | https://github.com/arthurnn/twirp-ruby/compare/v1.13.0...ruby-v1.31.1 33 | 34 | No ruby runtime changes, only ajusting docs. 35 | 36 | ### 1.13.0 37 | 38 | https://github.com/arthurnn/twirp-ruby/compare/v1.12.0...v1.13.0 39 | 40 | - [Rack 3.0 support](https://github.com/arthurnn/twirp-ruby/pull/124) 41 | - [Better handle nil response status in client](https://github.com/arthurnn/twirp-ruby/pull/127) 42 | 43 | ### 1.12.0 44 | 45 | https://github.com/arthurnn/twirp-ruby/compare/v1.10.0...v1.12.0 46 | 47 | - [Expose response HTTP headers to the caller](https://github.com/arthurnn/twirp-ruby/pull/119) 48 | - [Allow google-protobuf v4](https://github.com/arthurnn/twirp-ruby/pull/122) 49 | - Lock Rack version to be < 3, until we fix Rack 3 compatibility 50 | 51 | ### 1.11.0 - not released 52 | 53 | No ruby release for this version, despite an existent tag. 54 | https://github.com/arthurnn/twirp-ruby/compare/v1.10.0...v1.11.0 55 | 56 | There was no ruby change for this version therefor not release, instead that mark the de-coupling of the Go toolchain with the ruby version. 57 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | require "bundler/gem_helper" 3 | require "rake/testtask" 4 | 5 | # Override Bundler's gem release tasks to use the new tag format 6 | class CustomGemHelper < Bundler::GemHelper 7 | def version_tag 8 | "ruby-v#{version}" 9 | end 10 | end 11 | 12 | # Replace the standard gem tasks with our custom implementation 13 | CustomGemHelper.install_tasks 14 | 15 | Rake::TestTask.new do |t| 16 | t.test_files = FileList['test/*_test.rb'] 17 | t.warning = false 18 | end 19 | 20 | task :default => :test 21 | -------------------------------------------------------------------------------- /example/.ruby-version: -------------------------------------------------------------------------------- 1 | 3.1.0 2 | -------------------------------------------------------------------------------- /example/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gem "rack", ">= 3.0.0" 4 | gem "rackup" 5 | gem "google-protobuf", "~> 3" 6 | gem "twirp", path: "../" 7 | -------------------------------------------------------------------------------- /example/Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: .. 3 | specs: 4 | twirp (1.13.1) 5 | faraday (< 3) 6 | google-protobuf (>= 3.25, < 5.a) 7 | rack (>= 2.2.3) 8 | 9 | GEM 10 | remote: https://rubygems.org/ 11 | specs: 12 | faraday (2.7.2) 13 | faraday-net_http (>= 2.0, < 3.1) 14 | ruby2_keywords (>= 0.0.4) 15 | faraday-net_http (3.0.2) 16 | google-protobuf (3.25.5) 17 | rack (3.1.7) 18 | rackup (2.0.0) 19 | rack (>= 3) 20 | webrick 21 | ruby2_keywords (0.0.5) 22 | webrick (1.7.0) 23 | 24 | PLATFORMS 25 | ruby 26 | 27 | DEPENDENCIES 28 | google-protobuf (~> 3) 29 | rack (>= 3.0.0) 30 | rackup 31 | twirp! 32 | 33 | BUNDLED WITH 34 | 2.4.2 35 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Twirp HelloWorld Example 2 | 3 | ### Run the example 4 | 5 | To run the example, first make sure you are in the /example folder: 6 | ```sh 7 | cd example 8 | ``` 9 | 10 | Install gems: 11 | ```sh 12 | gem install bundler 13 | bundle install 14 | ``` 15 | 16 | Start the hello_world server: 17 | ```sh 18 | bundle exec ruby hello_world_server.rb 19 | ``` 20 | 21 | Now you can send `curl` requests from another terminal window: 22 | ```sh 23 | curl --request POST \ 24 | --url http://localhost:8080/twirp/example.hello_world.HelloWorld/Hello \ 25 | --header 'Content-Type: application/json; strict=true' \ 26 | --data '{"name": "World"}' 27 | ``` 28 | 29 | To send requests from Ruby code, run the hello_world client example: 30 | ```sh 31 | bundle exec ruby hello_world_client.rb 32 | ``` 33 | 34 | ### Run code generation 35 | 36 | Try to add a new field in `./hello_world/service.proto`, then run the generator code and see if the new field was properly added in the generated files. 37 | 38 | Make sure you have the [protobuf compiler](https://github.com/golang/protobuf) (version 3+). 39 | 40 | MacOS: 41 | 42 | ```bash 43 | brew install protobuf 44 | ``` 45 | 46 | Install the twirp plugin with go: 47 | 48 | ```sh 49 | mkdir -p $GOPATH/src/github.com/arthurnn 50 | ln -s ~/src/twirp-ruby $GOPATH/src/github.com/arthurnn/twirp-ruby 51 | go install github.com/arthurnn/twirp-ruby/protoc-gen-twirp_ruby 52 | ``` 53 | 54 | From the `/example` folder, run the generator command: 55 | 56 | ```sh 57 | protoc --proto_path=. ./hello_world/service.proto --ruby_out=. --twirp_ruby_out=. 58 | ``` 59 | -------------------------------------------------------------------------------- /example/hello_world/service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package example.hello_world; 3 | 4 | 5 | service HelloWorld { 6 | rpc Hello(HelloRequest) returns (HelloResponse); 7 | } 8 | 9 | message HelloRequest { 10 | string name = 1; 11 | } 12 | 13 | message HelloResponse { 14 | string message = 1; 15 | } 16 | -------------------------------------------------------------------------------- /example/hello_world/service_pb.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | # Generated by the protocol buffer compiler. DO NOT EDIT! 3 | # source: hello_world/service.proto 4 | 5 | require 'google/protobuf' 6 | 7 | 8 | descriptor_data = "\n\x19hello_world/service.proto\x12\x13\x65xample.hello_world\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\" \n\rHelloResponse\x12\x0f\n\x07message\x18\x01 \x01(\t2\\\n\nHelloWorld\x12N\n\x05Hello\x12!.example.hello_world.HelloRequest\x1a\".example.hello_world.HelloResponseb\x06proto3" 9 | 10 | pool = Google::Protobuf::DescriptorPool.generated_pool 11 | pool.add_serialized_file(descriptor_data) 12 | 13 | module Example 14 | module HelloWorld 15 | HelloRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("example.hello_world.HelloRequest").msgclass 16 | HelloResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("example.hello_world.HelloResponse").msgclass 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /example/hello_world/service_twirp.rb: -------------------------------------------------------------------------------- 1 | # Code generated by protoc-gen-twirp_ruby 1.14.1, DO NOT EDIT. 2 | require 'twirp' 3 | require_relative 'service_pb.rb' 4 | 5 | module Example 6 | module HelloWorld 7 | class HelloWorldService < ::Twirp::Service 8 | package 'example.hello_world' 9 | service 'HelloWorld' 10 | rpc :Hello, HelloRequest, HelloResponse, :ruby_method => :hello 11 | end 12 | 13 | class HelloWorldClient < ::Twirp::Client 14 | client_for HelloWorldService 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /example/hello_world_client.rb: -------------------------------------------------------------------------------- 1 | require 'rack' 2 | 3 | require_relative 'hello_world/service_twirp.rb' 4 | 5 | # Assume hello_world_server is running locally 6 | c = Example::HelloWorld::HelloWorldClient.new("http://localhost:8080/twirp") 7 | 8 | resp = c.hello(name: "World") 9 | if resp.error 10 | puts resp.error 11 | else 12 | puts resp.data.message 13 | end 14 | -------------------------------------------------------------------------------- /example/hello_world_server.rb: -------------------------------------------------------------------------------- 1 | require 'rack' 2 | require 'rackup' 3 | 4 | require_relative 'hello_world/service_twirp.rb' 5 | 6 | # Service implementation 7 | class HelloWorldHandler 8 | def hello(req, env) 9 | puts ">> Hello #{req.name}" 10 | {message: "Hello #{req.name}"} 11 | end 12 | end 13 | 14 | # Instantiate Service 15 | handler = HelloWorldHandler.new() 16 | service = Example::HelloWorld::HelloWorldService.new(handler) 17 | 18 | 19 | # Mount on webserver 20 | path_prefix = "/twirp/" + service.full_name 21 | Rackup::Server.start app: service, Port: 8080 22 | -------------------------------------------------------------------------------- /example_rack2/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gem "rack", "< 3" 4 | gem "webrick" 5 | gem "google-protobuf", "~> 3.x" 6 | gem "twirp", path: "../" 7 | -------------------------------------------------------------------------------- /example_rack2/Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: .. 3 | specs: 4 | twirp (1.12.0) 5 | faraday (< 3) 6 | google-protobuf (>= 3.25, < 5.a) 7 | rack (>= 2.2.3) 8 | 9 | GEM 10 | remote: https://rubygems.org/ 11 | specs: 12 | faraday (2.7.2) 13 | faraday-net_http (>= 2.0, < 3.1) 14 | ruby2_keywords (>= 0.0.4) 15 | faraday-net_http (3.0.2) 16 | google-protobuf (3.25.4) 17 | rack (2.2.8.1) 18 | ruby2_keywords (0.0.5) 19 | webrick (1.8.2) 20 | 21 | PLATFORMS 22 | ruby 23 | 24 | DEPENDENCIES 25 | google-protobuf (~> 3.x) 26 | rack (< 3) 27 | twirp! 28 | webrick 29 | 30 | BUNDLED WITH 31 | 2.4.2 32 | -------------------------------------------------------------------------------- /example_rack2/README.md: -------------------------------------------------------------------------------- 1 | # Twirp HelloWorld Example for Rack 2 2 | 3 | This is identical to the other example, but tweaked to run under Rack 2. 4 | 5 | ### Run the example 6 | 7 | To run the example, first make sure you are in the /example folder: 8 | ```sh 9 | cd example 10 | ``` 11 | 12 | Install gems: 13 | ```sh 14 | gem install bundler 15 | bundle install 16 | ``` 17 | 18 | Start the hello_world server: 19 | ```sh 20 | bundle exec ruby hello_world_server.rb 21 | ``` 22 | 23 | Now you can send `curl` requests from another terminal window: 24 | ```sh 25 | curl --request POST \ 26 | --url http://localhost:8080/twirp/example.hello_world.HelloWorld/Hello \ 27 | --header 'Content-Type: application/json; strict=true' \ 28 | --data '{"name": "World"}' 29 | ``` 30 | 31 | To send requests from Ruby code, run the hello_world client example: 32 | ```sh 33 | bundle exec ruby hello_world_client.rb 34 | ``` 35 | 36 | ### Run code generation 37 | 38 | Try to add a new field in `./hello_world/service.proto`, then run the generator code and see if the new field was properly added in the generated files. 39 | 40 | Make sure you have the [protobuf compiler](https://github.com/golang/protobuf) (version 3+). 41 | 42 | Install the twirp plugin with go: 43 | ```sh 44 | go get -u github.com/arthurnn/twirp-ruby/protoc-gen-twirp_ruby 45 | ``` 46 | 47 | From the `/example` folder, run the generator command: 48 | ```sh 49 | protoc --proto_path=. ./hello_world/service.proto --ruby_out=. --twirp_ruby_out=. 50 | ``` 51 | -------------------------------------------------------------------------------- /example_rack2/hello_world_client.rb: -------------------------------------------------------------------------------- 1 | require_relative '../example/hello_world_client.rb' 2 | -------------------------------------------------------------------------------- /example_rack2/hello_world_server.rb: -------------------------------------------------------------------------------- 1 | require 'rack' 2 | require 'webrick' 3 | 4 | require_relative '../example/hello_world/service_twirp.rb' 5 | 6 | # Service implementation 7 | class HelloWorldHandler 8 | def hello(req, env) 9 | puts ">> Hello #{req.name}" 10 | {message: "Hello #{req.name}"} 11 | end 12 | end 13 | 14 | # Instantiate Service 15 | handler = HelloWorldHandler.new() 16 | service = Example::HelloWorld::HelloWorldService.new(handler) 17 | 18 | 19 | # Mount on webserver 20 | path_prefix = "/twirp/" + service.full_name 21 | server = WEBrick::HTTPServer.new(Port: 8080) 22 | server.mount path_prefix, Rack::Handler::WEBrick, service 23 | server.start 24 | -------------------------------------------------------------------------------- /gemfiles/faraday-0.gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gemspec path: '..' 3 | 4 | gem 'faraday', '~> 0' 5 | -------------------------------------------------------------------------------- /gemfiles/faraday-1.gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gemspec path: '..' 3 | 4 | gem 'faraday', '~> 1' 5 | -------------------------------------------------------------------------------- /gemfiles/faraday-2.gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gemspec path: '..' 3 | 4 | gem 'faraday', '~> 2' 5 | -------------------------------------------------------------------------------- /gemfiles/rack-2.gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gemspec path: '..' 3 | 4 | gem 'rack', '~> 2' 5 | -------------------------------------------------------------------------------- /gemfiles/rack-3.gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gemspec path: '..' 3 | 4 | gem 'rack', '~> 3' 5 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/arthurnn/twirp-ruby 2 | 3 | go 1.22 4 | 5 | require ( 6 | github.com/pkg/errors v0.9.1 7 | github.com/stretchr/testify v1.3.0 8 | google.golang.org/protobuf v1.36.6 9 | ) 10 | 11 | require ( 12 | github.com/davecgh/go-spew v1.1.1 // indirect 13 | github.com/pmezard/go-difflib v1.0.0 // indirect 14 | ) 15 | 16 | retract v7.1.2+incompatible 17 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 2 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 3 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 4 | github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= 5 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 6 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 7 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 8 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 9 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 10 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 11 | github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= 12 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 13 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= 14 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 15 | google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= 16 | google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= 17 | -------------------------------------------------------------------------------- /internal/gen/typemap/testdata/fileset.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurnn/twirp-ruby/56552fb3101c0357ad6dc4b1ba441c678eb241b3/internal/gen/typemap/testdata/fileset.pb -------------------------------------------------------------------------------- /internal/gen/typemap/testdata/gen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Twitch Interactive, Inc. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). You may not 4 | // use this file except in compliance with the License. A copy of the License is 5 | // located at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // or in the "license" file accompanying this file. This file is distributed on 10 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | // express or implied. See the License for the specific language governing 12 | // permissions and limitations under the License. 13 | 14 | package testdata 15 | 16 | //go:generate protoc --descriptor_set_out=fileset.pb --include_imports --include_source_info ./service.proto 17 | -------------------------------------------------------------------------------- /internal/gen/typemap/testdata/importer.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package twirp.internal.gen.typemap.testdata.importer; 4 | 5 | import "root_pkg.proto"; 6 | 7 | message ImporterMsg { 8 | root_pkg.RootMsg a = 1; 9 | 10 | message ImporterInner {} 11 | } 12 | -------------------------------------------------------------------------------- /internal/gen/typemap/testdata/public_importer.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package twirp.internal.gen.typemap.testdata.public_importer; 4 | 5 | import public "root_pkg.proto"; 6 | import public "importer.proto"; 7 | 8 | message PublicImporterMsgA { 9 | importer.ImporterMsg a = 1; 10 | } 11 | 12 | message PublicImporterMsgB { 13 | root_pkg.RootMsg a = 1; 14 | } 15 | -------------------------------------------------------------------------------- /internal/gen/typemap/testdata/public_reimporter.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package twirp.internal.gen.typemap.testdata.public_reimporter; 4 | 5 | import public "public_importer.proto"; 6 | 7 | message PublicReimporterMsg { 8 | public_importer.PublicImporterMsgA a = 1; 9 | public_importer.PublicImporterMsgB b = 2; 10 | root_pkg.RootMsg c = 3; 11 | importer.ImporterMsg d = 4; 12 | } 13 | -------------------------------------------------------------------------------- /internal/gen/typemap/testdata/root_pkg.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package twirp.internal.gen.typemap.testdata.root_pkg; 4 | 5 | // RootMsg leading 6 | message RootMsg {} 7 | -------------------------------------------------------------------------------- /internal/gen/typemap/testdata/service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package twirp.internal.gen.typemap.testdata.public_reimporter; 4 | 5 | import public "public_reimporter.proto"; 6 | 7 | message ServiceMsg { 8 | public_importer.PublicImporterMsgA a = 1; 9 | public_importer.PublicImporterMsgB b = 2; 10 | root_pkg.RootMsg c = 3; 11 | importer.ImporterMsg d = 4; 12 | } 13 | 14 | message Parent { 15 | message NestedOuter{ 16 | message NestedInner{} 17 | } 18 | } 19 | 20 | service EmptyService {} 21 | 22 | service ServiceWithOneMethod{ 23 | // Method1 leading 24 | rpc Method1(root_pkg.RootMsg) returns (importer.ImporterMsg); 25 | // Method1 trailing 26 | } 27 | 28 | // ServiceWithManyMethods leading 29 | service ServiceWithManyMethods{ 30 | // Method1 leading 31 | rpc Method1(root_pkg.RootMsg) returns (importer.ImporterMsg); 32 | // Method2 leading 33 | rpc Method2(Parent) returns (Parent.NestedOuter); 34 | // Method2 trailing 35 | 36 | rpc Method3(importer.ImporterMsg.ImporterInner) returns (Parent.NestedOuter.NestedInner); 37 | } 38 | -------------------------------------------------------------------------------- /internal/gen/typemap/typemap_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Twitch Interactive, Inc. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). You may not 4 | // use this file except in compliance with the License. A copy of the License is 5 | // located at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // or in the "license" file accompanying this file. This file is distributed on 10 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | // express or implied. See the License for the specific language governing 12 | // permissions and limitations under the License. 13 | 14 | package typemap 15 | 16 | import ( 17 | "io/ioutil" 18 | "path/filepath" 19 | "testing" 20 | 21 | "google.golang.org/protobuf/proto" 22 | descriptor "google.golang.org/protobuf/types/descriptorpb" 23 | "github.com/stretchr/testify/assert" 24 | "github.com/stretchr/testify/require" 25 | ) 26 | 27 | func loadTestPb(t *testing.T) []*descriptor.FileDescriptorProto { 28 | f, err := ioutil.ReadFile(filepath.Join("testdata", "fileset.pb")) 29 | require.NoError(t, err, "unable to read testdata protobuf file") 30 | 31 | set := new(descriptor.FileDescriptorSet) 32 | err = proto.Unmarshal(f, set) 33 | require.NoError(t, err, "unable to unmarshal testdata protobuf file") 34 | 35 | return set.File 36 | } 37 | 38 | func protoFile(files []*descriptor.FileDescriptorProto, name string) *descriptor.FileDescriptorProto { 39 | for _, f := range files { 40 | if filepath.Base(f.GetName()) == name { 41 | return f 42 | } 43 | } 44 | return nil 45 | } 46 | 47 | func service(f *descriptor.FileDescriptorProto, name string) *descriptor.ServiceDescriptorProto { 48 | for _, s := range f.Service { 49 | if s.GetName() == name { 50 | return s 51 | } 52 | } 53 | return nil 54 | } 55 | 56 | func method(s *descriptor.ServiceDescriptorProto, name string) *descriptor.MethodDescriptorProto { 57 | for _, m := range s.Method { 58 | if m.GetName() == name { 59 | return m 60 | } 61 | } 62 | return nil 63 | } 64 | 65 | func TestNewRegistry(t *testing.T) { 66 | files := loadTestPb(t) 67 | file := protoFile(files, "service.proto") 68 | service := service(file, "ServiceWithManyMethods") 69 | 70 | reg := New(files) 71 | 72 | comments, err := reg.ServiceComments(file, service) 73 | require.NoError(t, err, "unable to load service comments") 74 | assert.Equal(t, " ServiceWithManyMethods leading\n", comments.Leading) 75 | 76 | method1 := method(service, "Method1") 77 | require.NotNil(t, method1) 78 | 79 | method1Input := reg.MethodInputDefinition(method1) 80 | require.NotNil(t, method1Input) 81 | assert.Equal(t, "RootMsg", method1Input.Descriptor.GetName()) 82 | } 83 | -------------------------------------------------------------------------------- /lib/twirp.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Twitch Interactive, Inc. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not 4 | # use this file except in compliance with the License. A copy of the License is 5 | # located at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # or in the "license" file accompanying this file. This file is distributed on 10 | # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | # express or implied. See the License for the specific language governing 12 | # permissions and limitations under the License. 13 | 14 | require_relative 'twirp/version' 15 | require_relative 'twirp/error' 16 | require_relative 'twirp/service' 17 | require_relative 'twirp/client' 18 | require_relative 'twirp/client_json' 19 | -------------------------------------------------------------------------------- /lib/twirp/client_json.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Twitch Interactive, Inc. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not 4 | # use this file except in compliance with the License. A copy of the License is 5 | # located at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # or in the "license" file accompanying this file. This file is distributed on 10 | # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | # express or implied. See the License for the specific language governing 12 | # permissions and limitations under the License. 13 | 14 | require_relative 'client' 15 | 16 | module Twirp 17 | 18 | # Convenience class to call any rpc method with dynamic json attributes, without a service definition. 19 | # This is useful to test a service before doing any code-generation. 20 | class ClientJSON < Twirp::Client 21 | 22 | def initialize(conn, opts={}) 23 | super(conn, opts) 24 | 25 | package = opts[:package].to_s 26 | service = opts[:service].to_s 27 | @strict = opts.fetch( :strict, false ) 28 | raise ArgumentError.new("Missing option :service") if service.empty? 29 | @service_full_name = package.empty? ? service : "#{package}.#{service}" 30 | end 31 | 32 | # This implementation does not use the defined Protobuf messages to serialize/deserialize data; 33 | # the request attrs can be anything and the response data is always a plain Hash of attributes. 34 | def rpc(rpc_method, attrs={}, req_opts=nil) 35 | body = Encoding.encode_json(attrs) 36 | 37 | encoding = @strict ? Encoding::JSON_STRICT : Encoding::JSON 38 | resp = self.class.make_http_request(@conn, @service_full_name, rpc_method, encoding, req_opts, body) 39 | 40 | rpc_response_thennable(resp) do |resp| 41 | rpc_response_to_clientresp(resp) 42 | end 43 | end 44 | 45 | private 46 | 47 | def rpc_response_to_clientresp(resp) 48 | if resp.status != 200 49 | return ClientResp.new(error: self.class.error_from_response(resp), headers: resp.headers) 50 | end 51 | 52 | data = Encoding.decode_json(resp.body) 53 | return ClientResp.new(data: data, body: resp.body, headers: resp.headers) 54 | end 55 | 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /lib/twirp/client_resp.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Twitch Interactive, Inc. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not 4 | # use this file except in compliance with the License. A copy of the License is 5 | # located at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # or in the "license" file accompanying this file. This file is distributed on 10 | # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | # express or implied. See the License for the specific language governing 12 | # permissions and limitations under the License. 13 | 14 | module Twirp 15 | class ClientResp 16 | attr_accessor :data 17 | attr_accessor :body 18 | attr_accessor :error 19 | attr_accessor :headers 20 | 21 | def initialize(data: nil, body: nil, error: nil, headers: nil) 22 | @data = data 23 | @error = error 24 | @body = body 25 | @headers = headers 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /lib/twirp/encoding.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Twitch Interactive, Inc. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not 4 | # use this file except in compliance with the License. A copy of the License is 5 | # located at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # or in the "license" file accompanying this file. This file is distributed on 10 | # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | # express or implied. See the License for the specific language governing 12 | # permissions and limitations under the License. 13 | 14 | require 'json' 15 | 16 | module Twirp 17 | 18 | module Encoding 19 | JSON = "application/json" 20 | # An opt-in content type useful when curling or manually testing a twirp 21 | # service. This will fail if unknown fields are encountered. The return 22 | # content type will be application/json. 23 | JSON_STRICT = "application/json; strict=true" 24 | PROTO = "application/protobuf" 25 | 26 | class << self 27 | 28 | def decode(bytes, msg_class, content_type) 29 | case content_type 30 | when JSON then msg_class.decode_json(bytes, ignore_unknown_fields: true) 31 | when JSON_STRICT then msg_class.decode_json(bytes, ignore_unknown_fields: false) 32 | when PROTO then msg_class.decode(bytes) 33 | else raise ArgumentError.new("Invalid content_type") 34 | end 35 | end 36 | 37 | def encode(msg_obj, msg_class, content_type) 38 | case content_type 39 | when JSON, JSON_STRICT then msg_class.encode_json(msg_obj, emit_defaults: true) 40 | when PROTO then msg_class.encode(msg_obj) 41 | else raise ArgumentError.new("Invalid content_type") 42 | end 43 | end 44 | 45 | def encode_json(attrs) 46 | ::JSON.generate(attrs) 47 | end 48 | 49 | def decode_json(bytes) 50 | ::JSON.parse(bytes) 51 | end 52 | 53 | def valid_content_type?(content_type) 54 | content_type == JSON || content_type == PROTO || content_type == JSON_STRICT 55 | end 56 | 57 | def valid_content_types 58 | [JSON, PROTO] 59 | end 60 | 61 | end 62 | end 63 | 64 | end 65 | -------------------------------------------------------------------------------- /lib/twirp/error.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Twitch Interactive, Inc. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not 4 | # use this file except in compliance with the License. A copy of the License is 5 | # located at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # or in the "license" file accompanying this file. This file is distributed on 10 | # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | # express or implied. See the License for the specific language governing 12 | # permissions and limitations under the License. 13 | 14 | module Twirp 15 | 16 | # Valid Twirp error codes and their mapping to related HTTP status. 17 | # This can also be used to check if a code is valid (check if not nil). 18 | ERROR_CODES_TO_HTTP_STATUS = { 19 | canceled: 408, # Request Timeout 20 | invalid_argument: 400, # Bad Request 21 | malformed: 400, # Bad Request 22 | deadline_exceeded: 408, # Request Timeout 23 | not_found: 404, # Not Found 24 | bad_route: 404, # Not Found 25 | already_exists: 409, # Conflict 26 | permission_denied: 403, # Forbidden 27 | unauthenticated: 401, # Unauthorized 28 | resource_exhausted: 429, # Too Many Requests 29 | failed_precondition: 412, # Precondition Failed 30 | aborted: 409, # Conflict 31 | out_of_range: 400, # Bad Request 32 | 33 | internal: 500, # Internal Server Error 34 | unknown: 500, # Internal Server Error 35 | unimplemented: 501, # Not Implemented 36 | unavailable: 503, # Service Unavailable 37 | data_loss: 500, # Internal Server Error 38 | } 39 | 40 | # List of all valid error codes in Twirp 41 | ERROR_CODES = ERROR_CODES_TO_HTTP_STATUS.keys 42 | 43 | 44 | # Twirp::Error represents an error response from a Twirp service. 45 | # Twirp::Error is not an Exception to be raised, but a value to be returned 46 | # by service handlers and received by clients. 47 | class Error 48 | 49 | def self.valid_code?(code) 50 | ERROR_CODES_TO_HTTP_STATUS.key? code # one of the valid symbols 51 | end 52 | 53 | # Code constructors to ensure valid error codes. Example: 54 | # Twirp::Error.internal("boom") 55 | # Twirp::Error.invalid_argument("foo is mandatory", mymeta: "foobar") 56 | # Twirp::Error.permission_denied("Thou shall not pass!", target: "Balrog") 57 | ERROR_CODES.each do |code| 58 | define_singleton_method code do |msg, meta=nil| 59 | new(code, msg, meta) 60 | end 61 | end 62 | 63 | # Wrap another error as a Twirp::Error :internal. 64 | def self.internal_with(err) 65 | twerr = internal err.message, cause: err.class.name 66 | twerr.cause = err # availabe in error hook for inspection, but not in the response 67 | twerr 68 | end 69 | 70 | attr_reader :code, :msg, :meta 71 | 72 | attr_accessor :cause # used when wrapping another error, but this is not serialized 73 | 74 | # Initialize a Twirp::Error 75 | # The code must be one of the valid ERROR_CODES Symbols (e.g. :internal, :not_found, :permission_denied ...). 76 | # The msg is a String with the error message. 77 | # The meta is optional error metadata, if included it must be a Hash with String values. 78 | def initialize(code, msg, meta=nil) 79 | @code = code.to_sym 80 | @msg = msg.to_s 81 | @meta = validate_meta(meta) 82 | end 83 | 84 | # Key-value representation of the error. Can be directly serialized into JSON. 85 | def to_h 86 | h = { 87 | code: @code, 88 | msg: @msg, 89 | } 90 | h[:meta] = @meta unless @meta.empty? 91 | h 92 | end 93 | 94 | def to_s 95 | "" 96 | end 97 | 98 | def inspect 99 | to_s 100 | end 101 | 102 | 103 | private 104 | 105 | def validate_meta(meta) 106 | return {} if !meta 107 | 108 | if !meta.is_a? Hash 109 | raise ArgumentError.new("Twirp::Error meta must be a Hash, but it is a #{meta.class.to_s}") 110 | end 111 | meta.each do |key, value| 112 | if !value.is_a?(String) 113 | raise ArgumentError.new("Twirp::Error meta values must be Strings, but key #{key.inspect} has the value <#{value.class.to_s}> #{value.inspect}") 114 | end 115 | end 116 | meta 117 | end 118 | 119 | end 120 | end 121 | -------------------------------------------------------------------------------- /lib/twirp/service_dsl.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Twitch Interactive, Inc. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not 4 | # use this file except in compliance with the License. A copy of the License is 5 | # located at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # or in the "license" file accompanying this file. This file is distributed on 10 | # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | # express or implied. See the License for the specific language governing 12 | # permissions and limitations under the License. 13 | 14 | module Twirp 15 | 16 | module ServiceDSL 17 | 18 | # Configure service package name. 19 | def package(name) 20 | @package = name.to_s 21 | end 22 | 23 | # Configure service name. 24 | def service(name) 25 | @service = name.to_s 26 | end 27 | 28 | # Configure service rpc methods. 29 | def rpc(rpc_method, input_class, output_class, opts) 30 | raise ArgumentError.new("rpc_method can not be empty") if rpc_method.to_s.empty? 31 | raise ArgumentError.new("input_class must be a Protobuf Message class") unless input_class.is_a?(Class) 32 | raise ArgumentError.new("output_class must be a Protobuf Message class") unless output_class.is_a?(Class) 33 | raise ArgumentError.new("opts[:ruby_method] is mandatory") unless opts && opts[:ruby_method] 34 | 35 | rpcdef = { 36 | rpc_method: rpc_method.to_sym, # as defined in the Proto file. 37 | input_class: input_class, # google/protobuf Message class to serialize the input (proto request). 38 | output_class: output_class, # google/protobuf Message class to serialize the output (proto response). 39 | ruby_method: opts[:ruby_method].to_sym, # method on the handler or client to handle this rpc requests. 40 | } 41 | 42 | @rpcs ||= {} 43 | @rpcs[rpc_method.to_s] = rpcdef 44 | 45 | rpc_define_method(rpcdef) if respond_to? :rpc_define_method # hook for the client to implement the methods on the class 46 | end 47 | 48 | # Get configured package name as String. 49 | # An empty value means that there's no package. 50 | def package_name 51 | @package.to_s 52 | end 53 | 54 | # Service name as String. Defaults to the class name. 55 | def service_name 56 | (@service || self.name.split("::").last).to_s 57 | end 58 | 59 | # Service name with package prefix, which should uniquelly identifiy the service, 60 | # for example "example.v3.Haberdasher" for package "example.v3" and service "Haberdasher". 61 | # This can be used as a path prefix to route requests to the service, because a Twirp URL is: 62 | # "#{base_url}/#{service_full_name}/#{method]" 63 | def service_full_name 64 | package_name.empty? ? service_name : "#{package_name}.#{service_name}" 65 | end 66 | 67 | # Get raw definitions for rpc methods. 68 | # This values are used as base env for handler methods. 69 | def rpcs 70 | @rpcs || {} 71 | end 72 | 73 | end 74 | end 75 | -------------------------------------------------------------------------------- /lib/twirp/version.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Twitch Interactive, Inc. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not 4 | # use this file except in compliance with the License. A copy of the License is 5 | # located at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # or in the "license" file accompanying this file. This file is distributed on 10 | # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | # express or implied. See the License for the specific language governing 12 | # permissions and limitations under the License. 13 | 14 | module Twirp 15 | VERSION = '1.13.1' 16 | end 17 | -------------------------------------------------------------------------------- /protoc-gen-twirp_ruby/main_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "io/ioutil" 6 | "path/filepath" 7 | "reflect" 8 | "testing" 9 | 10 | "google.golang.org/protobuf/proto" 11 | descriptor "google.golang.org/protobuf/types/descriptorpb" 12 | plugin_go "google.golang.org/protobuf/types/pluginpb" 13 | "github.com/stretchr/testify/require" 14 | ) 15 | 16 | func loadTestPb(t *testing.T) []*descriptor.FileDescriptorProto { 17 | f, err := ioutil.ReadFile(filepath.Join("testdata", "fileset.pb")) 18 | require.NoError(t, err, "unable to read testdata protobuf file") 19 | 20 | set := new(descriptor.FileDescriptorSet) 21 | err = proto.Unmarshal(f, set) 22 | require.NoError(t, err, "unable to unmarshal testdata protobuf file") 23 | 24 | return set.File 25 | } 26 | 27 | func testGenerator(t *testing.T) *generator { 28 | genReq := &plugin_go.CodeGeneratorRequest{ 29 | FileToGenerate: []string{"rubytypes.proto"}, 30 | ProtoFile: loadTestPb(t), 31 | } 32 | return newGenerator(genReq) 33 | } 34 | 35 | func TestPrint(t *testing.T) { 36 | b := new(bytes.Buffer) 37 | print(b, "Hello World") 38 | print(b, "Hello %s %d", "My Friend", 999) 39 | actual := b.String() 40 | expected := "Hello World\nHello My Friend 999\n" 41 | if expected != actual { 42 | t.Errorf("Unexpected print: %v", actual) 43 | } 44 | } 45 | 46 | func TestFilePathOnlyBaseNoExtension(t *testing.T) { 47 | tests := []struct { 48 | actual string 49 | expected string 50 | }{ 51 | {noExtension("foo_bar.txt"), "foo_bar"}, 52 | {noExtension("my/filename.txt"), "my/filename"}, 53 | {onlyBase("foo_bar.txt"), "foo_bar.txt"}, 54 | {onlyBase("/long/path/stuff/foo_bar.txt"), "foo_bar.txt"}, 55 | {noExtension(onlyBase("/long/path/stuff/foo_bar.txt")), "foo_bar"}, 56 | } 57 | for _, tt := range tests { 58 | if tt.expected != tt.actual { 59 | t.Errorf("expected %v; actual %v", tt.expected, tt.actual) 60 | } 61 | } 62 | } 63 | 64 | func TestToRubyType(t *testing.T) { 65 | tests := []struct { 66 | protoType string 67 | expected string 68 | }{ 69 | {".twirp.rubytypes.foo.my_message", "Foo::MyMessage"}, 70 | {".twirp.rubytypes.m.v.p99.hello_world", "M::V::P99::HelloWorld"}, 71 | {".google.protobuf.Empty", "Google::Protobuf::Empty"}, 72 | } 73 | 74 | g := testGenerator(t) 75 | g.findProtoFilesToGenerate() 76 | 77 | for _, tt := range tests { 78 | actual := g.toRubyType(tt.protoType) 79 | if !reflect.DeepEqual(actual, tt.expected) { 80 | t.Errorf("expected %v; actual %v", tt.expected, actual) 81 | } 82 | } 83 | } 84 | 85 | func TestSplitRubyConstants(t *testing.T) { 86 | tests := []struct { 87 | pkgName string 88 | expected []string 89 | }{ 90 | {"", []string{}}, 91 | {"example", []string{"Example"}}, 92 | {"example.hello_world", []string{"Example", "HelloWorld"}}, 93 | {"m.v.p", []string{"M", "V", "P"}}, 94 | {"p99.a2z", []string{"P99", "A2z"}}, 95 | } 96 | for _, tt := range tests { 97 | actual := splitRubyConstants(tt.pkgName) 98 | if !reflect.DeepEqual(actual, tt.expected) { 99 | t.Errorf("expected %v; actual %v", tt.expected, actual) 100 | } 101 | } 102 | } 103 | 104 | func TestSnakeCase(t *testing.T) { 105 | tests := []struct { 106 | actual string 107 | expected string 108 | }{ 109 | {snakeCase("foo_bar"), "foo_bar"}, 110 | {snakeCase("FooBar"), "foo_bar"}, 111 | {snakeCase("fooBar"), "foo_bar"}, 112 | {snakeCase("myLong_miXEDName"), "my_long_mi_x_e_d_name"}, 113 | } 114 | for _, tt := range tests { 115 | if tt.expected != tt.actual { 116 | t.Errorf("expected %v; actual %v", tt.expected, tt.actual) 117 | } 118 | } 119 | } 120 | 121 | func TestCamelCase(t *testing.T) { 122 | tests := []struct { 123 | actual string 124 | expected string 125 | }{ 126 | {camelCase("foo_bar"), "FooBar"}, 127 | {camelCase("FooBar"), "FooBar"}, 128 | {camelCase("fooBar"), "FooBar"}, 129 | {camelCase("myLong_miXEDName"), "MyLongMiXEDName"}, 130 | {camelCase("a2z"), "A2z"}, 131 | {camelCase("a_2z"), "A2z"}, 132 | } 133 | for _, tt := range tests { 134 | if tt.expected != tt.actual { 135 | t.Errorf("expected %v; actual %v", tt.expected, tt.actual) 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /protoc-gen-twirp_ruby/testdata/fileset.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurnn/twirp-ruby/56552fb3101c0357ad6dc4b1ba441c678eb241b3/protoc-gen-twirp_ruby/testdata/fileset.pb -------------------------------------------------------------------------------- /protoc-gen-twirp_ruby/testdata/gen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Twitch Interactive, Inc. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). You may not 4 | // use this file except in compliance with the License. A copy of the License is 5 | // located at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // or in the "license" file accompanying this file. This file is distributed on 10 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | // express or implied. See the License for the specific language governing 12 | // permissions and limitations under the License. 13 | 14 | package testdata 15 | 16 | //go:generate protoc --descriptor_set_out=fileset.pb --include_imports --include_source_info ./rubytypes.proto 17 | -------------------------------------------------------------------------------- /protoc-gen-twirp_ruby/testdata/rubytypes.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package twirp.rubytypes; 4 | 5 | import "google/protobuf/empty.proto"; 6 | 7 | message foo { 8 | message my_message{} 9 | google.protobuf.Empty empty = 1; 10 | } 11 | 12 | message m { 13 | message v { 14 | message p99 { 15 | message hello_world {} 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /protoc-gen-twirp_ruby/version.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Twitch Interactive, Inc. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). You may not 4 | // use this file except in compliance with the License. A copy of the License is 5 | // located at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // or in the "license" file accompanying this file. This file is distributed on 10 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | // express or implied. See the License for the specific language governing 12 | // permissions and limitations under the License. 13 | 14 | package main 15 | 16 | const Version = "1.14.1" 17 | -------------------------------------------------------------------------------- /test/client_json_test.rb: -------------------------------------------------------------------------------- 1 | require 'minitest/autorun' 2 | require 'rack/mock' 3 | require 'google/protobuf' 4 | require 'json' 5 | 6 | require_relative '../lib/twirp/client_json' 7 | require_relative './fake_services' 8 | 9 | class ClientJSONTest < Minitest::Test 10 | 11 | def test_client_json_requires_service 12 | assert_raises ArgumentError do 13 | Twirp::ClientJSON.new("http://localhost:8080") # missing service 14 | end 15 | Twirp::ClientJSON.new("http://localhost:8080", service: "FooBar") # ok 16 | end 17 | 18 | def test_client_json_success 19 | c = Twirp::ClientJSON.new(conn_stub("/my.pkg.Talking/Blah") {|req| 20 | assert_equal "application/json", req.request_headers['Content-Type'] 21 | assert_equal '{"blah1":1,"blah2":2}', req.body # body is json 22 | 23 | [200, {}, '{"blah_resp": 3}'] 24 | }, package: "my.pkg", service: "Talking") 25 | 26 | resp = c.rpc :Blah, blah1: 1, blah2: 2 27 | assert_nil resp.error 28 | refute_nil resp.data 29 | assert_equal 3, resp.data["blah_resp"] 30 | refute_nil resp.headers 31 | end 32 | 33 | def test_client_json_thennable 34 | c = Twirp::ClientJSON.new(conn_stub_thennable("/my.pkg.Talking/Blah") {|req| 35 | assert_equal "application/json", req.request_headers['Content-Type'] 36 | assert_equal '{"blah1":1,"blah2":2}', req.body # body is json 37 | 38 | [200, {}, '{"blah_resp": 3}'] 39 | }, package: "my.pkg", service: "Talking") 40 | 41 | resp_thennable = c.rpc :Blah, blah1: 1, blah2: 2 42 | # the final `.then {}` call will yield a ClientResp 43 | assert resp_thennable.is_a?(Thennable) 44 | resp = resp_thennable.value 45 | assert resp.is_a?(Twirp::ClientResp) 46 | 47 | # the final Thennable will have come from one with a faraday response 48 | assert resp_thennable.parent.is_a?(Thennable) 49 | assert resp_thennable.parent.value.is_a?(Faraday::Response) 50 | 51 | # the final ClientResp should look the same as when then isn't used 52 | assert_nil resp.error 53 | refute_nil resp.data 54 | assert_equal 3, resp.data["blah_resp"] 55 | end 56 | 57 | def test_client_json_strict_encoding 58 | c = Twirp::ClientJSON.new(conn_stub("/my.pkg.Talking/Blah") {|req| 59 | assert_equal "application/json; strict=true", req.request_headers['Content-Type'] 60 | assert_equal '{"blah1":1,"blah2":2}', req.body # body is json 61 | 62 | [200, {}, '{"blah_resp": 3}'] 63 | }, package: "my.pkg", service: "Talking", strict: true) 64 | 65 | resp = c.rpc :Blah, blah1: 1, blah2: 2 66 | assert_nil resp.error 67 | refute_nil resp.data 68 | assert_equal 3, resp.data["blah_resp"] 69 | end 70 | 71 | def test_client_json_error 72 | c = Twirp::ClientJSON.new(conn_stub("/Foo/Foomo") {|req| 73 | [400, {}, '{"code": "invalid_argument", "msg": "dont like empty"}'] 74 | }, service: "Foo") 75 | 76 | resp = c.rpc :Foomo, foo: "" 77 | assert_nil resp.data 78 | refute_nil resp.error 79 | assert_equal :invalid_argument, resp.error.code 80 | assert_equal "dont like empty", resp.error.msg 81 | refute_nil resp.headers 82 | end 83 | 84 | def test_client_bad_json_route 85 | c = Twirp::ClientJSON.new(conn_stub("/Foo/OtherMethod") {|req| 86 | [404, {}, 'not here buddy'] 87 | }, service: "Foo") 88 | 89 | resp = c.rpc :OtherMethod, foo: "" 90 | assert_nil resp.data 91 | refute_nil resp.error 92 | assert_equal :bad_route, resp.error.code 93 | refute_nil resp.headers 94 | end 95 | 96 | 97 | def conn_stub(path) 98 | Faraday.new do |conn| 99 | conn.adapter :test do |stub| 100 | stub.post(path) do |env| 101 | yield(env) 102 | end 103 | end 104 | end 105 | end 106 | 107 | # mock of a promise-like thennable, allowing a call to ".then" to get the real value 108 | class Thennable 109 | attr_reader :value, :parent 110 | 111 | def initialize(value, parent = nil) 112 | @value = value 113 | @parent = parent 114 | end 115 | 116 | def then(&block) 117 | # similar to a promise, but runs immediately 118 | Thennable.new(block.call(@value), self) 119 | end 120 | end 121 | 122 | module ThennableFaraday 123 | def post(*) 124 | Thennable.new(super) 125 | end 126 | end 127 | 128 | def conn_stub_thennable(path, &block) 129 | s = conn_stub(path, &block) 130 | s.extend(ThennableFaraday) 131 | s 132 | end 133 | 134 | end 135 | -------------------------------------------------------------------------------- /test/error_test.rb: -------------------------------------------------------------------------------- 1 | require 'minitest/autorun' 2 | 3 | require_relative '../lib/twirp/error' 4 | 5 | class TestErrorCodes < Minitest::Test 6 | 7 | def test_error_codes 8 | assert_equal 18, Twirp::ERROR_CODES.size 9 | 10 | # all codes should be symbols 11 | Twirp::ERROR_CODES.each do |code| 12 | assert_instance_of Symbol, code 13 | end 14 | 15 | # check some codes 16 | assert_includes Twirp::ERROR_CODES, :internal 17 | assert_includes Twirp::ERROR_CODES, :not_found 18 | assert_includes Twirp::ERROR_CODES, :invalid_argument 19 | end 20 | 21 | def test_codes_to_http_status 22 | assert_equal 18, Twirp::ERROR_CODES_TO_HTTP_STATUS.size 23 | 24 | assert_equal 404, Twirp::ERROR_CODES_TO_HTTP_STATUS[:not_found] 25 | assert_equal 500, Twirp::ERROR_CODES_TO_HTTP_STATUS[:internal] 26 | 27 | # nil for invalid_codes 28 | assert_nil Twirp::ERROR_CODES_TO_HTTP_STATUS[:invalid_fdsafda] 29 | assert_nil Twirp::ERROR_CODES_TO_HTTP_STATUS[500] 30 | assert_nil Twirp::ERROR_CODES_TO_HTTP_STATUS[nil] 31 | assert_nil Twirp::ERROR_CODES_TO_HTTP_STATUS["not_found"] # string checks not supported, please use symbols 32 | end 33 | end 34 | 35 | class TestTwirpError < Minitest::Test 36 | 37 | def test_constructors # Try out some constructors 38 | err = Twirp::Error.internal "woops" 39 | assert_equal :internal, err.code 40 | assert_equal "woops", err.msg 41 | assert_equal({}, err.meta) # empty 42 | 43 | err = Twirp::Error.not_found "not here", who: "Waldo" 44 | assert_equal :not_found, err.code 45 | assert_equal "not here", err.msg 46 | assert_equal({who: "Waldo"}, err.meta) 47 | 48 | err = Twirp::Error.invalid_argument("required", "argument" => "size") 49 | assert_equal :invalid_argument, err.code 50 | assert_equal "required", err.msg 51 | assert_equal({"argument" => "size"}, err.meta) # empty 52 | end 53 | 54 | def test_invalid_constructor # Make sure that only supported codes are implemented (prevent bad metaprogramming) 55 | assert_raises NoMethodError do 56 | Twirp::invalid_code_error "should fail" 57 | end 58 | end 59 | 60 | def test_new_with_valid_code_and_a_message 61 | err = Twirp::Error.new(:internal, "woops") 62 | assert_equal :internal, err.code 63 | assert_equal "woops", err.msg 64 | assert_equal({}, err.meta) # empty 65 | end 66 | 67 | def test_new_with_valid_metadata 68 | err = Twirp::Error.new(:internal, "woops", "meta" => "data", "for this" => "error") 69 | assert_equal "data", err.meta["meta"] 70 | assert_equal "error", err.meta["for this"] 71 | assert_nil err.meta["something else"] 72 | 73 | err = Twirp::Error.new(:internal, "woops", meta: "data") 74 | assert_equal err.meta[:meta], "data" 75 | assert_nil err.meta["meta"] # no symbol/string multiaccess for now 76 | end 77 | 78 | def test_invalid_metadata 79 | Twirp::Error.new(:internal, "woops") # ensure the base case doesn't error 80 | 81 | assert_raises ArgumentError do 82 | Twirp::Error.new(:internal, "woops", "string key" => :non_string_value) 83 | end 84 | 85 | assert_raises ArgumentError do 86 | Twirp::Error.new(:internal, "woops", "valid key" => "valid val", "bad_one" => 666) 87 | end 88 | end 89 | 90 | def test_to_h 91 | # returns a hash with attributes 92 | err = Twirp::Error.new(:internal, "err msg", "key" => "val") 93 | assert_equal({code: :internal, msg: "err msg", meta: {"key" => "val"}}, err.to_h) 94 | 95 | # skips meta if not included 96 | err = Twirp::Error.new(:internal, "err msg") 97 | assert_equal({code: :internal, msg: "err msg"}, err.to_h) 98 | end 99 | end 100 | 101 | -------------------------------------------------------------------------------- /test/fake_services.rb: -------------------------------------------------------------------------------- 1 | # Fake messages, services and hadndlers for tests. 2 | 3 | require 'google/protobuf' 4 | require_relative '../lib/twirp' 5 | 6 | # Protobuf messages. 7 | # An example of the result of the protoc ruby code generator. 8 | descriptor_data = "\n\ntest.proto\x12\x07\x65xample\"\x16\n\x04Size\x12\x0e\n\x06inches\x18\x01 \x01(\x05\"$\n\x03Hat\x12\x0e\n\x06inches\x18\x01 \x01(\x05\x12\r\n\x05\x63olor\x18\x02 \x01(\t\"\x07\n\x05\x45mptyb\x06proto3" 9 | Google::Protobuf::DescriptorPool.generated_pool.add_serialized_file(descriptor_data) 10 | 11 | module Example 12 | Size = Google::Protobuf::DescriptorPool.generated_pool.lookup("example.Size").msgclass 13 | Hat = Google::Protobuf::DescriptorPool.generated_pool.lookup("example.Hat").msgclass 14 | Empty = Google::Protobuf::DescriptorPool.generated_pool.lookup("example.Empty").msgclass 15 | end 16 | 17 | # Twirp Service. 18 | # An example of the result of the protoc twirp_ruby plugin code generator. 19 | module Example 20 | class Haberdasher < Twirp::Service 21 | package "example" 22 | service "Haberdasher" 23 | rpc :MakeHat, Size, Hat, :ruby_method => :make_hat 24 | end 25 | 26 | class HaberdasherClient < Twirp::Client 27 | client_for Haberdasher 28 | end 29 | end 30 | 31 | # Example service handler. 32 | # It would be provided by the developer as implementation for the service. 33 | class HaberdasherHandler 34 | def initialize(&block) 35 | @block = block if block_given? 36 | end 37 | 38 | def make_hat(input, env) 39 | @block && @block.call(input, env) 40 | end 41 | end 42 | 43 | # Twirp Service with no package and no rpc methods. 44 | class EmptyService < Twirp::Service 45 | end 46 | class EmptyClient < Twirp::Client 47 | end 48 | 49 | # Foo message 50 | descriptor_data = "\n\tfoo.proto\"\x12\n\x03\x46oo\x12\x0b\n\x03\x66oo\x18\x01 \x01(\tb\x06proto3" 51 | Google::Protobuf::DescriptorPool.generated_pool.add_serialized_file(descriptor_data) 52 | 53 | Foo = Google::Protobuf::DescriptorPool.generated_pool.lookup("Foo").msgclass 54 | 55 | # Foo Client 56 | class FooClient < Twirp::Client 57 | service "Foo" 58 | rpc :Foo, Foo, Foo, :ruby_method => :foo 59 | end 60 | -------------------------------------------------------------------------------- /test/license_header_test.rb: -------------------------------------------------------------------------------- 1 | require 'minitest/autorun' 2 | 3 | # Check that all .rb files in /lib have the license header. 4 | class LicenseHeaderTest < Minitest::Test 5 | 6 | LICENSE_HEADER_LINES = [ 7 | "# Copyright 2018 Twitch Interactive, Inc. All Rights Reserved.", 8 | "#", 9 | "# Licensed under the Apache License, Version 2.0 (the \"License\"). You may not", 10 | "# use this file except in compliance with the License. A copy of the License is", 11 | "# located at", 12 | "#", 13 | "# http://www.apache.org/licenses/LICENSE-2.0", 14 | "#", 15 | "# or in the \"license\" file accompanying this file. This file is distributed on", 16 | "# an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either", 17 | "# express or implied. See the License for the specific language governing", 18 | "# permissions and limitations under the License.", 19 | ] 20 | 21 | def test_files_have_license_header 22 | test_dir = File.dirname(__FILE__) 23 | 24 | files = Dir.glob("#{test_dir}/../lib/**/*.rb") 25 | assert_operator files.size, :>, 1, "at least one file was loaded, otherwise the glob expression may be failing" 26 | 27 | files.each do |filepath| 28 | lines = File.read(filepath).split("\n") 29 | assert_operator lines.size, :>, LICENSE_HEADER_LINES.size, "has license header" 30 | LICENSE_HEADER_LINES.each_with_index do |license_line, i| 31 | file_line = lines[i] 32 | assert_equal license_line, file_line 33 | end 34 | end 35 | end 36 | 37 | end 38 | -------------------------------------------------------------------------------- /twirp.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | 5 | require 'twirp/version' 6 | 7 | Gem::Specification.new do |spec| 8 | spec.name = "twirp" 9 | spec.version = Twirp::VERSION 10 | spec.authors = ["Cyrus A. Forbes", "Mario Izquierdo"] 11 | spec.email = ["forbescyrus@gmail.com", "tothemario@gmail.com"] 12 | spec.summary = %q{Twirp services in Ruby.} 13 | spec.description = %q{Twirp is a simple RPC framework with protobuf service definitions. The Twirp gem provides native support for Ruby.} 14 | spec.homepage = "https://github.com/arthurnn/twirp-ruby" 15 | spec.license = "MIT" 16 | 17 | spec.files = Dir['lib/**/*'] + %w(Gemfile LICENSE README.md twirp.gemspec) 18 | spec.test_files = Dir['test/**/*'] 19 | spec.require_paths = ["lib"] 20 | 21 | spec.required_ruby_version = '>= 1.9' 22 | spec.add_runtime_dependency 'google-protobuf', '>= 3.25', '< 5.a' 23 | spec.add_runtime_dependency 'faraday', '< 3' # for clients 24 | spec.add_dependency 'rack', '>= 2.2.3' 25 | 26 | spec.add_development_dependency 'bundler', '~> 2' 27 | spec.add_development_dependency 'minitest', '>= 5' 28 | spec.add_development_dependency 'rake' 29 | 30 | end 31 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2012-2016 Dave Collins 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/spew/bypasssafe.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2016 Dave Collins 2 | // 3 | // Permission to use, copy, modify, and distribute this software for any 4 | // purpose with or without fee is hereby granted, provided that the above 5 | // copyright notice and this permission notice appear in all copies. 6 | // 7 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | // NOTE: Due to the following build constraints, this file will only be compiled 16 | // when the code is running on Google App Engine, compiled by GopherJS, or 17 | // "-tags safe" is added to the go build command line. The "disableunsafe" 18 | // tag is deprecated and thus should not be used. 19 | // +build js appengine safe disableunsafe !go1.4 20 | 21 | package spew 22 | 23 | import "reflect" 24 | 25 | const ( 26 | // UnsafeDisabled is a build-time constant which specifies whether or 27 | // not access to the unsafe package is available. 28 | UnsafeDisabled = true 29 | ) 30 | 31 | // unsafeReflectValue typically converts the passed reflect.Value into a one 32 | // that bypasses the typical safety restrictions preventing access to 33 | // unaddressable and unexported data. However, doing this relies on access to 34 | // the unsafe package. This is a stub version which simply returns the passed 35 | // reflect.Value when the unsafe package is not available. 36 | func unsafeReflectValue(v reflect.Value) reflect.Value { 37 | return v 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go_import_path: github.com/pkg/errors 3 | go: 4 | - 1.11.x 5 | - 1.12.x 6 | - 1.13.x 7 | - tip 8 | 9 | script: 10 | - make check 11 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Dave Cheney 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/Makefile: -------------------------------------------------------------------------------- 1 | PKGS := github.com/pkg/errors 2 | SRCDIRS := $(shell go list -f '{{.Dir}}' $(PKGS)) 3 | GO := go 4 | 5 | check: test vet gofmt misspell unconvert staticcheck ineffassign unparam 6 | 7 | test: 8 | $(GO) test $(PKGS) 9 | 10 | vet: | test 11 | $(GO) vet $(PKGS) 12 | 13 | staticcheck: 14 | $(GO) get honnef.co/go/tools/cmd/staticcheck 15 | staticcheck -checks all $(PKGS) 16 | 17 | misspell: 18 | $(GO) get github.com/client9/misspell/cmd/misspell 19 | misspell \ 20 | -locale GB \ 21 | -error \ 22 | *.md *.go 23 | 24 | unconvert: 25 | $(GO) get github.com/mdempsky/unconvert 26 | unconvert -v $(PKGS) 27 | 28 | ineffassign: 29 | $(GO) get github.com/gordonklaus/ineffassign 30 | find $(SRCDIRS) -name '*.go' | xargs ineffassign 31 | 32 | pedantic: check errcheck 33 | 34 | unparam: 35 | $(GO) get mvdan.cc/unparam 36 | unparam ./... 37 | 38 | errcheck: 39 | $(GO) get github.com/kisielk/errcheck 40 | errcheck $(PKGS) 41 | 42 | gofmt: 43 | @echo Checking code is gofmted 44 | @test -z "$(shell gofmt -s -l -d -e $(SRCDIRS) | tee /dev/stderr)" 45 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/README.md: -------------------------------------------------------------------------------- 1 | # errors [![Travis-CI](https://travis-ci.org/pkg/errors.svg)](https://travis-ci.org/pkg/errors) [![AppVeyor](https://ci.appveyor.com/api/projects/status/b98mptawhudj53ep/branch/master?svg=true)](https://ci.appveyor.com/project/davecheney/errors/branch/master) [![GoDoc](https://godoc.org/github.com/pkg/errors?status.svg)](http://godoc.org/github.com/pkg/errors) [![Report card](https://goreportcard.com/badge/github.com/pkg/errors)](https://goreportcard.com/report/github.com/pkg/errors) [![Sourcegraph](https://sourcegraph.com/github.com/pkg/errors/-/badge.svg)](https://sourcegraph.com/github.com/pkg/errors?badge) 2 | 3 | Package errors provides simple error handling primitives. 4 | 5 | `go get github.com/pkg/errors` 6 | 7 | The traditional error handling idiom in Go is roughly akin to 8 | ```go 9 | if err != nil { 10 | return err 11 | } 12 | ``` 13 | which applied recursively up the call stack results in error reports without context or debugging information. The errors package allows programmers to add context to the failure path in their code in a way that does not destroy the original value of the error. 14 | 15 | ## Adding context to an error 16 | 17 | The errors.Wrap function returns a new error that adds context to the original error. For example 18 | ```go 19 | _, err := ioutil.ReadAll(r) 20 | if err != nil { 21 | return errors.Wrap(err, "read failed") 22 | } 23 | ``` 24 | ## Retrieving the cause of an error 25 | 26 | Using `errors.Wrap` constructs a stack of errors, adding context to the preceding error. Depending on the nature of the error it may be necessary to reverse the operation of errors.Wrap to retrieve the original error for inspection. Any error value which implements this interface can be inspected by `errors.Cause`. 27 | ```go 28 | type causer interface { 29 | Cause() error 30 | } 31 | ``` 32 | `errors.Cause` will recursively retrieve the topmost error which does not implement `causer`, which is assumed to be the original cause. For example: 33 | ```go 34 | switch err := errors.Cause(err).(type) { 35 | case *MyError: 36 | // handle specifically 37 | default: 38 | // unknown error 39 | } 40 | ``` 41 | 42 | [Read the package documentation for more information](https://godoc.org/github.com/pkg/errors). 43 | 44 | ## Roadmap 45 | 46 | With the upcoming [Go2 error proposals](https://go.googlesource.com/proposal/+/master/design/go2draft.md) this package is moving into maintenance mode. The roadmap for a 1.0 release is as follows: 47 | 48 | - 0.9. Remove pre Go 1.9 and Go 1.10 support, address outstanding pull requests (if possible) 49 | - 1.0. Final release. 50 | 51 | ## Contributing 52 | 53 | Because of the Go2 errors changes, this package is not accepting proposals for new functionality. With that said, we welcome pull requests, bug fixes and issue reports. 54 | 55 | Before sending a PR, please discuss your change by raising an issue. 56 | 57 | ## License 58 | 59 | BSD-2-Clause 60 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: build-{build}.{branch} 2 | 3 | clone_folder: C:\gopath\src\github.com\pkg\errors 4 | shallow_clone: true # for startup speed 5 | 6 | environment: 7 | GOPATH: C:\gopath 8 | 9 | platform: 10 | - x64 11 | 12 | # http://www.appveyor.com/docs/installed-software 13 | install: 14 | # some helpful output for debugging builds 15 | - go version 16 | - go env 17 | # pre-installed MinGW at C:\MinGW is 32bit only 18 | # but MSYS2 at C:\msys64 has mingw64 19 | - set PATH=C:\msys64\mingw64\bin;%PATH% 20 | - gcc --version 21 | - g++ --version 22 | 23 | build_script: 24 | - go install -v ./... 25 | 26 | test_script: 27 | - set PATH=C:\gopath\bin;%PATH% 28 | - go test -v ./... 29 | 30 | #artifacts: 31 | # - path: '%GOPATH%\bin\*.exe' 32 | deploy: off 33 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/go113.go: -------------------------------------------------------------------------------- 1 | // +build go1.13 2 | 3 | package errors 4 | 5 | import ( 6 | stderrors "errors" 7 | ) 8 | 9 | // Is reports whether any error in err's chain matches target. 10 | // 11 | // The chain consists of err itself followed by the sequence of errors obtained by 12 | // repeatedly calling Unwrap. 13 | // 14 | // An error is considered to match a target if it is equal to that target or if 15 | // it implements a method Is(error) bool such that Is(target) returns true. 16 | func Is(err, target error) bool { return stderrors.Is(err, target) } 17 | 18 | // As finds the first error in err's chain that matches target, and if so, sets 19 | // target to that error value and returns true. 20 | // 21 | // The chain consists of err itself followed by the sequence of errors obtained by 22 | // repeatedly calling Unwrap. 23 | // 24 | // An error matches target if the error's concrete value is assignable to the value 25 | // pointed to by target, or if the error has a method As(interface{}) bool such that 26 | // As(target) returns true. In the latter case, the As method is responsible for 27 | // setting target. 28 | // 29 | // As will panic if target is not a non-nil pointer to either a type that implements 30 | // error, or to any interface type. As returns false if err is nil. 31 | func As(err error, target interface{}) bool { return stderrors.As(err, target) } 32 | 33 | // Unwrap returns the result of calling the Unwrap method on err, if err's 34 | // type contains an Unwrap method returning error. 35 | // Otherwise, Unwrap returns nil. 36 | func Unwrap(err error) error { 37 | return stderrors.Unwrap(err) 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/pmezard/go-difflib/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Patrick Mezard 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | The names of its contributors may not be used to endorse or promote 14 | products derived from this software without specific prior written 15 | permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 18 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 20 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 23 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2012-2018 Mat Ryer and Tyler Bunnell 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/assertion_format.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentFormat}} 2 | func {{.DocInfo.Name}}f(t TestingT, {{.ParamsFormat}}) bool { 3 | if h, ok := t.(tHelper); ok { h.Helper() } 4 | return {{.DocInfo.Name}}(t, {{.ForwardedParamsFormat}}) 5 | } 6 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/assertion_forward.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentWithoutT "a"}} 2 | func (a *Assertions) {{.DocInfo.Name}}({{.Params}}) bool { 3 | if h, ok := a.t.(tHelper); ok { h.Helper() } 4 | return {{.DocInfo.Name}}(a.t, {{.ForwardedParams}}) 5 | } 6 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/doc.go: -------------------------------------------------------------------------------- 1 | // Package assert provides a set of comprehensive testing tools for use with the normal Go testing system. 2 | // 3 | // Example Usage 4 | // 5 | // The following is a complete example using assert in a standard test function: 6 | // import ( 7 | // "testing" 8 | // "github.com/stretchr/testify/assert" 9 | // ) 10 | // 11 | // func TestSomething(t *testing.T) { 12 | // 13 | // var a string = "Hello" 14 | // var b string = "Hello" 15 | // 16 | // assert.Equal(t, a, b, "The two words should be the same.") 17 | // 18 | // } 19 | // 20 | // if you assert many times, use the format below: 21 | // 22 | // import ( 23 | // "testing" 24 | // "github.com/stretchr/testify/assert" 25 | // ) 26 | // 27 | // func TestSomething(t *testing.T) { 28 | // assert := assert.New(t) 29 | // 30 | // var a string = "Hello" 31 | // var b string = "Hello" 32 | // 33 | // assert.Equal(a, b, "The two words should be the same.") 34 | // } 35 | // 36 | // Assertions 37 | // 38 | // Assertions allow you to easily write test code, and are global funcs in the `assert` package. 39 | // All assertion functions take, as the first argument, the `*testing.T` object provided by the 40 | // testing framework. This allows the assertion funcs to write the failings and other details to 41 | // the correct place. 42 | // 43 | // Every assertion function also takes an optional string message as the final argument, 44 | // allowing custom error messages to be appended to the message the assertion method outputs. 45 | package assert 46 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/errors.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | import ( 4 | "errors" 5 | ) 6 | 7 | // AnError is an error instance useful for testing. If the code does not care 8 | // about error specifics, and only needs to return the error for example, this 9 | // error should be used to make the test code more readable. 10 | var AnError = errors.New("assert.AnError general error for testing") 11 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/forward_assertions.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | // Assertions provides assertion methods around the 4 | // TestingT interface. 5 | type Assertions struct { 6 | t TestingT 7 | } 8 | 9 | // New makes a new Assertions object for the specified TestingT. 10 | func New(t TestingT) *Assertions { 11 | return &Assertions{ 12 | t: t, 13 | } 14 | } 15 | 16 | //go:generate go run ../_codegen/main.go -output-package=assert -template=assertion_forward.go.tmpl -include-format-funcs 17 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/doc.go: -------------------------------------------------------------------------------- 1 | // Package require implements the same assertions as the `assert` package but 2 | // stops test execution when a test fails. 3 | // 4 | // Example Usage 5 | // 6 | // The following is a complete example using require in a standard test function: 7 | // import ( 8 | // "testing" 9 | // "github.com/stretchr/testify/require" 10 | // ) 11 | // 12 | // func TestSomething(t *testing.T) { 13 | // 14 | // var a string = "Hello" 15 | // var b string = "Hello" 16 | // 17 | // require.Equal(t, a, b, "The two words should be the same.") 18 | // 19 | // } 20 | // 21 | // Assertions 22 | // 23 | // The `require` package have same global functions as in the `assert` package, 24 | // but instead of returning a boolean result they call `t.FailNow()`. 25 | // 26 | // Every assertion function also takes an optional string message as the final argument, 27 | // allowing custom error messages to be appended to the message the assertion method outputs. 28 | package require 29 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/forward_requirements.go: -------------------------------------------------------------------------------- 1 | package require 2 | 3 | // Assertions provides assertion methods around the 4 | // TestingT interface. 5 | type Assertions struct { 6 | t TestingT 7 | } 8 | 9 | // New makes a new Assertions object for the specified TestingT. 10 | func New(t TestingT) *Assertions { 11 | return &Assertions{ 12 | t: t, 13 | } 14 | } 15 | 16 | //go:generate go run ../_codegen/main.go -output-package=require -template=require_forward.go.tmpl -include-format-funcs 17 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/require.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.Comment}} 2 | func {{.DocInfo.Name}}(t TestingT, {{.Params}}) { 3 | if assert.{{.DocInfo.Name}}(t, {{.ForwardedParams}}) { return } 4 | if h, ok := t.(tHelper); ok { h.Helper() } 5 | t.FailNow() 6 | } 7 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/require_forward.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentWithoutT "a"}} 2 | func (a *Assertions) {{.DocInfo.Name}}({{.Params}}) { 3 | if h, ok := a.t.(tHelper); ok { h.Helper() } 4 | {{.DocInfo.Name}}(a.t, {{.ForwardedParams}}) 5 | } 6 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/requirements.go: -------------------------------------------------------------------------------- 1 | package require 2 | 3 | // TestingT is an interface wrapper around *testing.T 4 | type TestingT interface { 5 | Errorf(format string, args ...interface{}) 6 | FailNow() 7 | } 8 | 9 | type tHelper interface { 10 | Helper() 11 | } 12 | 13 | // ComparisonAssertionFunc is a common function prototype when comparing two values. Can be useful 14 | // for table driven tests. 15 | type ComparisonAssertionFunc func(TestingT, interface{}, interface{}, ...interface{}) 16 | 17 | // ValueAssertionFunc is a common function prototype when validating a single value. Can be useful 18 | // for table driven tests. 19 | type ValueAssertionFunc func(TestingT, interface{}, ...interface{}) 20 | 21 | // BoolAssertionFunc is a common function prototype when validating a bool value. Can be useful 22 | // for table driven tests. 23 | type BoolAssertionFunc func(TestingT, bool, ...interface{}) 24 | 25 | // ErrorAssertionFunc is a common function prototype when validating an error value. Can be useful 26 | // for table driven tests. 27 | type ErrorAssertionFunc func(TestingT, error, ...interface{}) 28 | 29 | //go:generate go run ../_codegen/main.go -output-package=require -template=require.go.tmpl -include-format-funcs 30 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/encoding/prototext/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package prototext marshals and unmarshals protocol buffer messages as the 6 | // textproto format. 7 | package prototext 8 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/descopts/options.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package descopts contains the nil pointers to concrete descriptor options. 6 | // 7 | // This package exists as a form of reverse dependency injection so that certain 8 | // packages (e.g., internal/filedesc and internal/filetype can avoid a direct 9 | // dependency on the descriptor proto package). 10 | package descopts 11 | 12 | import "google.golang.org/protobuf/reflect/protoreflect" 13 | 14 | // These variables are set by the init function in descriptor.pb.go via logic 15 | // in internal/filetype. In other words, so long as the descriptor proto package 16 | // is linked in, these variables will be populated. 17 | // 18 | // Each variable is populated with a nil pointer to the options struct. 19 | var ( 20 | File protoreflect.ProtoMessage 21 | Enum protoreflect.ProtoMessage 22 | EnumValue protoreflect.ProtoMessage 23 | Message protoreflect.ProtoMessage 24 | Field protoreflect.ProtoMessage 25 | Oneof protoreflect.ProtoMessage 26 | ExtensionRange protoreflect.ProtoMessage 27 | Service protoreflect.ProtoMessage 28 | Method protoreflect.ProtoMessage 29 | ) 30 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/detrand/rand.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package detrand provides deterministically random functionality. 6 | // 7 | // The pseudo-randomness of these functions is seeded by the program binary 8 | // itself and guarantees that the output does not change within a program, 9 | // while ensuring that the output is unstable across different builds. 10 | package detrand 11 | 12 | import ( 13 | "encoding/binary" 14 | "hash/fnv" 15 | "os" 16 | ) 17 | 18 | // Disable disables detrand such that all functions returns the zero value. 19 | // This function is not concurrent-safe and must be called during program init. 20 | func Disable() { 21 | randSeed = 0 22 | } 23 | 24 | // Bool returns a deterministically random boolean. 25 | func Bool() bool { 26 | return randSeed%2 == 1 27 | } 28 | 29 | // Intn returns a deterministically random integer between 0 and n-1, inclusive. 30 | func Intn(n int) int { 31 | if n <= 0 { 32 | panic("must be positive") 33 | } 34 | return int(randSeed % uint64(n)) 35 | } 36 | 37 | // randSeed is a best-effort at an approximate hash of the Go binary. 38 | var randSeed = binaryHash() 39 | 40 | func binaryHash() uint64 { 41 | // Open the Go binary. 42 | s, err := os.Executable() 43 | if err != nil { 44 | return 0 45 | } 46 | f, err := os.Open(s) 47 | if err != nil { 48 | return 0 49 | } 50 | defer f.Close() 51 | 52 | // Hash the size and several samples of the Go binary. 53 | const numSamples = 8 54 | var buf [64]byte 55 | h := fnv.New64() 56 | fi, err := f.Stat() 57 | if err != nil { 58 | return 0 59 | } 60 | binary.LittleEndian.PutUint64(buf[:8], uint64(fi.Size())) 61 | h.Write(buf[:8]) 62 | for i := int64(0); i < numSamples; i++ { 63 | if _, err := f.ReadAt(buf[:], i*fi.Size()/numSamples); err != nil { 64 | return 0 65 | } 66 | h.Write(buf[:]) 67 | } 68 | return h.Sum64() 69 | } 70 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/editiondefaults/defaults.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package editiondefaults contains the binary representation of the editions 6 | // defaults. 7 | package editiondefaults 8 | 9 | import _ "embed" 10 | 11 | //go:embed editions_defaults.binpb 12 | var Defaults []byte 13 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/editiondefaults/editions_defaults.binpb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurnn/twirp-ruby/56552fb3101c0357ad6dc4b1ba441c678eb241b3/vendor/google.golang.org/protobuf/internal/editiondefaults/editions_defaults.binpb -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/encoding/text/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package text implements the text format for protocol buffers. 6 | // This package has no semantic understanding for protocol buffers and is only 7 | // a parser and composer for the format. 8 | // 9 | // There is no formal specification for the protobuf text format, as such the 10 | // C++ implementation (see google::protobuf::TextFormat) is the reference 11 | // implementation of the text format. 12 | // 13 | // This package is neither a superset nor a subset of the C++ implementation. 14 | // This implementation permits a more liberal grammar in some cases to be 15 | // backwards compatible with the historical Go implementation. 16 | // Future parsings unique to Go should not be added. 17 | // Some grammars allowed by the C++ implementation are deliberately 18 | // not implemented here because they are considered a bug by the protobuf team 19 | // and should not be replicated. 20 | // 21 | // The Go implementation should implement a sufficient amount of the C++ 22 | // grammar such that the default text serialization by C++ can be parsed by Go. 23 | // However, just because the C++ parser accepts some input does not mean that 24 | // the Go implementation should as well. 25 | // 26 | // The text format is almost a superset of JSON except: 27 | // - message keys are not quoted strings, but identifiers 28 | // - the top-level value must be a message without the delimiters 29 | package text 30 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/errors/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package errors implements functions to manipulate errors. 6 | package errors 7 | 8 | import ( 9 | "errors" 10 | "fmt" 11 | 12 | "google.golang.org/protobuf/internal/detrand" 13 | ) 14 | 15 | // Error is a sentinel matching all errors produced by this package. 16 | var Error = errors.New("protobuf error") 17 | 18 | // New formats a string according to the format specifier and arguments and 19 | // returns an error that has a "proto" prefix. 20 | func New(f string, x ...any) error { 21 | return &prefixError{s: format(f, x...)} 22 | } 23 | 24 | type prefixError struct{ s string } 25 | 26 | var prefix = func() string { 27 | // Deliberately introduce instability into the error message string to 28 | // discourage users from performing error string comparisons. 29 | if detrand.Bool() { 30 | return "proto: " // use non-breaking spaces (U+00a0) 31 | } else { 32 | return "proto: " // use regular spaces (U+0020) 33 | } 34 | }() 35 | 36 | func (e *prefixError) Error() string { 37 | return prefix + e.s 38 | } 39 | 40 | func (e *prefixError) Unwrap() error { 41 | return Error 42 | } 43 | 44 | // Wrap returns an error that has a "proto" prefix, the formatted string described 45 | // by the format specifier and arguments, and a suffix of err. The error wraps err. 46 | func Wrap(err error, f string, x ...any) error { 47 | return &wrapError{ 48 | s: format(f, x...), 49 | err: err, 50 | } 51 | } 52 | 53 | type wrapError struct { 54 | s string 55 | err error 56 | } 57 | 58 | func (e *wrapError) Error() string { 59 | return format("%v%v: %v", prefix, e.s, e.err) 60 | } 61 | 62 | func (e *wrapError) Unwrap() error { 63 | return e.err 64 | } 65 | 66 | func (e *wrapError) Is(target error) bool { 67 | return target == Error 68 | } 69 | 70 | func format(f string, x ...any) string { 71 | // avoid "proto: " prefix when chaining 72 | for i := 0; i < len(x); i++ { 73 | switch e := x[i].(type) { 74 | case *prefixError: 75 | x[i] = e.s 76 | case *wrapError: 77 | x[i] = format("%v: %v", e.s, e.err) 78 | } 79 | } 80 | return fmt.Sprintf(f, x...) 81 | } 82 | 83 | func InvalidUTF8(name string) error { 84 | return New("field %v contains invalid UTF-8", name) 85 | } 86 | 87 | func RequiredNotSet(name string) error { 88 | return New("required field %v not set", name) 89 | } 90 | 91 | type SizeMismatchError struct { 92 | Calculated, Measured int 93 | } 94 | 95 | func (e *SizeMismatchError) Error() string { 96 | return fmt.Sprintf("size mismatch (see https://github.com/golang/protobuf/issues/1609): calculated=%d, measured=%d", e.Calculated, e.Measured) 97 | } 98 | 99 | func MismatchedSizeCalculation(calculated, measured int) error { 100 | return &SizeMismatchError{ 101 | Calculated: calculated, 102 | Measured: measured, 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/flags/flags.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package flags provides a set of flags controlled by build tags. 6 | package flags 7 | 8 | // ProtoLegacy specifies whether to enable support for legacy functionality 9 | // such as MessageSets, and various other obscure behavior 10 | // that is necessary to maintain backwards compatibility with proto1 or 11 | // the pre-release variants of proto2 and proto3. 12 | // 13 | // This is disabled by default unless built with the "protolegacy" tag. 14 | // 15 | // WARNING: The compatibility agreement covers nothing provided by this flag. 16 | // As such, functionality may suddenly be removed or changed at our discretion. 17 | const ProtoLegacy = protoLegacy 18 | 19 | // LazyUnmarshalExtensions specifies whether to lazily unmarshal extensions. 20 | // 21 | // Lazy extension unmarshaling validates the contents of message-valued 22 | // extension fields at unmarshal time, but defers creating the message 23 | // structure until the extension is first accessed. 24 | const LazyUnmarshalExtensions = ProtoLegacy 25 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/flags/proto_legacy_disable.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !protolegacy 6 | // +build !protolegacy 7 | 8 | package flags 9 | 10 | const protoLegacy = false 11 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/flags/proto_legacy_enable.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build protolegacy 6 | // +build protolegacy 7 | 8 | package flags 9 | 10 | const protoLegacy = true 11 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/genid/any_gen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Code generated by generate-protos. DO NOT EDIT. 6 | 7 | package genid 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | ) 12 | 13 | const File_google_protobuf_any_proto = "google/protobuf/any.proto" 14 | 15 | // Names for google.protobuf.Any. 16 | const ( 17 | Any_message_name protoreflect.Name = "Any" 18 | Any_message_fullname protoreflect.FullName = "google.protobuf.Any" 19 | ) 20 | 21 | // Field names for google.protobuf.Any. 22 | const ( 23 | Any_TypeUrl_field_name protoreflect.Name = "type_url" 24 | Any_Value_field_name protoreflect.Name = "value" 25 | 26 | Any_TypeUrl_field_fullname protoreflect.FullName = "google.protobuf.Any.type_url" 27 | Any_Value_field_fullname protoreflect.FullName = "google.protobuf.Any.value" 28 | ) 29 | 30 | // Field numbers for google.protobuf.Any. 31 | const ( 32 | Any_TypeUrl_field_number protoreflect.FieldNumber = 1 33 | Any_Value_field_number protoreflect.FieldNumber = 2 34 | ) 35 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/genid/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package genid contains constants for declarations in descriptor.proto 6 | // and the well-known types. 7 | package genid 8 | 9 | import "google.golang.org/protobuf/reflect/protoreflect" 10 | 11 | const GoogleProtobuf_package protoreflect.FullName = "google.protobuf" 12 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/genid/duration_gen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Code generated by generate-protos. DO NOT EDIT. 6 | 7 | package genid 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | ) 12 | 13 | const File_google_protobuf_duration_proto = "google/protobuf/duration.proto" 14 | 15 | // Names for google.protobuf.Duration. 16 | const ( 17 | Duration_message_name protoreflect.Name = "Duration" 18 | Duration_message_fullname protoreflect.FullName = "google.protobuf.Duration" 19 | ) 20 | 21 | // Field names for google.protobuf.Duration. 22 | const ( 23 | Duration_Seconds_field_name protoreflect.Name = "seconds" 24 | Duration_Nanos_field_name protoreflect.Name = "nanos" 25 | 26 | Duration_Seconds_field_fullname protoreflect.FullName = "google.protobuf.Duration.seconds" 27 | Duration_Nanos_field_fullname protoreflect.FullName = "google.protobuf.Duration.nanos" 28 | ) 29 | 30 | // Field numbers for google.protobuf.Duration. 31 | const ( 32 | Duration_Seconds_field_number protoreflect.FieldNumber = 1 33 | Duration_Nanos_field_number protoreflect.FieldNumber = 2 34 | ) 35 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/genid/empty_gen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Code generated by generate-protos. DO NOT EDIT. 6 | 7 | package genid 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | ) 12 | 13 | const File_google_protobuf_empty_proto = "google/protobuf/empty.proto" 14 | 15 | // Names for google.protobuf.Empty. 16 | const ( 17 | Empty_message_name protoreflect.Name = "Empty" 18 | Empty_message_fullname protoreflect.FullName = "google.protobuf.Empty" 19 | ) 20 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/genid/field_mask_gen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Code generated by generate-protos. DO NOT EDIT. 6 | 7 | package genid 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | ) 12 | 13 | const File_google_protobuf_field_mask_proto = "google/protobuf/field_mask.proto" 14 | 15 | // Names for google.protobuf.FieldMask. 16 | const ( 17 | FieldMask_message_name protoreflect.Name = "FieldMask" 18 | FieldMask_message_fullname protoreflect.FullName = "google.protobuf.FieldMask" 19 | ) 20 | 21 | // Field names for google.protobuf.FieldMask. 22 | const ( 23 | FieldMask_Paths_field_name protoreflect.Name = "paths" 24 | 25 | FieldMask_Paths_field_fullname protoreflect.FullName = "google.protobuf.FieldMask.paths" 26 | ) 27 | 28 | // Field numbers for google.protobuf.FieldMask. 29 | const ( 30 | FieldMask_Paths_field_number protoreflect.FieldNumber = 1 31 | ) 32 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/genid/go_features_gen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Code generated by generate-protos. DO NOT EDIT. 6 | 7 | package genid 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | ) 12 | 13 | const File_google_protobuf_go_features_proto = "google/protobuf/go_features.proto" 14 | 15 | // Names for pb.GoFeatures. 16 | const ( 17 | GoFeatures_message_name protoreflect.Name = "GoFeatures" 18 | GoFeatures_message_fullname protoreflect.FullName = "pb.GoFeatures" 19 | ) 20 | 21 | // Field names for pb.GoFeatures. 22 | const ( 23 | GoFeatures_LegacyUnmarshalJsonEnum_field_name protoreflect.Name = "legacy_unmarshal_json_enum" 24 | GoFeatures_ApiLevel_field_name protoreflect.Name = "api_level" 25 | GoFeatures_StripEnumPrefix_field_name protoreflect.Name = "strip_enum_prefix" 26 | 27 | GoFeatures_LegacyUnmarshalJsonEnum_field_fullname protoreflect.FullName = "pb.GoFeatures.legacy_unmarshal_json_enum" 28 | GoFeatures_ApiLevel_field_fullname protoreflect.FullName = "pb.GoFeatures.api_level" 29 | GoFeatures_StripEnumPrefix_field_fullname protoreflect.FullName = "pb.GoFeatures.strip_enum_prefix" 30 | ) 31 | 32 | // Field numbers for pb.GoFeatures. 33 | const ( 34 | GoFeatures_LegacyUnmarshalJsonEnum_field_number protoreflect.FieldNumber = 1 35 | GoFeatures_ApiLevel_field_number protoreflect.FieldNumber = 2 36 | GoFeatures_StripEnumPrefix_field_number protoreflect.FieldNumber = 3 37 | ) 38 | 39 | // Full and short names for pb.GoFeatures.APILevel. 40 | const ( 41 | GoFeatures_APILevel_enum_fullname = "pb.GoFeatures.APILevel" 42 | GoFeatures_APILevel_enum_name = "APILevel" 43 | ) 44 | 45 | // Enum values for pb.GoFeatures.APILevel. 46 | const ( 47 | GoFeatures_API_LEVEL_UNSPECIFIED_enum_value = 0 48 | GoFeatures_API_OPEN_enum_value = 1 49 | GoFeatures_API_HYBRID_enum_value = 2 50 | GoFeatures_API_OPAQUE_enum_value = 3 51 | ) 52 | 53 | // Full and short names for pb.GoFeatures.StripEnumPrefix. 54 | const ( 55 | GoFeatures_StripEnumPrefix_enum_fullname = "pb.GoFeatures.StripEnumPrefix" 56 | GoFeatures_StripEnumPrefix_enum_name = "StripEnumPrefix" 57 | ) 58 | 59 | // Enum values for pb.GoFeatures.StripEnumPrefix. 60 | const ( 61 | GoFeatures_STRIP_ENUM_PREFIX_UNSPECIFIED_enum_value = 0 62 | GoFeatures_STRIP_ENUM_PREFIX_KEEP_enum_value = 1 63 | GoFeatures_STRIP_ENUM_PREFIX_GENERATE_BOTH_enum_value = 2 64 | GoFeatures_STRIP_ENUM_PREFIX_STRIP_enum_value = 3 65 | ) 66 | 67 | // Extension numbers 68 | const ( 69 | FeatureSet_Go_ext_number protoreflect.FieldNumber = 1002 70 | ) 71 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/genid/goname.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package genid 6 | 7 | // Go names of implementation-specific struct fields in generated messages. 8 | const ( 9 | State_goname = "state" 10 | 11 | SizeCache_goname = "sizeCache" 12 | SizeCacheA_goname = "XXX_sizecache" 13 | 14 | UnknownFields_goname = "unknownFields" 15 | UnknownFieldsA_goname = "XXX_unrecognized" 16 | 17 | ExtensionFields_goname = "extensionFields" 18 | ExtensionFieldsA_goname = "XXX_InternalExtensions" 19 | ExtensionFieldsB_goname = "XXX_extensions" 20 | ) 21 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/genid/map_entry.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package genid 6 | 7 | import "google.golang.org/protobuf/reflect/protoreflect" 8 | 9 | // Generic field names and numbers for synthetic map entry messages. 10 | const ( 11 | MapEntry_Key_field_name protoreflect.Name = "key" 12 | MapEntry_Value_field_name protoreflect.Name = "value" 13 | 14 | MapEntry_Key_field_number protoreflect.FieldNumber = 1 15 | MapEntry_Value_field_number protoreflect.FieldNumber = 2 16 | ) 17 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/genid/name.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package genid 6 | 7 | const ( 8 | NoUnkeyedLiteral_goname = "noUnkeyedLiteral" 9 | NoUnkeyedLiteralA_goname = "XXX_NoUnkeyedLiteral" 10 | 11 | BuilderSuffix_goname = "_builder" 12 | ) 13 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/genid/source_context_gen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Code generated by generate-protos. DO NOT EDIT. 6 | 7 | package genid 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | ) 12 | 13 | const File_google_protobuf_source_context_proto = "google/protobuf/source_context.proto" 14 | 15 | // Names for google.protobuf.SourceContext. 16 | const ( 17 | SourceContext_message_name protoreflect.Name = "SourceContext" 18 | SourceContext_message_fullname protoreflect.FullName = "google.protobuf.SourceContext" 19 | ) 20 | 21 | // Field names for google.protobuf.SourceContext. 22 | const ( 23 | SourceContext_FileName_field_name protoreflect.Name = "file_name" 24 | 25 | SourceContext_FileName_field_fullname protoreflect.FullName = "google.protobuf.SourceContext.file_name" 26 | ) 27 | 28 | // Field numbers for google.protobuf.SourceContext. 29 | const ( 30 | SourceContext_FileName_field_number protoreflect.FieldNumber = 1 31 | ) 32 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/genid/struct_gen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Code generated by generate-protos. DO NOT EDIT. 6 | 7 | package genid 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | ) 12 | 13 | const File_google_protobuf_struct_proto = "google/protobuf/struct.proto" 14 | 15 | // Full and short names for google.protobuf.NullValue. 16 | const ( 17 | NullValue_enum_fullname = "google.protobuf.NullValue" 18 | NullValue_enum_name = "NullValue" 19 | ) 20 | 21 | // Enum values for google.protobuf.NullValue. 22 | const ( 23 | NullValue_NULL_VALUE_enum_value = 0 24 | ) 25 | 26 | // Names for google.protobuf.Struct. 27 | const ( 28 | Struct_message_name protoreflect.Name = "Struct" 29 | Struct_message_fullname protoreflect.FullName = "google.protobuf.Struct" 30 | ) 31 | 32 | // Field names for google.protobuf.Struct. 33 | const ( 34 | Struct_Fields_field_name protoreflect.Name = "fields" 35 | 36 | Struct_Fields_field_fullname protoreflect.FullName = "google.protobuf.Struct.fields" 37 | ) 38 | 39 | // Field numbers for google.protobuf.Struct. 40 | const ( 41 | Struct_Fields_field_number protoreflect.FieldNumber = 1 42 | ) 43 | 44 | // Names for google.protobuf.Struct.FieldsEntry. 45 | const ( 46 | Struct_FieldsEntry_message_name protoreflect.Name = "FieldsEntry" 47 | Struct_FieldsEntry_message_fullname protoreflect.FullName = "google.protobuf.Struct.FieldsEntry" 48 | ) 49 | 50 | // Field names for google.protobuf.Struct.FieldsEntry. 51 | const ( 52 | Struct_FieldsEntry_Key_field_name protoreflect.Name = "key" 53 | Struct_FieldsEntry_Value_field_name protoreflect.Name = "value" 54 | 55 | Struct_FieldsEntry_Key_field_fullname protoreflect.FullName = "google.protobuf.Struct.FieldsEntry.key" 56 | Struct_FieldsEntry_Value_field_fullname protoreflect.FullName = "google.protobuf.Struct.FieldsEntry.value" 57 | ) 58 | 59 | // Field numbers for google.protobuf.Struct.FieldsEntry. 60 | const ( 61 | Struct_FieldsEntry_Key_field_number protoreflect.FieldNumber = 1 62 | Struct_FieldsEntry_Value_field_number protoreflect.FieldNumber = 2 63 | ) 64 | 65 | // Names for google.protobuf.Value. 66 | const ( 67 | Value_message_name protoreflect.Name = "Value" 68 | Value_message_fullname protoreflect.FullName = "google.protobuf.Value" 69 | ) 70 | 71 | // Field names for google.protobuf.Value. 72 | const ( 73 | Value_NullValue_field_name protoreflect.Name = "null_value" 74 | Value_NumberValue_field_name protoreflect.Name = "number_value" 75 | Value_StringValue_field_name protoreflect.Name = "string_value" 76 | Value_BoolValue_field_name protoreflect.Name = "bool_value" 77 | Value_StructValue_field_name protoreflect.Name = "struct_value" 78 | Value_ListValue_field_name protoreflect.Name = "list_value" 79 | 80 | Value_NullValue_field_fullname protoreflect.FullName = "google.protobuf.Value.null_value" 81 | Value_NumberValue_field_fullname protoreflect.FullName = "google.protobuf.Value.number_value" 82 | Value_StringValue_field_fullname protoreflect.FullName = "google.protobuf.Value.string_value" 83 | Value_BoolValue_field_fullname protoreflect.FullName = "google.protobuf.Value.bool_value" 84 | Value_StructValue_field_fullname protoreflect.FullName = "google.protobuf.Value.struct_value" 85 | Value_ListValue_field_fullname protoreflect.FullName = "google.protobuf.Value.list_value" 86 | ) 87 | 88 | // Field numbers for google.protobuf.Value. 89 | const ( 90 | Value_NullValue_field_number protoreflect.FieldNumber = 1 91 | Value_NumberValue_field_number protoreflect.FieldNumber = 2 92 | Value_StringValue_field_number protoreflect.FieldNumber = 3 93 | Value_BoolValue_field_number protoreflect.FieldNumber = 4 94 | Value_StructValue_field_number protoreflect.FieldNumber = 5 95 | Value_ListValue_field_number protoreflect.FieldNumber = 6 96 | ) 97 | 98 | // Oneof names for google.protobuf.Value. 99 | const ( 100 | Value_Kind_oneof_name protoreflect.Name = "kind" 101 | 102 | Value_Kind_oneof_fullname protoreflect.FullName = "google.protobuf.Value.kind" 103 | ) 104 | 105 | // Names for google.protobuf.ListValue. 106 | const ( 107 | ListValue_message_name protoreflect.Name = "ListValue" 108 | ListValue_message_fullname protoreflect.FullName = "google.protobuf.ListValue" 109 | ) 110 | 111 | // Field names for google.protobuf.ListValue. 112 | const ( 113 | ListValue_Values_field_name protoreflect.Name = "values" 114 | 115 | ListValue_Values_field_fullname protoreflect.FullName = "google.protobuf.ListValue.values" 116 | ) 117 | 118 | // Field numbers for google.protobuf.ListValue. 119 | const ( 120 | ListValue_Values_field_number protoreflect.FieldNumber = 1 121 | ) 122 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/genid/timestamp_gen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Code generated by generate-protos. DO NOT EDIT. 6 | 7 | package genid 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | ) 12 | 13 | const File_google_protobuf_timestamp_proto = "google/protobuf/timestamp.proto" 14 | 15 | // Names for google.protobuf.Timestamp. 16 | const ( 17 | Timestamp_message_name protoreflect.Name = "Timestamp" 18 | Timestamp_message_fullname protoreflect.FullName = "google.protobuf.Timestamp" 19 | ) 20 | 21 | // Field names for google.protobuf.Timestamp. 22 | const ( 23 | Timestamp_Seconds_field_name protoreflect.Name = "seconds" 24 | Timestamp_Nanos_field_name protoreflect.Name = "nanos" 25 | 26 | Timestamp_Seconds_field_fullname protoreflect.FullName = "google.protobuf.Timestamp.seconds" 27 | Timestamp_Nanos_field_fullname protoreflect.FullName = "google.protobuf.Timestamp.nanos" 28 | ) 29 | 30 | // Field numbers for google.protobuf.Timestamp. 31 | const ( 32 | Timestamp_Seconds_field_number protoreflect.FieldNumber = 1 33 | Timestamp_Nanos_field_number protoreflect.FieldNumber = 2 34 | ) 35 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/genid/wrappers.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package genid 6 | 7 | import "google.golang.org/protobuf/reflect/protoreflect" 8 | 9 | // Generic field name and number for messages in wrappers.proto. 10 | const ( 11 | WrapperValue_Value_field_name protoreflect.Name = "value" 12 | WrapperValue_Value_field_number protoreflect.FieldNumber = 1 13 | ) 14 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/impl/bitmap.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !race 6 | 7 | package impl 8 | 9 | // There is no additional data as we're not running under race detector. 10 | type RaceDetectHookData struct{} 11 | 12 | // Empty stubs for when not using the race detector. Calls to these from index.go should be optimized away. 13 | func (presence) raceDetectHookPresent(num uint32) {} 14 | func (presence) raceDetectHookSetPresent(num uint32, size presenceSize) {} 15 | func (presence) raceDetectHookClearPresent(num uint32) {} 16 | func (presence) raceDetectHookAllocAndCopy(src presence) {} 17 | 18 | // raceDetectHookPresent is called by the generated file interface 19 | // (*proto.internalFuncs) Present to optionally read an unprotected 20 | // shadow bitmap when race detection is enabled. In regular code it is 21 | // a noop. 22 | func raceDetectHookPresent(field *uint32, num uint32) {} 23 | 24 | // raceDetectHookSetPresent is called by the generated file interface 25 | // (*proto.internalFuncs) SetPresent to optionally write an unprotected 26 | // shadow bitmap when race detection is enabled. In regular code it is 27 | // a noop. 28 | func raceDetectHookSetPresent(field *uint32, num uint32, size presenceSize) {} 29 | 30 | // raceDetectHookClearPresent is called by the generated file interface 31 | // (*proto.internalFuncs) ClearPresent to optionally write an unprotected 32 | // shadow bitmap when race detection is enabled. In regular code it is 33 | // a noop. 34 | func raceDetectHookClearPresent(field *uint32, num uint32) {} 35 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/impl/bitmap_race.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build race 6 | 7 | package impl 8 | 9 | // When running under race detector, we add a presence map of bytes, that we can access 10 | // in the hook functions so that we trigger the race detection whenever we have concurrent 11 | // Read-Writes or Write-Writes. The race detector does not otherwise detect invalid concurrent 12 | // access to lazy fields as all updates of bitmaps and pointers are done using atomic operations. 13 | type RaceDetectHookData struct { 14 | shadowPresence *[]byte 15 | } 16 | 17 | // Hooks for presence bitmap operations that allocate, read and write the shadowPresence 18 | // using non-atomic operations. 19 | func (data *RaceDetectHookData) raceDetectHookAlloc(size presenceSize) { 20 | sp := make([]byte, size) 21 | atomicStoreShadowPresence(&data.shadowPresence, &sp) 22 | } 23 | 24 | func (p presence) raceDetectHookPresent(num uint32) { 25 | data := p.toRaceDetectData() 26 | if data == nil { 27 | return 28 | } 29 | sp := atomicLoadShadowPresence(&data.shadowPresence) 30 | if sp != nil { 31 | _ = (*sp)[num] 32 | } 33 | } 34 | 35 | func (p presence) raceDetectHookSetPresent(num uint32, size presenceSize) { 36 | data := p.toRaceDetectData() 37 | if data == nil { 38 | return 39 | } 40 | sp := atomicLoadShadowPresence(&data.shadowPresence) 41 | if sp == nil { 42 | data.raceDetectHookAlloc(size) 43 | sp = atomicLoadShadowPresence(&data.shadowPresence) 44 | } 45 | (*sp)[num] = 1 46 | } 47 | 48 | func (p presence) raceDetectHookClearPresent(num uint32) { 49 | data := p.toRaceDetectData() 50 | if data == nil { 51 | return 52 | } 53 | sp := atomicLoadShadowPresence(&data.shadowPresence) 54 | if sp != nil { 55 | (*sp)[num] = 0 56 | 57 | } 58 | } 59 | 60 | // raceDetectHookAllocAndCopy allocates a new shadowPresence slice at lazy and copies 61 | // shadowPresence bytes from src to lazy. 62 | func (p presence) raceDetectHookAllocAndCopy(q presence) { 63 | sData := q.toRaceDetectData() 64 | dData := p.toRaceDetectData() 65 | if sData == nil { 66 | return 67 | } 68 | srcSp := atomicLoadShadowPresence(&sData.shadowPresence) 69 | if srcSp == nil { 70 | atomicStoreShadowPresence(&dData.shadowPresence, nil) 71 | return 72 | } 73 | n := len(*srcSp) 74 | dSlice := make([]byte, n) 75 | atomicStoreShadowPresence(&dData.shadowPresence, &dSlice) 76 | for i := 0; i < n; i++ { 77 | dSlice[i] = (*srcSp)[i] 78 | } 79 | } 80 | 81 | // raceDetectHookPresent is called by the generated file interface 82 | // (*proto.internalFuncs) Present to optionally read an unprotected 83 | // shadow bitmap when race detection is enabled. In regular code it is 84 | // a noop. 85 | func raceDetectHookPresent(field *uint32, num uint32) { 86 | data := findPointerToRaceDetectData(field, num) 87 | if data == nil { 88 | return 89 | } 90 | sp := atomicLoadShadowPresence(&data.shadowPresence) 91 | if sp != nil { 92 | _ = (*sp)[num] 93 | } 94 | } 95 | 96 | // raceDetectHookSetPresent is called by the generated file interface 97 | // (*proto.internalFuncs) SetPresent to optionally write an unprotected 98 | // shadow bitmap when race detection is enabled. In regular code it is 99 | // a noop. 100 | func raceDetectHookSetPresent(field *uint32, num uint32, size presenceSize) { 101 | data := findPointerToRaceDetectData(field, num) 102 | if data == nil { 103 | return 104 | } 105 | sp := atomicLoadShadowPresence(&data.shadowPresence) 106 | if sp == nil { 107 | data.raceDetectHookAlloc(size) 108 | sp = atomicLoadShadowPresence(&data.shadowPresence) 109 | } 110 | (*sp)[num] = 1 111 | } 112 | 113 | // raceDetectHookClearPresent is called by the generated file interface 114 | // (*proto.internalFuncs) ClearPresent to optionally write an unprotected 115 | // shadow bitmap when race detection is enabled. In regular code it is 116 | // a noop. 117 | func raceDetectHookClearPresent(field *uint32, num uint32) { 118 | data := findPointerToRaceDetectData(field, num) 119 | if data == nil { 120 | return 121 | } 122 | sp := atomicLoadShadowPresence(&data.shadowPresence) 123 | if sp != nil { 124 | (*sp)[num] = 0 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/impl/codec_messageset.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package impl 6 | 7 | import ( 8 | "sort" 9 | 10 | "google.golang.org/protobuf/encoding/protowire" 11 | "google.golang.org/protobuf/internal/encoding/messageset" 12 | "google.golang.org/protobuf/internal/errors" 13 | "google.golang.org/protobuf/internal/flags" 14 | ) 15 | 16 | func sizeMessageSet(mi *MessageInfo, p pointer, opts marshalOptions) (size int) { 17 | if !flags.ProtoLegacy { 18 | return 0 19 | } 20 | 21 | ext := *p.Apply(mi.extensionOffset).Extensions() 22 | for _, x := range ext { 23 | xi := getExtensionFieldInfo(x.Type()) 24 | if xi.funcs.size == nil { 25 | continue 26 | } 27 | num, _ := protowire.DecodeTag(xi.wiretag) 28 | size += messageset.SizeField(num) 29 | if fullyLazyExtensions(opts) { 30 | // Don't expand the extension, instead use the buffer to calculate size 31 | if lb := x.lazyBuffer(); lb != nil { 32 | // We got hold of the buffer, so it's still lazy. 33 | // Don't count the tag size in the extension buffer, it's already added. 34 | size += protowire.SizeTag(messageset.FieldMessage) + len(lb) - xi.tagsize 35 | continue 36 | } 37 | } 38 | size += xi.funcs.size(x.Value(), protowire.SizeTag(messageset.FieldMessage), opts) 39 | } 40 | 41 | if u := mi.getUnknownBytes(p); u != nil { 42 | size += messageset.SizeUnknown(*u) 43 | } 44 | 45 | return size 46 | } 47 | 48 | func marshalMessageSet(mi *MessageInfo, b []byte, p pointer, opts marshalOptions) ([]byte, error) { 49 | if !flags.ProtoLegacy { 50 | return b, errors.New("no support for message_set_wire_format") 51 | } 52 | 53 | ext := *p.Apply(mi.extensionOffset).Extensions() 54 | switch len(ext) { 55 | case 0: 56 | case 1: 57 | // Fast-path for one extension: Don't bother sorting the keys. 58 | for _, x := range ext { 59 | var err error 60 | b, err = marshalMessageSetField(mi, b, x, opts) 61 | if err != nil { 62 | return b, err 63 | } 64 | } 65 | default: 66 | // Sort the keys to provide a deterministic encoding. 67 | // Not sure this is required, but the old code does it. 68 | keys := make([]int, 0, len(ext)) 69 | for k := range ext { 70 | keys = append(keys, int(k)) 71 | } 72 | sort.Ints(keys) 73 | for _, k := range keys { 74 | var err error 75 | b, err = marshalMessageSetField(mi, b, ext[int32(k)], opts) 76 | if err != nil { 77 | return b, err 78 | } 79 | } 80 | } 81 | 82 | if u := mi.getUnknownBytes(p); u != nil { 83 | var err error 84 | b, err = messageset.AppendUnknown(b, *u) 85 | if err != nil { 86 | return b, err 87 | } 88 | } 89 | 90 | return b, nil 91 | } 92 | 93 | func marshalMessageSetField(mi *MessageInfo, b []byte, x ExtensionField, opts marshalOptions) ([]byte, error) { 94 | xi := getExtensionFieldInfo(x.Type()) 95 | num, _ := protowire.DecodeTag(xi.wiretag) 96 | b = messageset.AppendFieldStart(b, num) 97 | 98 | if fullyLazyExtensions(opts) { 99 | // Don't expand the extension if it's still in wire format, instead use the buffer content. 100 | if lb := x.lazyBuffer(); lb != nil { 101 | // The tag inside the lazy buffer is a different tag (the extension 102 | // number), but what we need here is the tag for FieldMessage: 103 | b = protowire.AppendVarint(b, protowire.EncodeTag(messageset.FieldMessage, protowire.BytesType)) 104 | b = append(b, lb[xi.tagsize:]...) 105 | b = messageset.AppendFieldEnd(b) 106 | return b, nil 107 | } 108 | } 109 | 110 | b, err := xi.funcs.marshal(b, x.Value(), protowire.EncodeTag(messageset.FieldMessage, protowire.BytesType), opts) 111 | if err != nil { 112 | return b, err 113 | } 114 | b = messageset.AppendFieldEnd(b) 115 | return b, nil 116 | } 117 | 118 | func unmarshalMessageSet(mi *MessageInfo, b []byte, p pointer, opts unmarshalOptions) (out unmarshalOutput, err error) { 119 | if !flags.ProtoLegacy { 120 | return out, errors.New("no support for message_set_wire_format") 121 | } 122 | 123 | ep := p.Apply(mi.extensionOffset).Extensions() 124 | if *ep == nil { 125 | *ep = make(map[int32]ExtensionField) 126 | } 127 | ext := *ep 128 | initialized := true 129 | err = messageset.Unmarshal(b, true, func(num protowire.Number, v []byte) error { 130 | o, err := mi.unmarshalExtension(v, num, protowire.BytesType, ext, opts) 131 | if err == errUnknown { 132 | u := mi.mutableUnknownBytes(p) 133 | *u = protowire.AppendTag(*u, num, protowire.BytesType) 134 | *u = append(*u, v...) 135 | return nil 136 | } 137 | if !o.initialized { 138 | initialized = false 139 | } 140 | return err 141 | }) 142 | out.n = len(b) 143 | out.initialized = initialized 144 | return out, err 145 | } 146 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/impl/codec_unsafe.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package impl 6 | 7 | // When using unsafe pointers, we can just treat enum values as int32s. 8 | 9 | var ( 10 | coderEnumNoZero = coderInt32NoZero 11 | coderEnum = coderInt32 12 | coderEnumPtr = coderInt32Ptr 13 | coderEnumSlice = coderInt32Slice 14 | coderEnumPackedSlice = coderInt32PackedSlice 15 | ) 16 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/impl/convert_list.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package impl 6 | 7 | import ( 8 | "fmt" 9 | "reflect" 10 | 11 | "google.golang.org/protobuf/reflect/protoreflect" 12 | ) 13 | 14 | func newListConverter(t reflect.Type, fd protoreflect.FieldDescriptor) Converter { 15 | switch { 16 | case t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Slice: 17 | return &listPtrConverter{t, newSingularConverter(t.Elem().Elem(), fd)} 18 | case t.Kind() == reflect.Slice: 19 | return &listConverter{t, newSingularConverter(t.Elem(), fd)} 20 | } 21 | panic(fmt.Sprintf("invalid Go type %v for field %v", t, fd.FullName())) 22 | } 23 | 24 | type listConverter struct { 25 | goType reflect.Type // []T 26 | c Converter 27 | } 28 | 29 | func (c *listConverter) PBValueOf(v reflect.Value) protoreflect.Value { 30 | if v.Type() != c.goType { 31 | panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType)) 32 | } 33 | pv := reflect.New(c.goType) 34 | pv.Elem().Set(v) 35 | return protoreflect.ValueOfList(&listReflect{pv, c.c}) 36 | } 37 | 38 | func (c *listConverter) GoValueOf(v protoreflect.Value) reflect.Value { 39 | rv := v.List().(*listReflect).v 40 | if rv.IsNil() { 41 | return reflect.Zero(c.goType) 42 | } 43 | return rv.Elem() 44 | } 45 | 46 | func (c *listConverter) IsValidPB(v protoreflect.Value) bool { 47 | list, ok := v.Interface().(*listReflect) 48 | if !ok { 49 | return false 50 | } 51 | return list.v.Type().Elem() == c.goType 52 | } 53 | 54 | func (c *listConverter) IsValidGo(v reflect.Value) bool { 55 | return v.IsValid() && v.Type() == c.goType 56 | } 57 | 58 | func (c *listConverter) New() protoreflect.Value { 59 | return protoreflect.ValueOfList(&listReflect{reflect.New(c.goType), c.c}) 60 | } 61 | 62 | func (c *listConverter) Zero() protoreflect.Value { 63 | return protoreflect.ValueOfList(&listReflect{reflect.Zero(reflect.PtrTo(c.goType)), c.c}) 64 | } 65 | 66 | type listPtrConverter struct { 67 | goType reflect.Type // *[]T 68 | c Converter 69 | } 70 | 71 | func (c *listPtrConverter) PBValueOf(v reflect.Value) protoreflect.Value { 72 | if v.Type() != c.goType { 73 | panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType)) 74 | } 75 | return protoreflect.ValueOfList(&listReflect{v, c.c}) 76 | } 77 | 78 | func (c *listPtrConverter) GoValueOf(v protoreflect.Value) reflect.Value { 79 | return v.List().(*listReflect).v 80 | } 81 | 82 | func (c *listPtrConverter) IsValidPB(v protoreflect.Value) bool { 83 | list, ok := v.Interface().(*listReflect) 84 | if !ok { 85 | return false 86 | } 87 | return list.v.Type() == c.goType 88 | } 89 | 90 | func (c *listPtrConverter) IsValidGo(v reflect.Value) bool { 91 | return v.IsValid() && v.Type() == c.goType 92 | } 93 | 94 | func (c *listPtrConverter) New() protoreflect.Value { 95 | return c.PBValueOf(reflect.New(c.goType.Elem())) 96 | } 97 | 98 | func (c *listPtrConverter) Zero() protoreflect.Value { 99 | return c.PBValueOf(reflect.Zero(c.goType)) 100 | } 101 | 102 | type listReflect struct { 103 | v reflect.Value // *[]T 104 | conv Converter 105 | } 106 | 107 | func (ls *listReflect) Len() int { 108 | if ls.v.IsNil() { 109 | return 0 110 | } 111 | return ls.v.Elem().Len() 112 | } 113 | func (ls *listReflect) Get(i int) protoreflect.Value { 114 | return ls.conv.PBValueOf(ls.v.Elem().Index(i)) 115 | } 116 | func (ls *listReflect) Set(i int, v protoreflect.Value) { 117 | ls.v.Elem().Index(i).Set(ls.conv.GoValueOf(v)) 118 | } 119 | func (ls *listReflect) Append(v protoreflect.Value) { 120 | ls.v.Elem().Set(reflect.Append(ls.v.Elem(), ls.conv.GoValueOf(v))) 121 | } 122 | func (ls *listReflect) AppendMutable() protoreflect.Value { 123 | if _, ok := ls.conv.(*messageConverter); !ok { 124 | panic("invalid AppendMutable on list with non-message type") 125 | } 126 | v := ls.NewElement() 127 | ls.Append(v) 128 | return v 129 | } 130 | func (ls *listReflect) Truncate(i int) { 131 | ls.v.Elem().Set(ls.v.Elem().Slice(0, i)) 132 | } 133 | func (ls *listReflect) NewElement() protoreflect.Value { 134 | return ls.conv.New() 135 | } 136 | func (ls *listReflect) IsValid() bool { 137 | return !ls.v.IsNil() 138 | } 139 | func (ls *listReflect) protoUnwrap() any { 140 | return ls.v.Interface() 141 | } 142 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/impl/convert_map.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package impl 6 | 7 | import ( 8 | "fmt" 9 | "reflect" 10 | 11 | "google.golang.org/protobuf/reflect/protoreflect" 12 | ) 13 | 14 | type mapConverter struct { 15 | goType reflect.Type // map[K]V 16 | keyConv, valConv Converter 17 | } 18 | 19 | func newMapConverter(t reflect.Type, fd protoreflect.FieldDescriptor) *mapConverter { 20 | if t.Kind() != reflect.Map { 21 | panic(fmt.Sprintf("invalid Go type %v for field %v", t, fd.FullName())) 22 | } 23 | return &mapConverter{ 24 | goType: t, 25 | keyConv: newSingularConverter(t.Key(), fd.MapKey()), 26 | valConv: newSingularConverter(t.Elem(), fd.MapValue()), 27 | } 28 | } 29 | 30 | func (c *mapConverter) PBValueOf(v reflect.Value) protoreflect.Value { 31 | if v.Type() != c.goType { 32 | panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType)) 33 | } 34 | return protoreflect.ValueOfMap(&mapReflect{v, c.keyConv, c.valConv}) 35 | } 36 | 37 | func (c *mapConverter) GoValueOf(v protoreflect.Value) reflect.Value { 38 | return v.Map().(*mapReflect).v 39 | } 40 | 41 | func (c *mapConverter) IsValidPB(v protoreflect.Value) bool { 42 | mapv, ok := v.Interface().(*mapReflect) 43 | if !ok { 44 | return false 45 | } 46 | return mapv.v.Type() == c.goType 47 | } 48 | 49 | func (c *mapConverter) IsValidGo(v reflect.Value) bool { 50 | return v.IsValid() && v.Type() == c.goType 51 | } 52 | 53 | func (c *mapConverter) New() protoreflect.Value { 54 | return c.PBValueOf(reflect.MakeMap(c.goType)) 55 | } 56 | 57 | func (c *mapConverter) Zero() protoreflect.Value { 58 | return c.PBValueOf(reflect.Zero(c.goType)) 59 | } 60 | 61 | type mapReflect struct { 62 | v reflect.Value // map[K]V 63 | keyConv Converter 64 | valConv Converter 65 | } 66 | 67 | func (ms *mapReflect) Len() int { 68 | return ms.v.Len() 69 | } 70 | func (ms *mapReflect) Has(k protoreflect.MapKey) bool { 71 | rk := ms.keyConv.GoValueOf(k.Value()) 72 | rv := ms.v.MapIndex(rk) 73 | return rv.IsValid() 74 | } 75 | func (ms *mapReflect) Get(k protoreflect.MapKey) protoreflect.Value { 76 | rk := ms.keyConv.GoValueOf(k.Value()) 77 | rv := ms.v.MapIndex(rk) 78 | if !rv.IsValid() { 79 | return protoreflect.Value{} 80 | } 81 | return ms.valConv.PBValueOf(rv) 82 | } 83 | func (ms *mapReflect) Set(k protoreflect.MapKey, v protoreflect.Value) { 84 | rk := ms.keyConv.GoValueOf(k.Value()) 85 | rv := ms.valConv.GoValueOf(v) 86 | ms.v.SetMapIndex(rk, rv) 87 | } 88 | func (ms *mapReflect) Clear(k protoreflect.MapKey) { 89 | rk := ms.keyConv.GoValueOf(k.Value()) 90 | ms.v.SetMapIndex(rk, reflect.Value{}) 91 | } 92 | func (ms *mapReflect) Mutable(k protoreflect.MapKey) protoreflect.Value { 93 | if _, ok := ms.valConv.(*messageConverter); !ok { 94 | panic("invalid Mutable on map with non-message value type") 95 | } 96 | v := ms.Get(k) 97 | if !v.IsValid() { 98 | v = ms.NewValue() 99 | ms.Set(k, v) 100 | } 101 | return v 102 | } 103 | func (ms *mapReflect) Range(f func(protoreflect.MapKey, protoreflect.Value) bool) { 104 | iter := ms.v.MapRange() 105 | for iter.Next() { 106 | k := ms.keyConv.PBValueOf(iter.Key()).MapKey() 107 | v := ms.valConv.PBValueOf(iter.Value()) 108 | if !f(k, v) { 109 | return 110 | } 111 | } 112 | } 113 | func (ms *mapReflect) NewValue() protoreflect.Value { 114 | return ms.valConv.New() 115 | } 116 | func (ms *mapReflect) IsValid() bool { 117 | return !ms.v.IsNil() 118 | } 119 | func (ms *mapReflect) protoUnwrap() any { 120 | return ms.v.Interface() 121 | } 122 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/impl/enum.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package impl 6 | 7 | import ( 8 | "reflect" 9 | 10 | "google.golang.org/protobuf/reflect/protoreflect" 11 | ) 12 | 13 | type EnumInfo struct { 14 | GoReflectType reflect.Type // int32 kind 15 | Desc protoreflect.EnumDescriptor 16 | } 17 | 18 | func (t *EnumInfo) New(n protoreflect.EnumNumber) protoreflect.Enum { 19 | return reflect.ValueOf(n).Convert(t.GoReflectType).Interface().(protoreflect.Enum) 20 | } 21 | func (t *EnumInfo) Descriptor() protoreflect.EnumDescriptor { return t.Desc } 22 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/impl/legacy_export.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package impl 6 | 7 | import ( 8 | "encoding/binary" 9 | "encoding/json" 10 | "hash/crc32" 11 | "math" 12 | "reflect" 13 | 14 | "google.golang.org/protobuf/internal/errors" 15 | "google.golang.org/protobuf/reflect/protoreflect" 16 | "google.golang.org/protobuf/runtime/protoiface" 17 | ) 18 | 19 | // These functions exist to support exported APIs in generated protobufs. 20 | // While these are deprecated, they cannot be removed for compatibility reasons. 21 | 22 | // LegacyEnumName returns the name of enums used in legacy code. 23 | func (Export) LegacyEnumName(ed protoreflect.EnumDescriptor) string { 24 | return legacyEnumName(ed) 25 | } 26 | 27 | // LegacyMessageTypeOf returns the protoreflect.MessageType for m, 28 | // with name used as the message name if necessary. 29 | func (Export) LegacyMessageTypeOf(m protoiface.MessageV1, name protoreflect.FullName) protoreflect.MessageType { 30 | if mv := (Export{}).protoMessageV2Of(m); mv != nil { 31 | return mv.ProtoReflect().Type() 32 | } 33 | return legacyLoadMessageType(reflect.TypeOf(m), name) 34 | } 35 | 36 | // UnmarshalJSONEnum unmarshals an enum from a JSON-encoded input. 37 | // The input can either be a string representing the enum value by name, 38 | // or a number representing the enum number itself. 39 | func (Export) UnmarshalJSONEnum(ed protoreflect.EnumDescriptor, b []byte) (protoreflect.EnumNumber, error) { 40 | if b[0] == '"' { 41 | var name protoreflect.Name 42 | if err := json.Unmarshal(b, &name); err != nil { 43 | return 0, errors.New("invalid input for enum %v: %s", ed.FullName(), b) 44 | } 45 | ev := ed.Values().ByName(name) 46 | if ev == nil { 47 | return 0, errors.New("invalid value for enum %v: %s", ed.FullName(), name) 48 | } 49 | return ev.Number(), nil 50 | } else { 51 | var num protoreflect.EnumNumber 52 | if err := json.Unmarshal(b, &num); err != nil { 53 | return 0, errors.New("invalid input for enum %v: %s", ed.FullName(), b) 54 | } 55 | return num, nil 56 | } 57 | } 58 | 59 | // CompressGZIP compresses the input as a GZIP-encoded file. 60 | // The current implementation does no compression. 61 | func (Export) CompressGZIP(in []byte) (out []byte) { 62 | // RFC 1952, section 2.3.1. 63 | var gzipHeader = [10]byte{0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff} 64 | 65 | // RFC 1951, section 3.2.4. 66 | var blockHeader [5]byte 67 | const maxBlockSize = math.MaxUint16 68 | numBlocks := 1 + len(in)/maxBlockSize 69 | 70 | // RFC 1952, section 2.3.1. 71 | var gzipFooter [8]byte 72 | binary.LittleEndian.PutUint32(gzipFooter[0:4], crc32.ChecksumIEEE(in)) 73 | binary.LittleEndian.PutUint32(gzipFooter[4:8], uint32(len(in))) 74 | 75 | // Encode the input without compression using raw DEFLATE blocks. 76 | out = make([]byte, 0, len(gzipHeader)+len(blockHeader)*numBlocks+len(in)+len(gzipFooter)) 77 | out = append(out, gzipHeader[:]...) 78 | for blockHeader[0] == 0 { 79 | blockSize := maxBlockSize 80 | if blockSize > len(in) { 81 | blockHeader[0] = 0x01 // final bit per RFC 1951, section 3.2.3. 82 | blockSize = len(in) 83 | } 84 | binary.LittleEndian.PutUint16(blockHeader[1:3], uint16(blockSize)) 85 | binary.LittleEndian.PutUint16(blockHeader[3:5], ^uint16(blockSize)) 86 | out = append(out, blockHeader[:]...) 87 | out = append(out, in[:blockSize]...) 88 | in = in[blockSize:] 89 | } 90 | out = append(out, gzipFooter[:]...) 91 | return out 92 | } 93 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/impl/legacy_file.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package impl 6 | 7 | import ( 8 | "bytes" 9 | "compress/gzip" 10 | "io" 11 | "sync" 12 | 13 | "google.golang.org/protobuf/internal/filedesc" 14 | "google.golang.org/protobuf/reflect/protoreflect" 15 | "google.golang.org/protobuf/reflect/protoregistry" 16 | ) 17 | 18 | // Every enum and message type generated by protoc-gen-go since commit 2fc053c5 19 | // on February 25th, 2016 has had a method to get the raw descriptor. 20 | // Types that were not generated by protoc-gen-go or were generated prior 21 | // to that version are not supported. 22 | // 23 | // The []byte returned is the encoded form of a FileDescriptorProto message 24 | // compressed using GZIP. The []int is the path from the top-level file 25 | // to the specific message or enum declaration. 26 | type ( 27 | enumV1 interface { 28 | EnumDescriptor() ([]byte, []int) 29 | } 30 | messageV1 interface { 31 | Descriptor() ([]byte, []int) 32 | } 33 | ) 34 | 35 | var legacyFileDescCache sync.Map // map[*byte]protoreflect.FileDescriptor 36 | 37 | // legacyLoadFileDesc unmarshals b as a compressed FileDescriptorProto message. 38 | // 39 | // This assumes that b is immutable and that b does not refer to part of a 40 | // concatenated series of GZIP files (which would require shenanigans that 41 | // rely on the concatenation properties of both protobufs and GZIP). 42 | // File descriptors generated by protoc-gen-go do not rely on that property. 43 | func legacyLoadFileDesc(b []byte) protoreflect.FileDescriptor { 44 | // Fast-path: check whether we already have a cached file descriptor. 45 | if fd, ok := legacyFileDescCache.Load(&b[0]); ok { 46 | return fd.(protoreflect.FileDescriptor) 47 | } 48 | 49 | // Slow-path: decompress and unmarshal the file descriptor proto. 50 | zr, err := gzip.NewReader(bytes.NewReader(b)) 51 | if err != nil { 52 | panic(err) 53 | } 54 | b2, err := io.ReadAll(zr) 55 | if err != nil { 56 | panic(err) 57 | } 58 | 59 | fd := filedesc.Builder{ 60 | RawDescriptor: b2, 61 | FileRegistry: resolverOnly{protoregistry.GlobalFiles}, // do not register back to global registry 62 | }.Build().File 63 | if fd, ok := legacyFileDescCache.LoadOrStore(&b[0], fd); ok { 64 | return fd.(protoreflect.FileDescriptor) 65 | } 66 | return fd 67 | } 68 | 69 | type resolverOnly struct { 70 | reg *protoregistry.Files 71 | } 72 | 73 | func (r resolverOnly) FindFileByPath(path string) (protoreflect.FileDescriptor, error) { 74 | return r.reg.FindFileByPath(path) 75 | } 76 | func (r resolverOnly) FindDescriptorByName(name protoreflect.FullName) (protoreflect.Descriptor, error) { 77 | return r.reg.FindDescriptorByName(name) 78 | } 79 | func (resolverOnly) RegisterFile(protoreflect.FileDescriptor) error { 80 | return nil 81 | } 82 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/impl/message_opaque_gen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Code generated by generate-types. DO NOT EDIT. 6 | 7 | package impl 8 | 9 | import ( 10 | "reflect" 11 | 12 | "google.golang.org/protobuf/reflect/protoreflect" 13 | ) 14 | 15 | func getterForOpaqueNullableScalar(mi *MessageInfo, index uint32, fd protoreflect.FieldDescriptor, fs reflect.StructField, conv Converter, fieldOffset offset) func(p pointer) protoreflect.Value { 16 | ft := fs.Type 17 | if ft.Kind() == reflect.Ptr { 18 | ft = ft.Elem() 19 | } 20 | if fd.Kind() == protoreflect.EnumKind { 21 | // Enums for nullable opaque types. 22 | return func(p pointer) protoreflect.Value { 23 | if p.IsNil() || !mi.present(p, index) { 24 | return conv.Zero() 25 | } 26 | rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem() 27 | return conv.PBValueOf(rv) 28 | } 29 | } 30 | switch ft.Kind() { 31 | case reflect.Bool: 32 | return func(p pointer) protoreflect.Value { 33 | if p.IsNil() || !mi.present(p, index) { 34 | return conv.Zero() 35 | } 36 | x := p.Apply(fieldOffset).Bool() 37 | return protoreflect.ValueOfBool(*x) 38 | } 39 | case reflect.Int32: 40 | return func(p pointer) protoreflect.Value { 41 | if p.IsNil() || !mi.present(p, index) { 42 | return conv.Zero() 43 | } 44 | x := p.Apply(fieldOffset).Int32() 45 | return protoreflect.ValueOfInt32(*x) 46 | } 47 | case reflect.Uint32: 48 | return func(p pointer) protoreflect.Value { 49 | if p.IsNil() || !mi.present(p, index) { 50 | return conv.Zero() 51 | } 52 | x := p.Apply(fieldOffset).Uint32() 53 | return protoreflect.ValueOfUint32(*x) 54 | } 55 | case reflect.Int64: 56 | return func(p pointer) protoreflect.Value { 57 | if p.IsNil() || !mi.present(p, index) { 58 | return conv.Zero() 59 | } 60 | x := p.Apply(fieldOffset).Int64() 61 | return protoreflect.ValueOfInt64(*x) 62 | } 63 | case reflect.Uint64: 64 | return func(p pointer) protoreflect.Value { 65 | if p.IsNil() || !mi.present(p, index) { 66 | return conv.Zero() 67 | } 68 | x := p.Apply(fieldOffset).Uint64() 69 | return protoreflect.ValueOfUint64(*x) 70 | } 71 | case reflect.Float32: 72 | return func(p pointer) protoreflect.Value { 73 | if p.IsNil() || !mi.present(p, index) { 74 | return conv.Zero() 75 | } 76 | x := p.Apply(fieldOffset).Float32() 77 | return protoreflect.ValueOfFloat32(*x) 78 | } 79 | case reflect.Float64: 80 | return func(p pointer) protoreflect.Value { 81 | if p.IsNil() || !mi.present(p, index) { 82 | return conv.Zero() 83 | } 84 | x := p.Apply(fieldOffset).Float64() 85 | return protoreflect.ValueOfFloat64(*x) 86 | } 87 | case reflect.String: 88 | if fd.Kind() == protoreflect.BytesKind { 89 | return func(p pointer) protoreflect.Value { 90 | if p.IsNil() || !mi.present(p, index) { 91 | return conv.Zero() 92 | } 93 | x := p.Apply(fieldOffset).StringPtr() 94 | if *x == nil { 95 | return conv.Zero() 96 | } 97 | if len(**x) == 0 { 98 | return protoreflect.ValueOfBytes(nil) 99 | } 100 | return protoreflect.ValueOfBytes([]byte(**x)) 101 | } 102 | } 103 | return func(p pointer) protoreflect.Value { 104 | if p.IsNil() || !mi.present(p, index) { 105 | return conv.Zero() 106 | } 107 | x := p.Apply(fieldOffset).StringPtr() 108 | if *x == nil { 109 | return conv.Zero() 110 | } 111 | return protoreflect.ValueOfString(**x) 112 | } 113 | case reflect.Slice: 114 | if fd.Kind() == protoreflect.StringKind { 115 | return func(p pointer) protoreflect.Value { 116 | if p.IsNil() || !mi.present(p, index) { 117 | return conv.Zero() 118 | } 119 | x := p.Apply(fieldOffset).Bytes() 120 | return protoreflect.ValueOfString(string(*x)) 121 | } 122 | } 123 | return func(p pointer) protoreflect.Value { 124 | if p.IsNil() || !mi.present(p, index) { 125 | return conv.Zero() 126 | } 127 | x := p.Apply(fieldOffset).Bytes() 128 | return protoreflect.ValueOfBytes(*x) 129 | } 130 | } 131 | panic("unexpected protobuf kind: " + ft.Kind().String()) 132 | } 133 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/impl/pointer_unsafe_opaque.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package impl 6 | 7 | import ( 8 | "sync/atomic" 9 | "unsafe" 10 | ) 11 | 12 | func (p pointer) AtomicGetPointer() pointer { 13 | return pointer{p: atomic.LoadPointer((*unsafe.Pointer)(p.p))} 14 | } 15 | 16 | func (p pointer) AtomicSetPointer(v pointer) { 17 | atomic.StorePointer((*unsafe.Pointer)(p.p), v.p) 18 | } 19 | 20 | func (p pointer) AtomicSetNilPointer() { 21 | atomic.StorePointer((*unsafe.Pointer)(p.p), unsafe.Pointer(nil)) 22 | } 23 | 24 | func (p pointer) AtomicSetPointerIfNil(v pointer) pointer { 25 | if atomic.CompareAndSwapPointer((*unsafe.Pointer)(p.p), unsafe.Pointer(nil), v.p) { 26 | return v 27 | } 28 | return pointer{p: atomic.LoadPointer((*unsafe.Pointer)(p.p))} 29 | } 30 | 31 | type atomicV1MessageInfo struct{ p Pointer } 32 | 33 | func (mi *atomicV1MessageInfo) Get() Pointer { 34 | return Pointer(atomic.LoadPointer((*unsafe.Pointer)(&mi.p))) 35 | } 36 | 37 | func (mi *atomicV1MessageInfo) SetIfNil(p Pointer) Pointer { 38 | if atomic.CompareAndSwapPointer((*unsafe.Pointer)(&mi.p), nil, unsafe.Pointer(p)) { 39 | return p 40 | } 41 | return mi.Get() 42 | } 43 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/order/order.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package order 6 | 7 | import ( 8 | "google.golang.org/protobuf/reflect/protoreflect" 9 | ) 10 | 11 | // FieldOrder specifies the ordering to visit message fields. 12 | // It is a function that reports whether x is ordered before y. 13 | type FieldOrder func(x, y protoreflect.FieldDescriptor) bool 14 | 15 | var ( 16 | // AnyFieldOrder specifies no specific field ordering. 17 | AnyFieldOrder FieldOrder = nil 18 | 19 | // LegacyFieldOrder sorts fields in the same ordering as emitted by 20 | // wire serialization in the github.com/golang/protobuf implementation. 21 | LegacyFieldOrder FieldOrder = func(x, y protoreflect.FieldDescriptor) bool { 22 | ox, oy := x.ContainingOneof(), y.ContainingOneof() 23 | inOneof := func(od protoreflect.OneofDescriptor) bool { 24 | return od != nil && !od.IsSynthetic() 25 | } 26 | 27 | // Extension fields sort before non-extension fields. 28 | if x.IsExtension() != y.IsExtension() { 29 | return x.IsExtension() && !y.IsExtension() 30 | } 31 | // Fields not within a oneof sort before those within a oneof. 32 | if inOneof(ox) != inOneof(oy) { 33 | return !inOneof(ox) && inOneof(oy) 34 | } 35 | // Fields in disjoint oneof sets are sorted by declaration index. 36 | if inOneof(ox) && inOneof(oy) && ox != oy { 37 | return ox.Index() < oy.Index() 38 | } 39 | // Fields sorted by field number. 40 | return x.Number() < y.Number() 41 | } 42 | 43 | // NumberFieldOrder sorts fields by their field number. 44 | NumberFieldOrder FieldOrder = func(x, y protoreflect.FieldDescriptor) bool { 45 | return x.Number() < y.Number() 46 | } 47 | 48 | // IndexNameFieldOrder sorts non-extension fields before extension fields. 49 | // Non-extensions are sorted according to their declaration index. 50 | // Extensions are sorted according to their full name. 51 | IndexNameFieldOrder FieldOrder = func(x, y protoreflect.FieldDescriptor) bool { 52 | // Non-extension fields sort before extension fields. 53 | if x.IsExtension() != y.IsExtension() { 54 | return !x.IsExtension() && y.IsExtension() 55 | } 56 | // Extensions sorted by fullname. 57 | if x.IsExtension() && y.IsExtension() { 58 | return x.FullName() < y.FullName() 59 | } 60 | // Non-extensions sorted by declaration index. 61 | return x.Index() < y.Index() 62 | } 63 | ) 64 | 65 | // KeyOrder specifies the ordering to visit map entries. 66 | // It is a function that reports whether x is ordered before y. 67 | type KeyOrder func(x, y protoreflect.MapKey) bool 68 | 69 | var ( 70 | // AnyKeyOrder specifies no specific key ordering. 71 | AnyKeyOrder KeyOrder = nil 72 | 73 | // GenericKeyOrder sorts false before true, numeric keys in ascending order, 74 | // and strings in lexicographical ordering according to UTF-8 codepoints. 75 | GenericKeyOrder KeyOrder = func(x, y protoreflect.MapKey) bool { 76 | switch x.Interface().(type) { 77 | case bool: 78 | return !x.Bool() && y.Bool() 79 | case int32, int64: 80 | return x.Int() < y.Int() 81 | case uint32, uint64: 82 | return x.Uint() < y.Uint() 83 | case string: 84 | return x.String() < y.String() 85 | default: 86 | panic("invalid map key type") 87 | } 88 | } 89 | ) 90 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/order/range.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package order provides ordered access to messages and maps. 6 | package order 7 | 8 | import ( 9 | "sort" 10 | "sync" 11 | 12 | "google.golang.org/protobuf/reflect/protoreflect" 13 | ) 14 | 15 | type messageField struct { 16 | fd protoreflect.FieldDescriptor 17 | v protoreflect.Value 18 | } 19 | 20 | var messageFieldPool = sync.Pool{ 21 | New: func() any { return new([]messageField) }, 22 | } 23 | 24 | type ( 25 | // FieldRnger is an interface for visiting all fields in a message. 26 | // The protoreflect.Message type implements this interface. 27 | FieldRanger interface{ Range(VisitField) } 28 | // VisitField is called every time a message field is visited. 29 | VisitField = func(protoreflect.FieldDescriptor, protoreflect.Value) bool 30 | ) 31 | 32 | // RangeFields iterates over the fields of fs according to the specified order. 33 | func RangeFields(fs FieldRanger, less FieldOrder, fn VisitField) { 34 | if less == nil { 35 | fs.Range(fn) 36 | return 37 | } 38 | 39 | // Obtain a pre-allocated scratch buffer. 40 | p := messageFieldPool.Get().(*[]messageField) 41 | fields := (*p)[:0] 42 | defer func() { 43 | if cap(fields) < 1024 { 44 | *p = fields 45 | messageFieldPool.Put(p) 46 | } 47 | }() 48 | 49 | // Collect all fields in the message and sort them. 50 | fs.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool { 51 | fields = append(fields, messageField{fd, v}) 52 | return true 53 | }) 54 | sort.Slice(fields, func(i, j int) bool { 55 | return less(fields[i].fd, fields[j].fd) 56 | }) 57 | 58 | // Visit the fields in the specified ordering. 59 | for _, f := range fields { 60 | if !fn(f.fd, f.v) { 61 | return 62 | } 63 | } 64 | } 65 | 66 | type mapEntry struct { 67 | k protoreflect.MapKey 68 | v protoreflect.Value 69 | } 70 | 71 | var mapEntryPool = sync.Pool{ 72 | New: func() any { return new([]mapEntry) }, 73 | } 74 | 75 | type ( 76 | // EntryRanger is an interface for visiting all fields in a message. 77 | // The protoreflect.Map type implements this interface. 78 | EntryRanger interface{ Range(VisitEntry) } 79 | // VisitEntry is called every time a map entry is visited. 80 | VisitEntry = func(protoreflect.MapKey, protoreflect.Value) bool 81 | ) 82 | 83 | // RangeEntries iterates over the entries of es according to the specified order. 84 | func RangeEntries(es EntryRanger, less KeyOrder, fn VisitEntry) { 85 | if less == nil { 86 | es.Range(fn) 87 | return 88 | } 89 | 90 | // Obtain a pre-allocated scratch buffer. 91 | p := mapEntryPool.Get().(*[]mapEntry) 92 | entries := (*p)[:0] 93 | defer func() { 94 | if cap(entries) < 1024 { 95 | *p = entries 96 | mapEntryPool.Put(p) 97 | } 98 | }() 99 | 100 | // Collect all entries in the map and sort them. 101 | es.Range(func(k protoreflect.MapKey, v protoreflect.Value) bool { 102 | entries = append(entries, mapEntry{k, v}) 103 | return true 104 | }) 105 | sort.Slice(entries, func(i, j int) bool { 106 | return less(entries[i].k, entries[j].k) 107 | }) 108 | 109 | // Visit the entries in the specified ordering. 110 | for _, e := range entries { 111 | if !fn(e.k, e.v) { 112 | return 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/pragma/pragma.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package pragma provides types that can be embedded into a struct to 6 | // statically enforce or prevent certain language properties. 7 | package pragma 8 | 9 | import "sync" 10 | 11 | // NoUnkeyedLiterals can be embedded in a struct to prevent unkeyed literals. 12 | type NoUnkeyedLiterals struct{} 13 | 14 | // DoNotImplement can be embedded in an interface to prevent trivial 15 | // implementations of the interface. 16 | // 17 | // This is useful to prevent unauthorized implementations of an interface 18 | // so that it can be extended in the future for any protobuf language changes. 19 | type DoNotImplement interface{ ProtoInternal(DoNotImplement) } 20 | 21 | // DoNotCompare can be embedded in a struct to prevent comparability. 22 | type DoNotCompare [0]func() 23 | 24 | // DoNotCopy can be embedded in a struct to help prevent shallow copies. 25 | // This does not rely on a Go language feature, but rather a special case 26 | // within the vet checker. 27 | // 28 | // See https://golang.org/issues/8005. 29 | type DoNotCopy [0]sync.Mutex 30 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/protolazy/pointer_unsafe.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package protolazy 6 | 7 | import ( 8 | "sync/atomic" 9 | "unsafe" 10 | ) 11 | 12 | func atomicLoadIndex(p **[]IndexEntry) *[]IndexEntry { 13 | return (*[]IndexEntry)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(p)))) 14 | } 15 | func atomicStoreIndex(p **[]IndexEntry, v *[]IndexEntry) { 16 | atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(p)), unsafe.Pointer(v)) 17 | } 18 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/set/ints.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package set provides simple set data structures for uint64s. 6 | package set 7 | 8 | import "math/bits" 9 | 10 | // int64s represents a set of integers within the range of 0..63. 11 | type int64s uint64 12 | 13 | func (bs *int64s) Len() int { 14 | return bits.OnesCount64(uint64(*bs)) 15 | } 16 | func (bs *int64s) Has(n uint64) bool { 17 | return uint64(*bs)&(uint64(1)< 0 18 | } 19 | func (bs *int64s) Set(n uint64) { 20 | *(*uint64)(bs) |= uint64(1) << n 21 | } 22 | func (bs *int64s) Clear(n uint64) { 23 | *(*uint64)(bs) &^= uint64(1) << n 24 | } 25 | 26 | // Ints represents a set of integers within the range of 0..math.MaxUint64. 27 | type Ints struct { 28 | lo int64s 29 | hi map[uint64]struct{} 30 | } 31 | 32 | func (bs *Ints) Len() int { 33 | return bs.lo.Len() + len(bs.hi) 34 | } 35 | func (bs *Ints) Has(n uint64) bool { 36 | if n < 64 { 37 | return bs.lo.Has(n) 38 | } 39 | _, ok := bs.hi[n] 40 | return ok 41 | } 42 | func (bs *Ints) Set(n uint64) { 43 | if n < 64 { 44 | bs.lo.Set(n) 45 | return 46 | } 47 | if bs.hi == nil { 48 | bs.hi = make(map[uint64]struct{}) 49 | } 50 | bs.hi[n] = struct{}{} 51 | } 52 | func (bs *Ints) Clear(n uint64) { 53 | if n < 64 { 54 | bs.lo.Clear(n) 55 | return 56 | } 57 | delete(bs.hi, n) 58 | } 59 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/strs/strings_unsafe.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package strs 6 | 7 | import ( 8 | "unsafe" 9 | 10 | "google.golang.org/protobuf/reflect/protoreflect" 11 | ) 12 | 13 | // UnsafeString returns an unsafe string reference of b. 14 | // The caller must treat the input slice as immutable. 15 | // 16 | // WARNING: Use carefully. The returned result must not leak to the end user 17 | // unless the input slice is provably immutable. 18 | func UnsafeString(b []byte) string { 19 | return unsafe.String(unsafe.SliceData(b), len(b)) 20 | } 21 | 22 | // UnsafeBytes returns an unsafe bytes slice reference of s. 23 | // The caller must treat returned slice as immutable. 24 | // 25 | // WARNING: Use carefully. The returned result must not leak to the end user. 26 | func UnsafeBytes(s string) []byte { 27 | return unsafe.Slice(unsafe.StringData(s), len(s)) 28 | } 29 | 30 | // Builder builds a set of strings with shared lifetime. 31 | // This differs from strings.Builder, which is for building a single string. 32 | type Builder struct { 33 | buf []byte 34 | } 35 | 36 | // AppendFullName is equivalent to protoreflect.FullName.Append, 37 | // but optimized for large batches where each name has a shared lifetime. 38 | func (sb *Builder) AppendFullName(prefix protoreflect.FullName, name protoreflect.Name) protoreflect.FullName { 39 | n := len(prefix) + len(".") + len(name) 40 | if len(prefix) == 0 { 41 | n -= len(".") 42 | } 43 | sb.grow(n) 44 | sb.buf = append(sb.buf, prefix...) 45 | sb.buf = append(sb.buf, '.') 46 | sb.buf = append(sb.buf, name...) 47 | return protoreflect.FullName(sb.last(n)) 48 | } 49 | 50 | // MakeString is equivalent to string(b), but optimized for large batches 51 | // with a shared lifetime. 52 | func (sb *Builder) MakeString(b []byte) string { 53 | sb.grow(len(b)) 54 | sb.buf = append(sb.buf, b...) 55 | return sb.last(len(b)) 56 | } 57 | 58 | func (sb *Builder) grow(n int) { 59 | if cap(sb.buf)-len(sb.buf) >= n { 60 | return 61 | } 62 | 63 | // Unlike strings.Builder, we do not need to copy over the contents 64 | // of the old buffer since our builder provides no API for 65 | // retrieving previously created strings. 66 | sb.buf = make([]byte, 0, 2*(cap(sb.buf)+n)) 67 | } 68 | 69 | func (sb *Builder) last(n int) string { 70 | return UnsafeString(sb.buf[len(sb.buf)-n:]) 71 | } 72 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/internal/version/version.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package version records versioning information about this module. 6 | package version 7 | 8 | import ( 9 | "fmt" 10 | "strings" 11 | ) 12 | 13 | // These constants determine the current version of this module. 14 | // 15 | // For our release process, we enforce the following rules: 16 | // - Tagged releases use a tag that is identical to String. 17 | // - Tagged releases never reference a commit where the String 18 | // contains "devel". 19 | // - The set of all commits in this repository where String 20 | // does not contain "devel" must have a unique String. 21 | // 22 | // Steps for tagging a new release: 23 | // 24 | // 1. Create a new CL. 25 | // 26 | // 2. Update Minor, Patch, and/or PreRelease as necessary. 27 | // PreRelease must not contain the string "devel". 28 | // 29 | // 3. Since the last released minor version, have there been any changes to 30 | // generator that relies on new functionality in the runtime? 31 | // If yes, then increment RequiredGenerated. 32 | // 33 | // 4. Since the last released minor version, have there been any changes to 34 | // the runtime that removes support for old .pb.go source code? 35 | // If yes, then increment SupportMinimum. 36 | // 37 | // 5. Send out the CL for review and submit it. 38 | // Note that the next CL in step 8 must be submitted after this CL 39 | // without any other CLs in-between. 40 | // 41 | // 6. Tag a new version, where the tag is is the current String. 42 | // 43 | // 7. Write release notes for all notable changes 44 | // between this release and the last release. 45 | // 46 | // 8. Create a new CL. 47 | // 48 | // 9. Update PreRelease to include the string "devel". 49 | // For example: "" -> "devel" or "rc.1" -> "rc.1.devel" 50 | // 51 | // 10. Send out the CL for review and submit it. 52 | const ( 53 | Major = 1 54 | Minor = 36 55 | Patch = 6 56 | PreRelease = "" 57 | ) 58 | 59 | // String formats the version string for this module in semver format. 60 | // 61 | // Examples: 62 | // 63 | // v1.20.1 64 | // v1.21.0-rc.1 65 | func String() string { 66 | v := fmt.Sprintf("v%d.%d.%d", Major, Minor, Patch) 67 | if PreRelease != "" { 68 | v += "-" + PreRelease 69 | 70 | // TODO: Add metadata about the commit or build hash. 71 | // See https://golang.org/issue/29814 72 | // See https://golang.org/issue/33533 73 | var metadata string 74 | if strings.Contains(PreRelease, "devel") && metadata != "" { 75 | v += "+" + metadata 76 | } 77 | } 78 | return v 79 | } 80 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/proto/checkinit.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package proto 6 | 7 | import ( 8 | "google.golang.org/protobuf/internal/errors" 9 | "google.golang.org/protobuf/reflect/protoreflect" 10 | "google.golang.org/protobuf/runtime/protoiface" 11 | ) 12 | 13 | // CheckInitialized returns an error if any required fields in m are not set. 14 | func CheckInitialized(m Message) error { 15 | // Treat a nil message interface as an "untyped" empty message, 16 | // which we assume to have no required fields. 17 | if m == nil { 18 | return nil 19 | } 20 | 21 | return checkInitialized(m.ProtoReflect()) 22 | } 23 | 24 | // CheckInitialized returns an error if any required fields in m are not set. 25 | func checkInitialized(m protoreflect.Message) error { 26 | if methods := protoMethods(m); methods != nil && methods.CheckInitialized != nil { 27 | _, err := methods.CheckInitialized(protoiface.CheckInitializedInput{ 28 | Message: m, 29 | }) 30 | return err 31 | } 32 | return checkInitializedSlow(m) 33 | } 34 | 35 | func checkInitializedSlow(m protoreflect.Message) error { 36 | md := m.Descriptor() 37 | fds := md.Fields() 38 | for i, nums := 0, md.RequiredNumbers(); i < nums.Len(); i++ { 39 | fd := fds.ByNumber(nums.Get(i)) 40 | if !m.Has(fd) { 41 | return errors.RequiredNotSet(string(fd.FullName())) 42 | } 43 | } 44 | var err error 45 | m.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool { 46 | switch { 47 | case fd.IsList(): 48 | if fd.Message() == nil { 49 | return true 50 | } 51 | for i, list := 0, v.List(); i < list.Len() && err == nil; i++ { 52 | err = checkInitialized(list.Get(i).Message()) 53 | } 54 | case fd.IsMap(): 55 | if fd.MapValue().Message() == nil { 56 | return true 57 | } 58 | v.Map().Range(func(key protoreflect.MapKey, v protoreflect.Value) bool { 59 | err = checkInitialized(v.Message()) 60 | return err == nil 61 | }) 62 | default: 63 | if fd.Message() == nil { 64 | return true 65 | } 66 | err = checkInitialized(v.Message()) 67 | } 68 | return err == nil 69 | }) 70 | return err 71 | } 72 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/proto/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package proto provides functions operating on protocol buffer messages. 6 | // 7 | // For documentation on protocol buffers in general, see: 8 | // https://protobuf.dev. 9 | // 10 | // For a tutorial on using protocol buffers with Go, see: 11 | // https://protobuf.dev/getting-started/gotutorial. 12 | // 13 | // For a guide to generated Go protocol buffer code, see: 14 | // https://protobuf.dev/reference/go/go-generated. 15 | // 16 | // # Binary serialization 17 | // 18 | // This package contains functions to convert to and from the wire format, 19 | // an efficient binary serialization of protocol buffers. 20 | // 21 | // - [Size] reports the size of a message in the wire format. 22 | // 23 | // - [Marshal] converts a message to the wire format. 24 | // The [MarshalOptions] type provides more control over wire marshaling. 25 | // 26 | // - [Unmarshal] converts a message from the wire format. 27 | // The [UnmarshalOptions] type provides more control over wire unmarshaling. 28 | // 29 | // # Basic message operations 30 | // 31 | // - [Clone] makes a deep copy of a message. 32 | // 33 | // - [Merge] merges the content of a message into another. 34 | // 35 | // - [Equal] compares two messages. For more control over comparisons 36 | // and detailed reporting of differences, see package 37 | // [google.golang.org/protobuf/testing/protocmp]. 38 | // 39 | // - [Reset] clears the content of a message. 40 | // 41 | // - [CheckInitialized] reports whether all required fields in a message are set. 42 | // 43 | // # Optional scalar constructors 44 | // 45 | // The API for some generated messages represents optional scalar fields 46 | // as pointers to a value. For example, an optional string field has the 47 | // Go type *string. 48 | // 49 | // - [Bool], [Int32], [Int64], [Uint32], [Uint64], [Float32], [Float64], and [String] 50 | // take a value and return a pointer to a new instance of it, 51 | // to simplify construction of optional field values. 52 | // 53 | // Generated enum types usually have an Enum method which performs the 54 | // same operation. 55 | // 56 | // Optional scalar fields are only supported in proto2. 57 | // 58 | // # Extension accessors 59 | // 60 | // - [HasExtension], [GetExtension], [SetExtension], and [ClearExtension] 61 | // access extension field values in a protocol buffer message. 62 | // 63 | // Extension fields are only supported in proto2. 64 | // 65 | // # Related packages 66 | // 67 | // - Package [google.golang.org/protobuf/encoding/protojson] converts messages to 68 | // and from JSON. 69 | // 70 | // - Package [google.golang.org/protobuf/encoding/prototext] converts messages to 71 | // and from the text format. 72 | // 73 | // - Package [google.golang.org/protobuf/reflect/protoreflect] provides a 74 | // reflection interface for protocol buffer data types. 75 | // 76 | // - Package [google.golang.org/protobuf/testing/protocmp] provides features 77 | // to compare protocol buffer messages with the [github.com/google/go-cmp/cmp] 78 | // package. 79 | // 80 | // - Package [google.golang.org/protobuf/types/dynamicpb] provides a dynamic 81 | // message type, suitable for working with messages where the protocol buffer 82 | // type is only known at runtime. 83 | // 84 | // This module contains additional packages for more specialized use cases. 85 | // Consult the individual package documentation for details. 86 | package proto 87 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/proto/encode_gen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Code generated by generate-types. DO NOT EDIT. 6 | 7 | package proto 8 | 9 | import ( 10 | "math" 11 | "unicode/utf8" 12 | 13 | "google.golang.org/protobuf/encoding/protowire" 14 | "google.golang.org/protobuf/internal/errors" 15 | "google.golang.org/protobuf/internal/strs" 16 | "google.golang.org/protobuf/reflect/protoreflect" 17 | ) 18 | 19 | var wireTypes = map[protoreflect.Kind]protowire.Type{ 20 | protoreflect.BoolKind: protowire.VarintType, 21 | protoreflect.EnumKind: protowire.VarintType, 22 | protoreflect.Int32Kind: protowire.VarintType, 23 | protoreflect.Sint32Kind: protowire.VarintType, 24 | protoreflect.Uint32Kind: protowire.VarintType, 25 | protoreflect.Int64Kind: protowire.VarintType, 26 | protoreflect.Sint64Kind: protowire.VarintType, 27 | protoreflect.Uint64Kind: protowire.VarintType, 28 | protoreflect.Sfixed32Kind: protowire.Fixed32Type, 29 | protoreflect.Fixed32Kind: protowire.Fixed32Type, 30 | protoreflect.FloatKind: protowire.Fixed32Type, 31 | protoreflect.Sfixed64Kind: protowire.Fixed64Type, 32 | protoreflect.Fixed64Kind: protowire.Fixed64Type, 33 | protoreflect.DoubleKind: protowire.Fixed64Type, 34 | protoreflect.StringKind: protowire.BytesType, 35 | protoreflect.BytesKind: protowire.BytesType, 36 | protoreflect.MessageKind: protowire.BytesType, 37 | protoreflect.GroupKind: protowire.StartGroupType, 38 | } 39 | 40 | func (o MarshalOptions) marshalSingular(b []byte, fd protoreflect.FieldDescriptor, v protoreflect.Value) ([]byte, error) { 41 | switch fd.Kind() { 42 | case protoreflect.BoolKind: 43 | b = protowire.AppendVarint(b, protowire.EncodeBool(v.Bool())) 44 | case protoreflect.EnumKind: 45 | b = protowire.AppendVarint(b, uint64(v.Enum())) 46 | case protoreflect.Int32Kind: 47 | b = protowire.AppendVarint(b, uint64(int32(v.Int()))) 48 | case protoreflect.Sint32Kind: 49 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(int32(v.Int())))) 50 | case protoreflect.Uint32Kind: 51 | b = protowire.AppendVarint(b, uint64(uint32(v.Uint()))) 52 | case protoreflect.Int64Kind: 53 | b = protowire.AppendVarint(b, uint64(v.Int())) 54 | case protoreflect.Sint64Kind: 55 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(v.Int())) 56 | case protoreflect.Uint64Kind: 57 | b = protowire.AppendVarint(b, v.Uint()) 58 | case protoreflect.Sfixed32Kind: 59 | b = protowire.AppendFixed32(b, uint32(v.Int())) 60 | case protoreflect.Fixed32Kind: 61 | b = protowire.AppendFixed32(b, uint32(v.Uint())) 62 | case protoreflect.FloatKind: 63 | b = protowire.AppendFixed32(b, math.Float32bits(float32(v.Float()))) 64 | case protoreflect.Sfixed64Kind: 65 | b = protowire.AppendFixed64(b, uint64(v.Int())) 66 | case protoreflect.Fixed64Kind: 67 | b = protowire.AppendFixed64(b, v.Uint()) 68 | case protoreflect.DoubleKind: 69 | b = protowire.AppendFixed64(b, math.Float64bits(v.Float())) 70 | case protoreflect.StringKind: 71 | if strs.EnforceUTF8(fd) && !utf8.ValidString(v.String()) { 72 | return b, errors.InvalidUTF8(string(fd.FullName())) 73 | } 74 | b = protowire.AppendString(b, v.String()) 75 | case protoreflect.BytesKind: 76 | b = protowire.AppendBytes(b, v.Bytes()) 77 | case protoreflect.MessageKind: 78 | var pos int 79 | var err error 80 | b, pos = appendSpeculativeLength(b) 81 | b, err = o.marshalMessage(b, v.Message()) 82 | if err != nil { 83 | return b, err 84 | } 85 | b = finishSpeculativeLength(b, pos) 86 | case protoreflect.GroupKind: 87 | var err error 88 | b, err = o.marshalMessage(b, v.Message()) 89 | if err != nil { 90 | return b, err 91 | } 92 | b = protowire.AppendVarint(b, protowire.EncodeTag(fd.Number(), protowire.EndGroupType)) 93 | default: 94 | return b, errors.New("invalid kind %v", fd.Kind()) 95 | } 96 | return b, nil 97 | } 98 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/proto/equal.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package proto 6 | 7 | import ( 8 | "reflect" 9 | 10 | "google.golang.org/protobuf/reflect/protoreflect" 11 | "google.golang.org/protobuf/runtime/protoiface" 12 | ) 13 | 14 | // Equal reports whether two messages are equal, 15 | // by recursively comparing the fields of the message. 16 | // 17 | // - Bytes fields are equal if they contain identical bytes. 18 | // Empty bytes (regardless of nil-ness) are considered equal. 19 | // 20 | // - Floating-point fields are equal if they contain the same value. 21 | // Unlike the == operator, a NaN is equal to another NaN. 22 | // 23 | // - Other scalar fields are equal if they contain the same value. 24 | // 25 | // - Message fields are equal if they have 26 | // the same set of populated known and extension field values, and 27 | // the same set of unknown fields values. 28 | // 29 | // - Lists are equal if they are the same length and 30 | // each corresponding element is equal. 31 | // 32 | // - Maps are equal if they have the same set of keys and 33 | // the corresponding value for each key is equal. 34 | // 35 | // An invalid message is not equal to a valid message. 36 | // An invalid message is only equal to another invalid message of the 37 | // same type. An invalid message often corresponds to a nil pointer 38 | // of the concrete message type. For example, (*pb.M)(nil) is not equal 39 | // to &pb.M{}. 40 | // If two valid messages marshal to the same bytes under deterministic 41 | // serialization, then Equal is guaranteed to report true. 42 | func Equal(x, y Message) bool { 43 | if x == nil || y == nil { 44 | return x == nil && y == nil 45 | } 46 | if reflect.TypeOf(x).Kind() == reflect.Ptr && x == y { 47 | // Avoid an expensive comparison if both inputs are identical pointers. 48 | return true 49 | } 50 | mx := x.ProtoReflect() 51 | my := y.ProtoReflect() 52 | if mx.IsValid() != my.IsValid() { 53 | return false 54 | } 55 | 56 | // Only one of the messages needs to implement the fast-path for it to work. 57 | pmx := protoMethods(mx) 58 | pmy := protoMethods(my) 59 | if pmx != nil && pmy != nil && pmx.Equal != nil && pmy.Equal != nil { 60 | return pmx.Equal(protoiface.EqualInput{MessageA: mx, MessageB: my}).Equal 61 | } 62 | 63 | vx := protoreflect.ValueOfMessage(mx) 64 | vy := protoreflect.ValueOfMessage(my) 65 | return vx.Equal(vy) 66 | } 67 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/proto/messageset.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package proto 6 | 7 | import ( 8 | "google.golang.org/protobuf/encoding/protowire" 9 | "google.golang.org/protobuf/internal/encoding/messageset" 10 | "google.golang.org/protobuf/internal/errors" 11 | "google.golang.org/protobuf/internal/flags" 12 | "google.golang.org/protobuf/internal/order" 13 | "google.golang.org/protobuf/reflect/protoreflect" 14 | "google.golang.org/protobuf/reflect/protoregistry" 15 | ) 16 | 17 | func (o MarshalOptions) sizeMessageSet(m protoreflect.Message) (size int) { 18 | m.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool { 19 | size += messageset.SizeField(fd.Number()) 20 | size += protowire.SizeTag(messageset.FieldMessage) 21 | size += protowire.SizeBytes(o.size(v.Message())) 22 | return true 23 | }) 24 | size += messageset.SizeUnknown(m.GetUnknown()) 25 | return size 26 | } 27 | 28 | func (o MarshalOptions) marshalMessageSet(b []byte, m protoreflect.Message) ([]byte, error) { 29 | if !flags.ProtoLegacy { 30 | return b, errors.New("no support for message_set_wire_format") 31 | } 32 | fieldOrder := order.AnyFieldOrder 33 | if o.Deterministic { 34 | fieldOrder = order.NumberFieldOrder 35 | } 36 | var err error 37 | order.RangeFields(m, fieldOrder, func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool { 38 | b, err = o.marshalMessageSetField(b, fd, v) 39 | return err == nil 40 | }) 41 | if err != nil { 42 | return b, err 43 | } 44 | return messageset.AppendUnknown(b, m.GetUnknown()) 45 | } 46 | 47 | func (o MarshalOptions) marshalMessageSetField(b []byte, fd protoreflect.FieldDescriptor, value protoreflect.Value) ([]byte, error) { 48 | b = messageset.AppendFieldStart(b, fd.Number()) 49 | b = protowire.AppendTag(b, messageset.FieldMessage, protowire.BytesType) 50 | calculatedSize := o.Size(value.Message().Interface()) 51 | b = protowire.AppendVarint(b, uint64(calculatedSize)) 52 | before := len(b) 53 | b, err := o.marshalMessage(b, value.Message()) 54 | if err != nil { 55 | return b, err 56 | } 57 | if measuredSize := len(b) - before; calculatedSize != measuredSize { 58 | return nil, errors.MismatchedSizeCalculation(calculatedSize, measuredSize) 59 | } 60 | b = messageset.AppendFieldEnd(b) 61 | return b, nil 62 | } 63 | 64 | func (o UnmarshalOptions) unmarshalMessageSet(b []byte, m protoreflect.Message) error { 65 | if !flags.ProtoLegacy { 66 | return errors.New("no support for message_set_wire_format") 67 | } 68 | return messageset.Unmarshal(b, false, func(num protowire.Number, v []byte) error { 69 | err := o.unmarshalMessageSetField(m, num, v) 70 | if err == errUnknown { 71 | unknown := m.GetUnknown() 72 | unknown = protowire.AppendTag(unknown, num, protowire.BytesType) 73 | unknown = protowire.AppendBytes(unknown, v) 74 | m.SetUnknown(unknown) 75 | return nil 76 | } 77 | return err 78 | }) 79 | } 80 | 81 | func (o UnmarshalOptions) unmarshalMessageSetField(m protoreflect.Message, num protowire.Number, v []byte) error { 82 | md := m.Descriptor() 83 | if !md.ExtensionRanges().Has(num) { 84 | return errUnknown 85 | } 86 | xt, err := o.Resolver.FindExtensionByNumber(md.FullName(), num) 87 | if err == protoregistry.NotFound { 88 | return errUnknown 89 | } 90 | if err != nil { 91 | return errors.New("%v: unable to resolve extension %v: %v", md.FullName(), num, err) 92 | } 93 | xd := xt.TypeDescriptor() 94 | if err := o.unmarshalMessage(v, m.Mutable(xd).Message()); err != nil { 95 | return err 96 | } 97 | return nil 98 | } 99 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/proto/proto.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package proto 6 | 7 | import ( 8 | "google.golang.org/protobuf/internal/errors" 9 | "google.golang.org/protobuf/reflect/protoreflect" 10 | ) 11 | 12 | // Message is the top-level interface that all messages must implement. 13 | // It provides access to a reflective view of a message. 14 | // Any implementation of this interface may be used with all functions in the 15 | // protobuf module that accept a Message, except where otherwise specified. 16 | // 17 | // This is the v2 interface definition for protobuf messages. 18 | // The v1 interface definition is [github.com/golang/protobuf/proto.Message]. 19 | // 20 | // - To convert a v1 message to a v2 message, 21 | // use [google.golang.org/protobuf/protoadapt.MessageV2Of]. 22 | // - To convert a v2 message to a v1 message, 23 | // use [google.golang.org/protobuf/protoadapt.MessageV1Of]. 24 | type Message = protoreflect.ProtoMessage 25 | 26 | // Error matches all errors produced by packages in the protobuf module 27 | // according to [errors.Is]. 28 | // 29 | // Example usage: 30 | // 31 | // if errors.Is(err, proto.Error) { ... } 32 | var Error error 33 | 34 | func init() { 35 | Error = errors.Error 36 | } 37 | 38 | // MessageName returns the full name of m. 39 | // If m is nil, it returns an empty string. 40 | func MessageName(m Message) protoreflect.FullName { 41 | if m == nil { 42 | return "" 43 | } 44 | return m.ProtoReflect().Descriptor().FullName() 45 | } 46 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/proto/proto_methods.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // The protoreflect build tag disables use of fast-path methods. 6 | //go:build !protoreflect 7 | // +build !protoreflect 8 | 9 | package proto 10 | 11 | import ( 12 | "google.golang.org/protobuf/reflect/protoreflect" 13 | "google.golang.org/protobuf/runtime/protoiface" 14 | ) 15 | 16 | const hasProtoMethods = true 17 | 18 | func protoMethods(m protoreflect.Message) *protoiface.Methods { 19 | return m.ProtoMethods() 20 | } 21 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/proto/proto_reflect.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // The protoreflect build tag disables use of fast-path methods. 6 | //go:build protoreflect 7 | // +build protoreflect 8 | 9 | package proto 10 | 11 | import ( 12 | "google.golang.org/protobuf/reflect/protoreflect" 13 | "google.golang.org/protobuf/runtime/protoiface" 14 | ) 15 | 16 | const hasProtoMethods = false 17 | 18 | func protoMethods(m protoreflect.Message) *protoiface.Methods { 19 | return nil 20 | } 21 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/proto/reset.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package proto 6 | 7 | import ( 8 | "fmt" 9 | 10 | "google.golang.org/protobuf/reflect/protoreflect" 11 | ) 12 | 13 | // Reset clears every field in the message. 14 | // The resulting message shares no observable memory with its previous state 15 | // other than the memory for the message itself. 16 | func Reset(m Message) { 17 | if mr, ok := m.(interface{ Reset() }); ok && hasProtoMethods { 18 | mr.Reset() 19 | return 20 | } 21 | resetMessage(m.ProtoReflect()) 22 | } 23 | 24 | func resetMessage(m protoreflect.Message) { 25 | if !m.IsValid() { 26 | panic(fmt.Sprintf("cannot reset invalid %v message", m.Descriptor().FullName())) 27 | } 28 | 29 | // Clear all known fields. 30 | fds := m.Descriptor().Fields() 31 | for i := 0; i < fds.Len(); i++ { 32 | m.Clear(fds.Get(i)) 33 | } 34 | 35 | // Clear extension fields. 36 | m.Range(func(fd protoreflect.FieldDescriptor, _ protoreflect.Value) bool { 37 | m.Clear(fd) 38 | return true 39 | }) 40 | 41 | // Clear unknown fields. 42 | m.SetUnknown(nil) 43 | } 44 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/proto/size.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package proto 6 | 7 | import ( 8 | "google.golang.org/protobuf/encoding/protowire" 9 | "google.golang.org/protobuf/internal/encoding/messageset" 10 | "google.golang.org/protobuf/reflect/protoreflect" 11 | "google.golang.org/protobuf/runtime/protoiface" 12 | ) 13 | 14 | // Size returns the size in bytes of the wire-format encoding of m. 15 | // 16 | // Note that Size might return more bytes than Marshal will write in the case of 17 | // lazily decoded messages that arrive in non-minimal wire format: see 18 | // https://protobuf.dev/reference/go/size/ for more details. 19 | func Size(m Message) int { 20 | return MarshalOptions{}.Size(m) 21 | } 22 | 23 | // Size returns the size in bytes of the wire-format encoding of m. 24 | // 25 | // Note that Size might return more bytes than Marshal will write in the case of 26 | // lazily decoded messages that arrive in non-minimal wire format: see 27 | // https://protobuf.dev/reference/go/size/ for more details. 28 | func (o MarshalOptions) Size(m Message) int { 29 | // Treat a nil message interface as an empty message; nothing to output. 30 | if m == nil { 31 | return 0 32 | } 33 | 34 | return o.size(m.ProtoReflect()) 35 | } 36 | 37 | // size is a centralized function that all size operations go through. 38 | // For profiling purposes, avoid changing the name of this function or 39 | // introducing other code paths for size that do not go through this. 40 | func (o MarshalOptions) size(m protoreflect.Message) (size int) { 41 | methods := protoMethods(m) 42 | if methods != nil && methods.Size != nil { 43 | out := methods.Size(protoiface.SizeInput{ 44 | Message: m, 45 | Flags: o.flags(), 46 | }) 47 | return out.Size 48 | } 49 | if methods != nil && methods.Marshal != nil { 50 | // This is not efficient, but we don't have any choice. 51 | // This case is mainly used for legacy types with a Marshal method. 52 | out, _ := methods.Marshal(protoiface.MarshalInput{ 53 | Message: m, 54 | Flags: o.flags(), 55 | }) 56 | return len(out.Buf) 57 | } 58 | return o.sizeMessageSlow(m) 59 | } 60 | 61 | func (o MarshalOptions) sizeMessageSlow(m protoreflect.Message) (size int) { 62 | if messageset.IsMessageSet(m.Descriptor()) { 63 | return o.sizeMessageSet(m) 64 | } 65 | m.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool { 66 | size += o.sizeField(fd, v) 67 | return true 68 | }) 69 | size += len(m.GetUnknown()) 70 | return size 71 | } 72 | 73 | func (o MarshalOptions) sizeField(fd protoreflect.FieldDescriptor, value protoreflect.Value) (size int) { 74 | num := fd.Number() 75 | switch { 76 | case fd.IsList(): 77 | return o.sizeList(num, fd, value.List()) 78 | case fd.IsMap(): 79 | return o.sizeMap(num, fd, value.Map()) 80 | default: 81 | return protowire.SizeTag(num) + o.sizeSingular(num, fd.Kind(), value) 82 | } 83 | } 84 | 85 | func (o MarshalOptions) sizeList(num protowire.Number, fd protoreflect.FieldDescriptor, list protoreflect.List) (size int) { 86 | sizeTag := protowire.SizeTag(num) 87 | 88 | if fd.IsPacked() && list.Len() > 0 { 89 | content := 0 90 | for i, llen := 0, list.Len(); i < llen; i++ { 91 | content += o.sizeSingular(num, fd.Kind(), list.Get(i)) 92 | } 93 | return sizeTag + protowire.SizeBytes(content) 94 | } 95 | 96 | for i, llen := 0, list.Len(); i < llen; i++ { 97 | size += sizeTag + o.sizeSingular(num, fd.Kind(), list.Get(i)) 98 | } 99 | return size 100 | } 101 | 102 | func (o MarshalOptions) sizeMap(num protowire.Number, fd protoreflect.FieldDescriptor, mapv protoreflect.Map) (size int) { 103 | sizeTag := protowire.SizeTag(num) 104 | 105 | mapv.Range(func(key protoreflect.MapKey, value protoreflect.Value) bool { 106 | size += sizeTag 107 | size += protowire.SizeBytes(o.sizeField(fd.MapKey(), key.Value()) + o.sizeField(fd.MapValue(), value)) 108 | return true 109 | }) 110 | return size 111 | } 112 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/proto/size_gen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Code generated by generate-types. DO NOT EDIT. 6 | 7 | package proto 8 | 9 | import ( 10 | "google.golang.org/protobuf/encoding/protowire" 11 | "google.golang.org/protobuf/reflect/protoreflect" 12 | ) 13 | 14 | func (o MarshalOptions) sizeSingular(num protowire.Number, kind protoreflect.Kind, v protoreflect.Value) int { 15 | switch kind { 16 | case protoreflect.BoolKind: 17 | return protowire.SizeVarint(protowire.EncodeBool(v.Bool())) 18 | case protoreflect.EnumKind: 19 | return protowire.SizeVarint(uint64(v.Enum())) 20 | case protoreflect.Int32Kind: 21 | return protowire.SizeVarint(uint64(int32(v.Int()))) 22 | case protoreflect.Sint32Kind: 23 | return protowire.SizeVarint(protowire.EncodeZigZag(int64(int32(v.Int())))) 24 | case protoreflect.Uint32Kind: 25 | return protowire.SizeVarint(uint64(uint32(v.Uint()))) 26 | case protoreflect.Int64Kind: 27 | return protowire.SizeVarint(uint64(v.Int())) 28 | case protoreflect.Sint64Kind: 29 | return protowire.SizeVarint(protowire.EncodeZigZag(v.Int())) 30 | case protoreflect.Uint64Kind: 31 | return protowire.SizeVarint(v.Uint()) 32 | case protoreflect.Sfixed32Kind: 33 | return protowire.SizeFixed32() 34 | case protoreflect.Fixed32Kind: 35 | return protowire.SizeFixed32() 36 | case protoreflect.FloatKind: 37 | return protowire.SizeFixed32() 38 | case protoreflect.Sfixed64Kind: 39 | return protowire.SizeFixed64() 40 | case protoreflect.Fixed64Kind: 41 | return protowire.SizeFixed64() 42 | case protoreflect.DoubleKind: 43 | return protowire.SizeFixed64() 44 | case protoreflect.StringKind: 45 | return protowire.SizeBytes(len(v.String())) 46 | case protoreflect.BytesKind: 47 | return protowire.SizeBytes(len(v.Bytes())) 48 | case protoreflect.MessageKind: 49 | return protowire.SizeBytes(o.size(v.Message())) 50 | case protoreflect.GroupKind: 51 | return protowire.SizeGroup(num, o.size(v.Message())) 52 | default: 53 | return 0 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/proto/wrapperopaque.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package proto 6 | 7 | // ValueOrNil returns nil if has is false, or a pointer to a new variable 8 | // containing the value returned by the specified getter. 9 | // 10 | // This function is similar to the wrappers (proto.Int32(), proto.String(), 11 | // etc.), but is generic (works for any field type) and works with the hasser 12 | // and getter of a field, as opposed to a value. 13 | // 14 | // This is convenient when populating builder fields. 15 | // 16 | // Example: 17 | // 18 | // hop := attr.GetDirectHop() 19 | // injectedRoute := ripb.InjectedRoute_builder{ 20 | // Prefixes: route.GetPrefixes(), 21 | // NextHop: proto.ValueOrNil(hop.HasAddress(), hop.GetAddress), 22 | // } 23 | func ValueOrNil[T any](has bool, getter func() T) *T { 24 | if !has { 25 | return nil 26 | } 27 | v := getter() 28 | return &v 29 | } 30 | 31 | // ValueOrDefault returns the protobuf message val if val is not nil, otherwise 32 | // it returns a pointer to an empty val message. 33 | // 34 | // This function allows for translating code from the old Open Struct API to the 35 | // new Opaque API. 36 | // 37 | // The old Open Struct API represented oneof fields with a wrapper struct: 38 | // 39 | // var signedImg *accountpb.SignedImage 40 | // profile := &accountpb.Profile{ 41 | // // The Avatar oneof will be set, with an empty SignedImage. 42 | // Avatar: &accountpb.Profile_SignedImage{signedImg}, 43 | // } 44 | // 45 | // The new Opaque API treats oneof fields like regular fields, there are no more 46 | // wrapper structs: 47 | // 48 | // var signedImg *accountpb.SignedImage 49 | // profile := &accountpb.Profile{} 50 | // profile.SetSignedImage(signedImg) 51 | // 52 | // For convenience, the Opaque API also offers Builders, which allow for a 53 | // direct translation of struct initialization. However, because Builders use 54 | // nilness to represent field presence (but there is no non-nil wrapper struct 55 | // anymore), Builders cannot distinguish between an unset oneof and a set oneof 56 | // with nil message. The above code would need to be translated with help of the 57 | // ValueOrDefault function to retain the same behavior: 58 | // 59 | // var signedImg *accountpb.SignedImage 60 | // return &accountpb.Profile_builder{ 61 | // SignedImage: proto.ValueOrDefault(signedImg), 62 | // }.Build() 63 | func ValueOrDefault[T interface { 64 | *P 65 | Message 66 | }, P any](val T) T { 67 | if val == nil { 68 | return T(new(P)) 69 | } 70 | return val 71 | } 72 | 73 | // ValueOrDefaultBytes is like ValueOrDefault but for working with fields of 74 | // type []byte. 75 | func ValueOrDefaultBytes(val []byte) []byte { 76 | if val == nil { 77 | return []byte{} 78 | } 79 | return val 80 | } 81 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/proto/wrappers.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package proto 6 | 7 | // Bool stores v in a new bool value and returns a pointer to it. 8 | func Bool(v bool) *bool { return &v } 9 | 10 | // Int32 stores v in a new int32 value and returns a pointer to it. 11 | func Int32(v int32) *int32 { return &v } 12 | 13 | // Int64 stores v in a new int64 value and returns a pointer to it. 14 | func Int64(v int64) *int64 { return &v } 15 | 16 | // Float32 stores v in a new float32 value and returns a pointer to it. 17 | func Float32(v float32) *float32 { return &v } 18 | 19 | // Float64 stores v in a new float64 value and returns a pointer to it. 20 | func Float64(v float64) *float64 { return &v } 21 | 22 | // Uint32 stores v in a new uint32 value and returns a pointer to it. 23 | func Uint32(v uint32) *uint32 { return &v } 24 | 25 | // Uint64 stores v in a new uint64 value and returns a pointer to it. 26 | func Uint64(v uint64) *uint64 { return &v } 27 | 28 | // String stores v in a new string value and returns a pointer to it. 29 | func String(v string) *string { return &v } 30 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/reflect/protoreflect/methods.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package protoreflect 6 | 7 | import ( 8 | "google.golang.org/protobuf/internal/pragma" 9 | ) 10 | 11 | // The following types are used by the fast-path Message.ProtoMethods method. 12 | // 13 | // To avoid polluting the public protoreflect API with types used only by 14 | // low-level implementations, the canonical definitions of these types are 15 | // in the runtime/protoiface package. The definitions here and in protoiface 16 | // must be kept in sync. 17 | type ( 18 | methods = struct { 19 | pragma.NoUnkeyedLiterals 20 | Flags supportFlags 21 | Size func(sizeInput) sizeOutput 22 | Marshal func(marshalInput) (marshalOutput, error) 23 | Unmarshal func(unmarshalInput) (unmarshalOutput, error) 24 | Merge func(mergeInput) mergeOutput 25 | CheckInitialized func(checkInitializedInput) (checkInitializedOutput, error) 26 | Equal func(equalInput) equalOutput 27 | } 28 | supportFlags = uint64 29 | sizeInput = struct { 30 | pragma.NoUnkeyedLiterals 31 | Message Message 32 | Flags uint8 33 | } 34 | sizeOutput = struct { 35 | pragma.NoUnkeyedLiterals 36 | Size int 37 | } 38 | marshalInput = struct { 39 | pragma.NoUnkeyedLiterals 40 | Message Message 41 | Buf []byte 42 | Flags uint8 43 | } 44 | marshalOutput = struct { 45 | pragma.NoUnkeyedLiterals 46 | Buf []byte 47 | } 48 | unmarshalInput = struct { 49 | pragma.NoUnkeyedLiterals 50 | Message Message 51 | Buf []byte 52 | Flags uint8 53 | Resolver interface { 54 | FindExtensionByName(field FullName) (ExtensionType, error) 55 | FindExtensionByNumber(message FullName, field FieldNumber) (ExtensionType, error) 56 | } 57 | Depth int 58 | } 59 | unmarshalOutput = struct { 60 | pragma.NoUnkeyedLiterals 61 | Flags uint8 62 | } 63 | mergeInput = struct { 64 | pragma.NoUnkeyedLiterals 65 | Source Message 66 | Destination Message 67 | } 68 | mergeOutput = struct { 69 | pragma.NoUnkeyedLiterals 70 | Flags uint8 71 | } 72 | checkInitializedInput = struct { 73 | pragma.NoUnkeyedLiterals 74 | Message Message 75 | } 76 | checkInitializedOutput = struct { 77 | pragma.NoUnkeyedLiterals 78 | } 79 | equalInput = struct { 80 | pragma.NoUnkeyedLiterals 81 | MessageA Message 82 | MessageB Message 83 | } 84 | equalOutput = struct { 85 | pragma.NoUnkeyedLiterals 86 | Equal bool 87 | } 88 | ) 89 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/reflect/protoreflect/source.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package protoreflect 6 | 7 | import ( 8 | "strconv" 9 | ) 10 | 11 | // SourceLocations is a list of source locations. 12 | type SourceLocations interface { 13 | // Len reports the number of source locations in the proto file. 14 | Len() int 15 | // Get returns the ith SourceLocation. It panics if out of bounds. 16 | Get(int) SourceLocation 17 | 18 | // ByPath returns the SourceLocation for the given path, 19 | // returning the first location if multiple exist for the same path. 20 | // If multiple locations exist for the same path, 21 | // then SourceLocation.Next index can be used to identify the 22 | // index of the next SourceLocation. 23 | // If no location exists for this path, it returns the zero value. 24 | ByPath(path SourcePath) SourceLocation 25 | 26 | // ByDescriptor returns the SourceLocation for the given descriptor, 27 | // returning the first location if multiple exist for the same path. 28 | // If no location exists for this descriptor, it returns the zero value. 29 | ByDescriptor(desc Descriptor) SourceLocation 30 | 31 | doNotImplement 32 | } 33 | 34 | // SourceLocation describes a source location and 35 | // corresponds with the google.protobuf.SourceCodeInfo.Location message. 36 | type SourceLocation struct { 37 | // Path is the path to the declaration from the root file descriptor. 38 | // The contents of this slice must not be mutated. 39 | Path SourcePath 40 | 41 | // StartLine and StartColumn are the zero-indexed starting location 42 | // in the source file for the declaration. 43 | StartLine, StartColumn int 44 | // EndLine and EndColumn are the zero-indexed ending location 45 | // in the source file for the declaration. 46 | // In the descriptor.proto, the end line may be omitted if it is identical 47 | // to the start line. Here, it is always populated. 48 | EndLine, EndColumn int 49 | 50 | // LeadingDetachedComments are the leading detached comments 51 | // for the declaration. The contents of this slice must not be mutated. 52 | LeadingDetachedComments []string 53 | // LeadingComments is the leading attached comment for the declaration. 54 | LeadingComments string 55 | // TrailingComments is the trailing attached comment for the declaration. 56 | TrailingComments string 57 | 58 | // Next is an index into SourceLocations for the next source location that 59 | // has the same Path. It is zero if there is no next location. 60 | Next int 61 | } 62 | 63 | // SourcePath identifies part of a file descriptor for a source location. 64 | // The SourcePath is a sequence of either field numbers or indexes into 65 | // a repeated field that form a path starting from the root file descriptor. 66 | // 67 | // See google.protobuf.SourceCodeInfo.Location.path. 68 | type SourcePath []int32 69 | 70 | // Equal reports whether p1 equals p2. 71 | func (p1 SourcePath) Equal(p2 SourcePath) bool { 72 | if len(p1) != len(p2) { 73 | return false 74 | } 75 | for i := range p1 { 76 | if p1[i] != p2[i] { 77 | return false 78 | } 79 | } 80 | return true 81 | } 82 | 83 | // String formats the path in a humanly readable manner. 84 | // The output is guaranteed to be deterministic, 85 | // making it suitable for use as a key into a Go map. 86 | // It is not guaranteed to be stable as the exact output could change 87 | // in a future version of this module. 88 | // 89 | // Example output: 90 | // 91 | // .message_type[6].nested_type[15].field[3] 92 | func (p SourcePath) String() string { 93 | b := p.appendFileDescriptorProto(nil) 94 | for _, i := range p { 95 | b = append(b, '.') 96 | b = strconv.AppendInt(b, int64(i), 10) 97 | } 98 | return string(b) 99 | } 100 | 101 | type appendFunc func(*SourcePath, []byte) []byte 102 | 103 | func (p *SourcePath) appendSingularField(b []byte, name string, f appendFunc) []byte { 104 | if len(*p) == 0 { 105 | return b 106 | } 107 | b = append(b, '.') 108 | b = append(b, name...) 109 | *p = (*p)[1:] 110 | if f != nil { 111 | b = f(p, b) 112 | } 113 | return b 114 | } 115 | 116 | func (p *SourcePath) appendRepeatedField(b []byte, name string, f appendFunc) []byte { 117 | b = p.appendSingularField(b, name, nil) 118 | if len(*p) == 0 || (*p)[0] < 0 { 119 | return b 120 | } 121 | b = append(b, '[') 122 | b = strconv.AppendUint(b, uint64((*p)[0]), 10) 123 | b = append(b, ']') 124 | *p = (*p)[1:] 125 | if f != nil { 126 | b = f(p, b) 127 | } 128 | return b 129 | } 130 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/reflect/protoreflect/value_equal.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package protoreflect 6 | 7 | import ( 8 | "bytes" 9 | "fmt" 10 | "math" 11 | "reflect" 12 | 13 | "google.golang.org/protobuf/encoding/protowire" 14 | ) 15 | 16 | // Equal reports whether v1 and v2 are recursively equal. 17 | // 18 | // - Values of different types are always unequal. 19 | // 20 | // - Bytes values are equal if they contain identical bytes. 21 | // Empty bytes (regardless of nil-ness) are considered equal. 22 | // 23 | // - Floating point values are equal if they contain the same value. 24 | // Unlike the == operator, a NaN is equal to another NaN. 25 | // 26 | // - Enums are equal if they contain the same number. 27 | // Since [Value] does not contain an enum descriptor, 28 | // enum values do not consider the type of the enum. 29 | // 30 | // - Other scalar values are equal if they contain the same value. 31 | // 32 | // - [Message] values are equal if they belong to the same message descriptor, 33 | // have the same set of populated known and extension field values, 34 | // and the same set of unknown fields values. 35 | // 36 | // - [List] values are equal if they are the same length and 37 | // each corresponding element is equal. 38 | // 39 | // - [Map] values are equal if they have the same set of keys and 40 | // the corresponding value for each key is equal. 41 | func (v1 Value) Equal(v2 Value) bool { 42 | return equalValue(v1, v2) 43 | } 44 | 45 | func equalValue(x, y Value) bool { 46 | eqType := x.typ == y.typ 47 | switch x.typ { 48 | case nilType: 49 | return eqType 50 | case boolType: 51 | return eqType && x.Bool() == y.Bool() 52 | case int32Type, int64Type: 53 | return eqType && x.Int() == y.Int() 54 | case uint32Type, uint64Type: 55 | return eqType && x.Uint() == y.Uint() 56 | case float32Type, float64Type: 57 | return eqType && equalFloat(x.Float(), y.Float()) 58 | case stringType: 59 | return eqType && x.String() == y.String() 60 | case bytesType: 61 | return eqType && bytes.Equal(x.Bytes(), y.Bytes()) 62 | case enumType: 63 | return eqType && x.Enum() == y.Enum() 64 | default: 65 | switch x := x.Interface().(type) { 66 | case Message: 67 | y, ok := y.Interface().(Message) 68 | return ok && equalMessage(x, y) 69 | case List: 70 | y, ok := y.Interface().(List) 71 | return ok && equalList(x, y) 72 | case Map: 73 | y, ok := y.Interface().(Map) 74 | return ok && equalMap(x, y) 75 | default: 76 | panic(fmt.Sprintf("unknown type: %T", x)) 77 | } 78 | } 79 | } 80 | 81 | // equalFloat compares two floats, where NaNs are treated as equal. 82 | func equalFloat(x, y float64) bool { 83 | if math.IsNaN(x) || math.IsNaN(y) { 84 | return math.IsNaN(x) && math.IsNaN(y) 85 | } 86 | return x == y 87 | } 88 | 89 | // equalMessage compares two messages. 90 | func equalMessage(mx, my Message) bool { 91 | if mx.Descriptor() != my.Descriptor() { 92 | return false 93 | } 94 | 95 | nx := 0 96 | equal := true 97 | mx.Range(func(fd FieldDescriptor, vx Value) bool { 98 | nx++ 99 | vy := my.Get(fd) 100 | equal = my.Has(fd) && equalValue(vx, vy) 101 | return equal 102 | }) 103 | if !equal { 104 | return false 105 | } 106 | ny := 0 107 | my.Range(func(fd FieldDescriptor, vx Value) bool { 108 | ny++ 109 | return true 110 | }) 111 | if nx != ny { 112 | return false 113 | } 114 | 115 | return equalUnknown(mx.GetUnknown(), my.GetUnknown()) 116 | } 117 | 118 | // equalList compares two lists. 119 | func equalList(x, y List) bool { 120 | if x.Len() != y.Len() { 121 | return false 122 | } 123 | for i := x.Len() - 1; i >= 0; i-- { 124 | if !equalValue(x.Get(i), y.Get(i)) { 125 | return false 126 | } 127 | } 128 | return true 129 | } 130 | 131 | // equalMap compares two maps. 132 | func equalMap(x, y Map) bool { 133 | if x.Len() != y.Len() { 134 | return false 135 | } 136 | equal := true 137 | x.Range(func(k MapKey, vx Value) bool { 138 | vy := y.Get(k) 139 | equal = y.Has(k) && equalValue(vx, vy) 140 | return equal 141 | }) 142 | return equal 143 | } 144 | 145 | // equalUnknown compares unknown fields by direct comparison on the raw bytes 146 | // of each individual field number. 147 | func equalUnknown(x, y RawFields) bool { 148 | if len(x) != len(y) { 149 | return false 150 | } 151 | if bytes.Equal([]byte(x), []byte(y)) { 152 | return true 153 | } 154 | 155 | mx := make(map[FieldNumber]RawFields) 156 | my := make(map[FieldNumber]RawFields) 157 | for len(x) > 0 { 158 | fnum, _, n := protowire.ConsumeField(x) 159 | mx[fnum] = append(mx[fnum], x[:n]...) 160 | x = x[n:] 161 | } 162 | for len(y) > 0 { 163 | fnum, _, n := protowire.ConsumeField(y) 164 | my[fnum] = append(my[fnum], y[:n]...) 165 | y = y[n:] 166 | } 167 | return reflect.DeepEqual(mx, my) 168 | } 169 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/reflect/protoreflect/value_unsafe.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package protoreflect 6 | 7 | import ( 8 | "unsafe" 9 | 10 | "google.golang.org/protobuf/internal/pragma" 11 | ) 12 | 13 | type ( 14 | ifaceHeader struct { 15 | _ [0]any // if interfaces have greater alignment than unsafe.Pointer, this will enforce it. 16 | Type unsafe.Pointer 17 | Data unsafe.Pointer 18 | } 19 | ) 20 | 21 | var ( 22 | nilType = typeOf(nil) 23 | boolType = typeOf(*new(bool)) 24 | int32Type = typeOf(*new(int32)) 25 | int64Type = typeOf(*new(int64)) 26 | uint32Type = typeOf(*new(uint32)) 27 | uint64Type = typeOf(*new(uint64)) 28 | float32Type = typeOf(*new(float32)) 29 | float64Type = typeOf(*new(float64)) 30 | stringType = typeOf(*new(string)) 31 | bytesType = typeOf(*new([]byte)) 32 | enumType = typeOf(*new(EnumNumber)) 33 | ) 34 | 35 | // typeOf returns a pointer to the Go type information. 36 | // The pointer is comparable and equal if and only if the types are identical. 37 | func typeOf(t any) unsafe.Pointer { 38 | return (*ifaceHeader)(unsafe.Pointer(&t)).Type 39 | } 40 | 41 | // value is a union where only one type can be represented at a time. 42 | // The struct is 24B large on 64-bit systems and requires the minimum storage 43 | // necessary to represent each possible type. 44 | // 45 | // The Go GC needs to be able to scan variables containing pointers. 46 | // As such, pointers and non-pointers cannot be intermixed. 47 | type value struct { 48 | pragma.DoNotCompare // 0B 49 | 50 | // typ stores the type of the value as a pointer to the Go type. 51 | typ unsafe.Pointer // 8B 52 | 53 | // ptr stores the data pointer for a String, Bytes, or interface value. 54 | ptr unsafe.Pointer // 8B 55 | 56 | // num stores a Bool, Int32, Int64, Uint32, Uint64, Float32, Float64, or 57 | // Enum value as a raw uint64. 58 | // 59 | // It is also used to store the length of a String or Bytes value; 60 | // the capacity is ignored. 61 | num uint64 // 8B 62 | } 63 | 64 | func valueOfString(v string) Value { 65 | return Value{typ: stringType, ptr: unsafe.Pointer(unsafe.StringData(v)), num: uint64(len(v))} 66 | } 67 | func valueOfBytes(v []byte) Value { 68 | return Value{typ: bytesType, ptr: unsafe.Pointer(unsafe.SliceData(v)), num: uint64(len(v))} 69 | } 70 | func valueOfIface(v any) Value { 71 | p := (*ifaceHeader)(unsafe.Pointer(&v)) 72 | return Value{typ: p.Type, ptr: p.Data} 73 | } 74 | 75 | func (v Value) getString() string { 76 | return unsafe.String((*byte)(v.ptr), v.num) 77 | } 78 | func (v Value) getBytes() []byte { 79 | return unsafe.Slice((*byte)(v.ptr), v.num) 80 | } 81 | func (v Value) getIface() (x any) { 82 | *(*ifaceHeader)(unsafe.Pointer(&x)) = ifaceHeader{Type: v.typ, Data: v.ptr} 83 | return x 84 | } 85 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/runtime/protoiface/legacy.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package protoiface 6 | 7 | type MessageV1 interface { 8 | Reset() 9 | String() string 10 | ProtoMessage() 11 | } 12 | 13 | type ExtensionRangeV1 struct { 14 | Start, End int32 // both inclusive 15 | } 16 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/runtime/protoimpl/impl.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package protoimpl contains the default implementation for messages 6 | // generated by protoc-gen-go. 7 | // 8 | // WARNING: This package should only ever be imported by generated messages. 9 | // The compatibility agreement covers nothing except for functionality needed 10 | // to keep existing generated messages operational. Breakages that occur due 11 | // to unauthorized usages of this package are not the author's responsibility. 12 | package protoimpl 13 | 14 | import ( 15 | "google.golang.org/protobuf/internal/filedesc" 16 | "google.golang.org/protobuf/internal/filetype" 17 | "google.golang.org/protobuf/internal/impl" 18 | "google.golang.org/protobuf/internal/protolazy" 19 | ) 20 | 21 | // UnsafeEnabled specifies whether package unsafe can be used. 22 | const UnsafeEnabled = impl.UnsafeEnabled 23 | 24 | type ( 25 | // Types used by generated code in init functions. 26 | DescBuilder = filedesc.Builder 27 | TypeBuilder = filetype.Builder 28 | 29 | // Types used by generated code to implement EnumType, MessageType, and ExtensionType. 30 | EnumInfo = impl.EnumInfo 31 | MessageInfo = impl.MessageInfo 32 | ExtensionInfo = impl.ExtensionInfo 33 | 34 | // Types embedded in generated messages. 35 | MessageState = impl.MessageState 36 | SizeCache = impl.SizeCache 37 | WeakFields = impl.WeakFields 38 | UnknownFields = impl.UnknownFields 39 | ExtensionFields = impl.ExtensionFields 40 | ExtensionFieldV1 = impl.ExtensionField 41 | 42 | Pointer = impl.Pointer 43 | 44 | LazyUnmarshalInfo = *protolazy.XXX_lazyUnmarshalInfo 45 | RaceDetectHookData = impl.RaceDetectHookData 46 | ) 47 | 48 | var X impl.Export 49 | -------------------------------------------------------------------------------- /vendor/google.golang.org/protobuf/runtime/protoimpl/version.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package protoimpl 6 | 7 | import ( 8 | "google.golang.org/protobuf/internal/version" 9 | ) 10 | 11 | const ( 12 | // MaxVersion is the maximum supported version for generated .pb.go files. 13 | // It is always the current version of the module. 14 | MaxVersion = version.Minor 15 | 16 | // GenVersion is the runtime version required by generated .pb.go files. 17 | // This is incremented when generated code relies on new functionality 18 | // in the runtime. 19 | GenVersion = 20 20 | 21 | // MinVersion is the minimum supported version for generated .pb.go files. 22 | // This is incremented when the runtime drops support for old code. 23 | MinVersion = 0 24 | ) 25 | 26 | // EnforceVersion is used by code generated by protoc-gen-go 27 | // to statically enforce minimum and maximum versions of this package. 28 | // A compilation failure implies either that: 29 | // - the runtime package is too old and needs to be updated OR 30 | // - the generated code is too old and needs to be regenerated. 31 | // 32 | // The runtime package can be upgraded by running: 33 | // 34 | // go get google.golang.org/protobuf 35 | // 36 | // The generated code can be regenerated by running: 37 | // 38 | // protoc --go_out=${PROTOC_GEN_GO_ARGS} ${PROTO_FILES} 39 | // 40 | // Example usage by generated code: 41 | // 42 | // const ( 43 | // // Verify that this generated code is sufficiently up-to-date. 44 | // _ = protoimpl.EnforceVersion(genVersion - protoimpl.MinVersion) 45 | // // Verify that runtime/protoimpl is sufficiently up-to-date. 46 | // _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - genVersion) 47 | // ) 48 | // 49 | // The genVersion is the current minor version used to generated the code. 50 | // This compile-time check relies on negative integer overflow of a uint 51 | // being a compilation failure (guaranteed by the Go specification). 52 | type EnforceVersion uint 53 | 54 | // This enforces the following invariant: 55 | // 56 | // MinVersion ≤ GenVersion ≤ MaxVersion 57 | const ( 58 | _ = EnforceVersion(GenVersion - MinVersion) 59 | _ = EnforceVersion(MaxVersion - GenVersion) 60 | ) 61 | -------------------------------------------------------------------------------- /vendor/modules.txt: -------------------------------------------------------------------------------- 1 | # github.com/davecgh/go-spew v1.1.1 2 | ## explicit 3 | github.com/davecgh/go-spew/spew 4 | # github.com/pkg/errors v0.9.1 5 | ## explicit 6 | github.com/pkg/errors 7 | # github.com/pmezard/go-difflib v1.0.0 8 | ## explicit 9 | github.com/pmezard/go-difflib/difflib 10 | # github.com/stretchr/testify v1.3.0 11 | ## explicit 12 | github.com/stretchr/testify/assert 13 | github.com/stretchr/testify/require 14 | # google.golang.org/protobuf v1.36.6 15 | ## explicit; go 1.22 16 | google.golang.org/protobuf/encoding/prototext 17 | google.golang.org/protobuf/encoding/protowire 18 | google.golang.org/protobuf/internal/descfmt 19 | google.golang.org/protobuf/internal/descopts 20 | google.golang.org/protobuf/internal/detrand 21 | google.golang.org/protobuf/internal/editiondefaults 22 | google.golang.org/protobuf/internal/encoding/defval 23 | google.golang.org/protobuf/internal/encoding/messageset 24 | google.golang.org/protobuf/internal/encoding/tag 25 | google.golang.org/protobuf/internal/encoding/text 26 | google.golang.org/protobuf/internal/errors 27 | google.golang.org/protobuf/internal/filedesc 28 | google.golang.org/protobuf/internal/filetype 29 | google.golang.org/protobuf/internal/flags 30 | google.golang.org/protobuf/internal/genid 31 | google.golang.org/protobuf/internal/impl 32 | google.golang.org/protobuf/internal/order 33 | google.golang.org/protobuf/internal/pragma 34 | google.golang.org/protobuf/internal/protolazy 35 | google.golang.org/protobuf/internal/set 36 | google.golang.org/protobuf/internal/strs 37 | google.golang.org/protobuf/internal/version 38 | google.golang.org/protobuf/proto 39 | google.golang.org/protobuf/reflect/protoreflect 40 | google.golang.org/protobuf/reflect/protoregistry 41 | google.golang.org/protobuf/runtime/protoiface 42 | google.golang.org/protobuf/runtime/protoimpl 43 | google.golang.org/protobuf/types/descriptorpb 44 | google.golang.org/protobuf/types/pluginpb 45 | --------------------------------------------------------------------------------