How trpc-group/trpc-cpp works
Project Type and Purpose
• This is a C++ RPC framework (tRPC-Cpp) that provides a layered, plugin-based RPC engine (not a standalone app), intended for embedding into C++ services or clients.
• It is composed of a “framework core” (runtime, transport, RPC) plus a rich plugin ecosystem (protocol codecs, serialization, compressor, naming, config, logging, metrics, tracing, telemetry, tools).
File-Structure Analysis
• Top-level: README, docs, examples, tests, third_party, cmake, BUILD/WORKSPACE for Bazel, CMakeLists for CMake.
• “trpc/” directory holds the core engine, subdivided into modules: runtime, transport, rpc, codec, common, filter, overload_control, metrics, naming, serialization, server, client, stream, tools, telemetry, tracing.
• “plugins” are implemented under each module: e.g., trpc/codec/grpc, trpc/codec/http, trpc/serialization/pb, etc.
• Examples under “examples/” show how to drive the framework as a client or server for various protocols.
Key README Insights
• Core layers:
• Runtime (thread‐model, io‐model)
• Transport (network I/O, protocol framing)
• RPC (service proxies, handlers, sync/async/stream)
• Admin interface for management.
• Plugin types: protocol codec, serialization, compressor, naming, config, logging, metrics, tracing, telemetry, plus tools (admin, tvar, rpcz).
Main Components
• Runtime Layer
• Thread-model (thread, fiber)
• IO-model (reactor for network, async‐io for disk)
• Transport Layer
• Client transport (TCP/UDP/SSL/Unix‐socket)
• Server transport
• Codec manager (selects protocol codec plugin)
• RPC Layer
• Client side: Service proxy, client context, call patterns (sync/future/fiber)
• Server side: Service dispatcher, method handlers (unary, streaming, non-RPC, one-way)
• Admin Interface (over RPC)
• Protocol codecs: trpc, http, grpc, rpcz, flatbuffers_protocol, third-party protocol
• Serialization: pb, flatbuffers, json, noop
• Compression: gzip, zlib, snappy, lz4
• Naming: registry, load balance strategies
• Config: local file, etcd plugin support
• Logging: default, cls plugin
• Metrics: built-in, Prometheus plugin
• Tracing: built-in, Jaeger plugin
• Telemetry: built-in, OpenTelemetry plugin
• Tools: admin service, tvar, rpcz
c. External Systems
• Backends for plugins, e.g., etcd, Prometheus server, Jaeger collector, OpenTelemetry collector, Redis, Polarismesh
Relationships & Interactions
• Runtime schedules CPU and IO tasks for Transport and RPC layers.
• Transport uses Runtime to send/receive bytes, then hands off to the codec manager.
• Codec manager invokes a protocol plugin to decode/encode messages.
• RPC layer calls the decoded message into a service handler or constructs a request via the service proxy.
• Admin and tool APIs are just special RPC services running on the same transport.
• Plugins register via factory or plugin manager in common modules.
Architectural Patterns
• Layered architecture (Runtime → Transport → RPC).
• Plugin/Factory pattern for codecs, serializers, compressors, naming, config, logging, metrics, tracing, telemetry.
• Reactor/M:N coroutine for concurrency.
• Service Proxy and Service Handler abstractions for decoupling.
Final Advice
• Special interactions (e.g., async‐io based on io-uring, fiber vs. thread models).
• Review the official architecture image in docs/images/arch_design.png for inspiration on layout and iconography.