chaokunyang commented on code in PR #3723: URL: https://github.com/apache/fory/pull/3723#discussion_r3418586875
########## docs/guide/dart/grpc-support.md: ########## @@ -0,0 +1,310 @@ +--- +title: gRPC Support +sidebar_position: 12 +id: grpc_support +license: | + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--- + +Fory can generate Dart gRPC service companions for schemas that define services. +The generated code uses normal `package:grpc` clients, service bases, method +descriptors, call options, deadlines, cancellations, and status codes, while +request and response objects are serialized with Fory instead of protobuf. + +Use this mode when both RPC peers are generated from the same Fory IDL, protobuf +IDL, or FlatBuffers IDL and both sides expect Fory-encoded message bodies. Use +normal protobuf gRPC generation for APIs that must be consumed by generic +protobuf clients, reflection tools, or components that expect protobuf message +bytes. + +## Add Dependencies + +The `fory` package does not add gRPC dependencies. Add `grpc` (and the +`build_runner` dev dependency that generates the Fory serializer code) in the +application that compiles or runs generated service companions: + +```yaml +dependencies: + fory: ^1.1.0 + grpc: ^4.0.0 + +dev_dependencies: + build_runner: ^2.4.0 +``` + +The same dependencies cover both client and server applications. + +## Define a Service + +Service definitions can come from Fory IDL, protobuf IDL, or FlatBuffers +`rpc_service` definitions. A Fory IDL service looks like this: + +```protobuf +package demo.greeter; + +message HelloRequest { + string name = 1; +} + +message HelloReply { + string reply = 1; +} + +service Greeter { + rpc SayHello (HelloRequest) returns (HelloReply); +} +``` + +Generate Dart model and gRPC companion code with `--grpc`: + +```bash +foryc service.fdl --dart_out=./lib/generated --grpc +``` + +Then run `build_runner` once to emit the Fory serializer part file for the +generated models (this step is required before the code can run): + +```bash +dart run build_runner build --delete-conflicting-outputs +``` + +For this schema, the Dart generator emits: + +| File | Purpose | +| ------------------------------------------------ | ---------------------------------------------------- | +| `demo/greeter/demo_greeter.dart` | Fory model types and the schema module | Review Comment: These generated names do not match the current Dart generator for the command above. With source `service.fdl` and package `demo.greeter`, `_module_file_name_for_schema` uses the package leaf and emits `demo/greeter/greeter.dart`, `greeter.fory.dart`, `greeter_grpc.dart`, and `GreeterForyModule`, not `demo_greeter.*` / `DemoGreeterForyModule`. Please either update the docs/examples to match the current output or change the generator if source-stem-owned module names are the intended design. ########## .github/workflows/ci.yml: ########## @@ -855,6 +855,50 @@ jobs: cd integration_tests/grpc_tests/java mvn -T16 --no-transfer-progress -Dtest=KotlinGrpcInteropTest test + grpc_java_dart_tests: + name: Java/Dart gRPC Tests + needs: changes + if: needs.changes.outputs.grpc_tests == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: 21 + distribution: "temurin" + - name: Set up Python 3.11 + uses: actions/setup-python@v5 + with: + python-version: 3.11 + cache: "pip" + - name: Set up Dart + uses: dart-lang/setup-dart@v1 Review Comment: This adds an unpinned third-party action to ASF CI. The existing Dart release workflow pins `dart-lang/setup-dart` to a commit SHA (`e51d8... # v1.7.1`), so this job should use a pinned SHA or the same approved setup path instead of `@v1` to avoid mutable action resolution and ASF action-policy issues. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
