Skip to content

feat(compiler): support C++ gRPC code generation - #3877

Draft
BaldDemian wants to merge 1 commit into
apache:mainfrom
BaldDemian:cpp-grpc
Draft

feat(compiler): support C++ gRPC code generation#3877
BaldDemian wants to merge 1 commit into
apache:mainfrom
BaldDemian:cpp-grpc

Conversation

@BaldDemian

@BaldDemian BaldDemian commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Why?

Support C++ gRPC code generation.

What does this PR do?

Overview

This PR adds C++ gRPC code generation support.
All unary, server-streaming, client-streaming, and bidirectional RPC types are supported.
They integrate with gRPC C++ synchronous APIs.

Fory-backed codec

Generated gRPC code uses Fory as codec. Given that the codec is relatively small, it is generated directed within each *_service_grpc.h.
On writes, codec moves serialized bytes into a gRPC Slice, avoiding an additional outbound payload copy. On reads, it uses a single ByteBuffer slice when possible and merges fragmented buffers only when necessary.

Error-handling

To make the logic more robust, this PR also adds gRPC-related naming collision detection and escaping.
This PR also considers special characters of C++ such as compilation guards.
Generated model and service headers use sanitized include guards;
the shared Fory codec is protected by FORY_GENERATED_GRPC_SERIALIZATION_TRAITS_;
each grpc::SerializationTraits<T> specialization has a stable, type-specific guard derived from a sanitized fully qualified type name and a SHA-256 prefix. This prevents duplicate specializations when several generated service headers use the same message type.

Testing

This PR adds compiler-side pytests and C++-Java gRPC interop tests. It also adds a dedicated job in the CI.

Documentation

This PR adds documentation for the usage and example of the C++ gRPC code generation feature.

Related issues

Close #3276.

AI Contribution Checklist

  • Substantial AI assistance was used in this PR: yes / no
  • If yes, I included a completed AI Contribution Checklist in this PR description and the required AI Usage Disclosure.
  • If yes, my PR description includes the required ai_review summary and screenshot evidence or equivalent persisted links of the final clean AI review results from both fresh reviewers described in AI_POLICY.md, the Fory-guided reviewer and the independent general reviewer, on the current PR diff or current HEAD after the latest code changes.

Does this PR introduce any user-facing change?

N/A.

Benchmark

N/A.

@BaldDemian
BaldDemian force-pushed the cpp-grpc branch 3 times, most recently from d93b1e2 to cce1a87 Compare July 22, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Compiler][gRPC][C++] Generate gRPC stubs with Fory codec

1 participant