{"owner":"apache","repo":"brpc","hasSkills":true,"hasMcp":false,"mcpConfig":null,"found":["AGENTS.md","CLAUDE.md"],"skills":{"AGENTS.md":"<!--\nSPDX-License-Identifier: Apache-2.0\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    https://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n-->\n\n# Repository Guidelines\n\n## Project Structure & Module Organization\n\nCore C++ code lives in `src/`: `src/brpc`, `src/bthread`,\n`src/butil`, `src/bvar`, `src/json2pb`, and `src/mcpack2pb`. Tests are in\n`test/` and mirror module names. Samples are in `example/`; utilities\nare in `tools/`. Documentation is under `docs/en` and `docs/cn`; packaging and\nbindings live in `package/`, `homebrew-formula/`, `python/`, and `java/`.\n\n## Build, Test, and Development Commands\n\n- `sh config_brpc.sh --headers=/usr/include --libs=/usr/lib && make`: configure and build with Make.\n- `cmake -B build && cmake --build build -j6`: configure and build with CMake.\n- `cmake -B build -DBUILD_UNIT_TESTS=ON && cmake --build build -j6 && cd build && ctest`: run CMake tests.\n- `cd test && make && sh run_tests.sh`: run the Make-based test suite.\n- `bazel build //:brpc` and `bazel test //test/...`: build or test with Bazel.\n- `cd example/echo_c++ && make && ./echo_server & ./echo_client`: smoke-test an example.\n\n## Coding Style & Naming Conventions\n\nFollow Google C++ style with 4-space indentation. Keep feature-specific code in\nthe relevant protocol or module, not broad files such as `server.cpp` or\n`channel.cpp`, unless the behavior is general. Use existing names:\n`*_unittest.cpp` or `*_unittest.cc`, module prefixes such as `brpc_`,\n`bthread_`, and `bvar_`, and `.proto` files beside related code.\n\n## Testing Guidelines\n\nNew behavior should include unit tests. Run the smallest relevant test first,\nthen the broader affected suite. Tests use Google Test and live in `test/`.\nSome integration tests require Redis or MySQL and may skip when absent.\n\n## Commit & Pull Request Guidelines\n\nRecent history uses short imperative subjects such as `Fix bazel compile error\non macOS`. Keep commits focused, explain behavioral impact when needed, and\nlink issues. Pull requests should describe the change, list tests run, note\nplatform or dependency assumptions, and pass GitHub Actions.\n\n## Security & Configuration Tips\n\nRead `SECURITY.md` before reporting vulnerabilities. Avoid committing\nbuild directories, local paths, credentials, or machine-specific configuration.\nPrefer flags such as `--with-glog`, `--with-thrift`, `--with-asan`,\nor the matching CMake/Bazel options.\n","CLAUDE.md":"# CLAUDE.md\n\nThis file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.\n\n## Project Overview\n\nApache bRPC is an industrial-grade C++ RPC framework supporting multiple protocols (baidu_std, HTTP/H2, gRPC, thrift, redis, memcached, RTMP, RDMA) on the same port. Used in high-performance systems: search, storage, ML, ads, recommendations. Current version: 1.17.0.\n\n## Build Commands\n\n### Make (primary)\n\n```bash\n# Generate config (required before first build)\n./config_brpc.sh --headers=/usr/include --libs=/usr/lib\n\n# Build library (produces libbrpc.a and libbrpc.so/dylib)\nmake -j$(nproc)\n\n# Build debug version (with UNIT_TEST flag, no NDEBUG)\nmake debug\n```\n\nConfig options: `--with-glog`, `--with-thrift`, `--with-rdma`, `--with-asan`, `--werror`\n\n### CMake\n\n```bash\nmkdir build && cd build\ncmake .. -DCMAKE_BUILD_TYPE=Release\nmake -j$(nproc)\n```\n\nKey CMake options: `-DWITH_GLOG=ON`, `-DWITH_THRIFT=ON`, `-DWITH_RDMA=ON`, `-DWITH_ASAN=ON`, `-DBUILD_UNIT_TESTS=ON`, `-DDOWNLOAD_GTEST=ON`\n\n### Bazel\n\n```bash\nbazel build -- //... -//example/...\n```\n\n## Running Tests\n\nTests use Google Test. Build and run with Make:\n\n```bash\ncd test\nmake -j$(nproc)\n./run_tests.sh          # runs all: test_butil, test_bvar, bthread_*unittest, brpc_*unittest\n```\n\nRun a single test binary:\n\n```bash\ncd test\n./<test_binary>                    # e.g. ./test_butil\n./<test_binary> --gtest_filter='TestSuite.TestName'   # single test case\n```\n\nWith CMake:\n\n```bash\ncmake .. -DBUILD_UNIT_TESTS=ON -DDOWNLOAD_GTEST=ON\nmake -j$(nproc) && ctest\n```\n\nASAN is used in CI: `ASAN_OPTIONS=\"detect_leaks=0:detect_stack_use_after_return=1\" ./<test_binary>`\n\n## Architecture\n\n### Core Libraries (under `src/`)\n\n- **brpc/** — The RPC framework. Three core abstractions:\n  - `Server` — listens on a port, dispatches requests to registered services. Supports multiple protocols on the same port via protocol detection.\n  - `Channel` — client-side stub for sending RPCs. Configured with naming service, load balancer, timeout, retry policies via `ChannelOptions`.\n  - `Controller` — per-RPC context carrying request metadata, error state, timeout, attachments. Extends `google::protobuf::RpcController`.\n  - `Socket` (`socket.h`) — low-level connection abstraction managing fd lifecycle, SSL, and write buffering. Uses `VersionedRefWithId` for safe concurrent access.\n\n- **bthread/** — M:N user-level threading (the concurrency foundation of brpc)\n  - `TaskControl` manages a pool of worker pthreads, each running a `TaskGroup`\n  - `TaskGroup` owns a local run queue + work-stealing queue (`work_stealing_queue.h`, lock-free CAS-based)\n  - `bthread_start_urgent()` runs task immediately on current worker; `bthread_start_background()` enqueues for later scheduling\n  - Most brpc callbacks execute in bthreads, not pthreads\n\n- **butil/** — Base utility library (originally forked from Chromium)\n  - `IOBuf` (`iobuf.h`) — zero-copy buffer using reference-counted blocks with SmallView (2 inline BlockRefs) / BigView (heap) optimization. Core data structure for network I/O.\n  - Also: FlatMap, logging, string utils, time, files, containers\n  - `third_party/` — Bundled snappy, murmurhash3, symbolize, etc.\n\n- **bvar/** — Multi-dimensional statistics variables\n  - Thread-local aggregation via `AgentCombiner` for lock-free counters\n  - Types: `Adder`, `Recorder`, `LatencyRecorder`, `PassiveStatus`\n  - Composable windows: `PerSecond<Adder<>>`, `Window<>`\n  - Auto-exposed via builtin `/vars` endpoint\n\n- **json2pb/** — Bidirectional JSON <-> Protobuf conversion\n\n- **mcpack2pb/** — MCPack format <-> Protobuf conversion (Baidu legacy)\n\n### Key Design Patterns\n\n- **Protocol plugins** (`src/brpc/policy/`): Each protocol implements the `Protocol` struct (function pointers for Parse/Serialize/Pack/Process/Verify in `protocol.h`), registered via `RegisterProtocol()`. 18 protocols implemented. Adding a new protocol does not touch core files — see `docs/en/new_protocol.md`.\n- **Naming services / Load balancers**: Pluggable via `NamingService` and `LoadBalancer` interfaces (DNS, ZK, etcd, round-robin, consistent hashing, locality-aware, etc.)\n- **Builtin services** (`src/brpc/builtin/`): Every brpc server auto-exposes debug endpoints — `/status`, `/vars`, `/flags`, `/rpcz`, `/hotspots` (cpu/heap/contention profilers).\n- **Error model**: Functions return 0/-1 with errno; `Controller::SetFailed()` for RPC-level errors; custom error codes defined in `errno.proto`.\n- **Memory patterns**: `ResourcePool` / `ObjectPool` for socket and bthread recycling; `butil::intrusive_ptr` for hot-path reference counting; IOBuf for zero-copy I/O.\n\n## Code Style\n\n- Google C++ Style Guide with **4-space indentation**\n- Protocol-specific code goes in `src/brpc/policy/`, not in core files like `server.cpp` or `channel.cpp`\n- General modifications should not be hidden inside protocol-specific files\n- All changes require unit tests\n- CI runs on GitHub Actions (Linux gcc/clang, macOS) — must pass before merge\n- Uses C++14 minimum; some C++17 features with compiler guards. Legacy patterns (`DISALLOW_COPY_AND_ASSIGN` macro) still prevalent.\n\n## Dependencies\n\nRequired: protobuf (3.x–21.x), gflags, leveldb, openssl. Optional: glog, thrift, gperftools (tcmalloc/profiler), gtest (for tests), libunwind, abseil-cpp, BoringSSL (alternative to openssl).\n\n## Examples\n\n30+ examples in `example/` covering echo, HTTP, gRPC, streaming, redis, memcache, thrift, RDMA, coroutine, etc. Each has its own Makefile/CMakeLists.txt/BUILD.\n"},"files":{"AGENTS.md":"<!--\nSPDX-License-Identifier: Apache-2.0\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    https://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n-->\n\n# Repository Guidelines\n\n## Project Structure & Module Organization\n\nCore C++ code lives in `src/`: `src/brpc`, `src/bthread`,\n`src/butil`, `src/bvar`, `src/json2pb`, and `src/mcpack2pb`. Tests are in\n`test/` and mirror module names. Samples are in `example/`; utilities\nare in `tools/`. Documentation is under `docs/en` and `docs/cn`; packaging and\nbindings live in `package/`, `homebrew-formula/`, `python/`, and `java/`.\n\n## Build, Test, and Development Commands\n\n- `sh config_brpc.sh --headers=/usr/include --libs=/usr/lib && make`: configure and build with Make.\n- `cmake -B build && cmake --build build -j6`: configure and build with CMake.\n- `cmake -B build -DBUILD_UNIT_TESTS=ON && cmake --build build -j6 && cd build && ctest`: run CMake tests.\n- `cd test && make && sh run_tests.sh`: run the Make-based test suite.\n- `bazel build //:brpc` and `bazel test //test/...`: build or test with Bazel.\n- `cd example/echo_c++ && make && ./echo_server & ./echo_client`: smoke-test an example.\n\n## Coding Style & Naming Conventions\n\nFollow Google C++ style with 4-space indentation. Keep feature-specific code in\nthe relevant protocol or module, not broad files such as `server.cpp` or\n`channel.cpp`, unless the behavior is general. Use existing names:\n`*_unittest.cpp` or `*_unittest.cc`, module prefixes such as `brpc_`,\n`bthread_`, and `bvar_`, and `.proto` files beside related code.\n\n## Testing Guidelines\n\nNew behavior should include unit tests. Run the smallest relevant test first,\nthen the broader affected suite. Tests use Google Test and live in `test/`.\nSome integration tests require Redis or MySQL and may skip when absent.\n\n## Commit & Pull Request Guidelines\n\nRecent history uses short imperative subjects such as `Fix bazel compile error\non macOS`. Keep commits focused, explain behavioral impact when needed, and\nlink issues. Pull requests should describe the change, list tests run, note\nplatform or dependency assumptions, and pass GitHub Actions.\n\n## Security & Configuration Tips\n\nRead `SECURITY.md` before reporting vulnerabilities. Avoid committing\nbuild directories, local paths, credentials, or machine-specific configuration.\nPrefer flags such as `--with-glog`, `--with-thrift`, `--with-asan`,\nor the matching CMake/Bazel options.\n","CLAUDE.md":"# CLAUDE.md\n\nThis file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.\n\n## Project Overview\n\nApache bRPC is an industrial-grade C++ RPC framework supporting multiple protocols (baidu_std, HTTP/H2, gRPC, thrift, redis, memcached, RTMP, RDMA) on the same port. Used in high-performance systems: search, storage, ML, ads, recommendations. Current version: 1.17.0.\n\n## Build Commands\n\n### Make (primary)\n\n```bash\n# Generate config (required before first build)\n./config_brpc.sh --headers=/usr/include --libs=/usr/lib\n\n# Build library (produces libbrpc.a and libbrpc.so/dylib)\nmake -j$(nproc)\n\n# Build debug version (with UNIT_TEST flag, no NDEBUG)\nmake debug\n```\n\nConfig options: `--with-glog`, `--with-thrift`, `--with-rdma`, `--with-asan`, `--werror`\n\n### CMake\n\n```bash\nmkdir build && cd build\ncmake .. -DCMAKE_BUILD_TYPE=Release\nmake -j$(nproc)\n```\n\nKey CMake options: `-DWITH_GLOG=ON`, `-DWITH_THRIFT=ON`, `-DWITH_RDMA=ON`, `-DWITH_ASAN=ON`, `-DBUILD_UNIT_TESTS=ON`, `-DDOWNLOAD_GTEST=ON`\n\n### Bazel\n\n```bash\nbazel build -- //... -//example/...\n```\n\n## Running Tests\n\nTests use Google Test. Build and run with Make:\n\n```bash\ncd test\nmake -j$(nproc)\n./run_tests.sh          # runs all: test_butil, test_bvar, bthread_*unittest, brpc_*unittest\n```\n\nRun a single test binary:\n\n```bash\ncd test\n./<test_binary>                    # e.g. ./test_butil\n./<test_binary> --gtest_filter='TestSuite.TestName'   # single test case\n```\n\nWith CMake:\n\n```bash\ncmake .. -DBUILD_UNIT_TESTS=ON -DDOWNLOAD_GTEST=ON\nmake -j$(nproc) && ctest\n```\n\nASAN is used in CI: `ASAN_OPTIONS=\"detect_leaks=0:detect_stack_use_after_return=1\" ./<test_binary>`\n\n## Architecture\n\n### Core Libraries (under `src/`)\n\n- **brpc/** — The RPC framework. Three core abstractions:\n  - `Server` — listens on a port, dispatches requests to registered services. Supports multiple protocols on the same port via protocol detection.\n  - `Channel` — client-side stub for sending RPCs. Configured with naming service, load balancer, timeout, retry policies via `ChannelOptions`.\n  - `Controller` — per-RPC context carrying request metadata, error state, timeout, attachments. Extends `google::protobuf::RpcController`.\n  - `Socket` (`socket.h`) — low-level connection abstraction managing fd lifecycle, SSL, and write buffering. Uses `VersionedRefWithId` for safe concurrent access.\n\n- **bthread/** — M:N user-level threading (the concurrency foundation of brpc)\n  - `TaskControl` manages a pool of worker pthreads, each running a `TaskGroup`\n  - `TaskGroup` owns a local run queue + work-stealing queue (`work_stealing_queue.h`, lock-free CAS-based)\n  - `bthread_start_urgent()` runs task immediately on current worker; `bthread_start_background()` enqueues for later scheduling\n  - Most brpc callbacks execute in bthreads, not pthreads\n\n- **butil/** — Base utility library (originally forked from Chromium)\n  - `IOBuf` (`iobuf.h`) — zero-copy buffer using reference-counted blocks with SmallView (2 inline BlockRefs) / BigView (heap) optimization. Core data structure for network I/O.\n  - Also: FlatMap, logging, string utils, time, files, containers\n  - `third_party/` — Bundled snappy, murmurhash3, symbolize, etc.\n\n- **bvar/** — Multi-dimensional statistics variables\n  - Thread-local aggregation via `AgentCombiner` for lock-free counters\n  - Types: `Adder`, `Recorder`, `LatencyRecorder`, `PassiveStatus`\n  - Composable windows: `PerSecond<Adder<>>`, `Window<>`\n  - Auto-exposed via builtin `/vars` endpoint\n\n- **json2pb/** — Bidirectional JSON <-> Protobuf conversion\n\n- **mcpack2pb/** — MCPack format <-> Protobuf conversion (Baidu legacy)\n\n### Key Design Patterns\n\n- **Protocol plugins** (`src/brpc/policy/`): Each protocol implements the `Protocol` struct (function pointers for Parse/Serialize/Pack/Process/Verify in `protocol.h`), registered via `RegisterProtocol()`. 18 protocols implemented. Adding a new protocol does not touch core files — see `docs/en/new_protocol.md`.\n- **Naming services / Load balancers**: Pluggable via `NamingService` and `LoadBalancer` interfaces (DNS, ZK, etcd, round-robin, consistent hashing, locality-aware, etc.)\n- **Builtin services** (`src/brpc/builtin/`): Every brpc server auto-exposes debug endpoints — `/status`, `/vars`, `/flags`, `/rpcz`, `/hotspots` (cpu/heap/contention profilers).\n- **Error model**: Functions return 0/-1 with errno; `Controller::SetFailed()` for RPC-level errors; custom error codes defined in `errno.proto`.\n- **Memory patterns**: `ResourcePool` / `ObjectPool` for socket and bthread recycling; `butil::intrusive_ptr` for hot-path reference counting; IOBuf for zero-copy I/O.\n\n## Code Style\n\n- Google C++ Style Guide with **4-space indentation**\n- Protocol-specific code goes in `src/brpc/policy/`, not in core files like `server.cpp` or `channel.cpp`\n- General modifications should not be hidden inside protocol-specific files\n- All changes require unit tests\n- CI runs on GitHub Actions (Linux gcc/clang, macOS) — must pass before merge\n- Uses C++14 minimum; some C++17 features with compiler guards. Legacy patterns (`DISALLOW_COPY_AND_ASSIGN` macro) still prevalent.\n\n## Dependencies\n\nRequired: protobuf (3.x–21.x), gflags, leveldb, openssl. Optional: glog, thrift, gperftools (tcmalloc/profiler), gtest (for tests), libunwind, abseil-cpp, BoringSSL (alternative to openssl).\n\n## Examples\n\n30+ examples in `example/` covering echo, HTTP, gRPC, streaming, redis, memcache, thrift, RDMA, coroutine, etc. Each has its own Makefile/CMakeLists.txt/BUILD.\n"},"items":[{"name":"AGENTS.md","path":"AGENTS.md","title":"AGENTS.md","content":"<!--\nSPDX-License-Identifier: Apache-2.0\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    https://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n-->\n\n# Repository Guidelines\n\n## Project Structure & Module Organization\n\nCore C++ code lives in `src/`: `src/brpc`, `src/bthread`,\n`src/butil`, `src/bvar`, `src/json2pb`, and `src/mcpack2pb`. Tests are in\n`test/` and mirror module names. Samples are in `example/`; utilities\nare in `tools/`. Documentation is under `docs/en` and `docs/cn`; packaging and\nbindings live in `package/`, `homebrew-formula/`, `python/`, and `java/`.\n\n## Build, Test, and Development Commands\n\n- `sh config_brpc.sh --headers=/usr/include --libs=/usr/lib && make`: configure and build with Make.\n- `cmake -B build && cmake --build build -j6`: configure and build with CMake.\n- `cmake -B build -DBUILD_UNIT_TESTS=ON && cmake --build build -j6 && cd build && ctest`: run CMake tests.\n- `cd test && make && sh run_tests.sh`: run the Make-based test suite.\n- `bazel build //:brpc` and `bazel test //test/...`: build or test with Bazel.\n- `cd example/echo_c++ && make && ./echo_server & ./echo_client`: smoke-test an example.\n\n## Coding Style & Naming Conventions\n\nFollow Google C++ style with 4-space indentation. Keep feature-specific code in\nthe relevant protocol or module, not broad files such as `server.cpp` or\n`channel.cpp`, unless the behavior is general. Use existing names:\n`*_unittest.cpp` or `*_unittest.cc`, module prefixes such as `brpc_`,\n`bthread_`, and `bvar_`, and `.proto` files beside related code.\n\n## Testing Guidelines\n\nNew behavior should include unit tests. Run the smallest relevant test first,\nthen the broader affected suite. Tests use Google Test and live in `test/`.\nSome integration tests require Redis or MySQL and may skip when absent.\n\n## Commit & Pull Request Guidelines\n\nRecent history uses short imperative subjects such as `Fix bazel compile error\non macOS`. Keep commits focused, explain behavioral impact when needed, and\nlink issues. Pull requests should describe the change, list tests run, note\nplatform or dependency assumptions, and pass GitHub Actions.\n\n## Security & Configuration Tips\n\nRead `SECURITY.md` before reporting vulnerabilities. Avoid committing\nbuild directories, local paths, credentials, or machine-specific configuration.\nPrefer flags such as `--with-glog`, `--with-thrift`, `--with-asan`,\nor the matching CMake/Bazel options.\n","category":"root","tokens":708},{"name":"CLAUDE.md","path":"CLAUDE.md","title":"CLAUDE.md","content":"# CLAUDE.md\n\nThis file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.\n\n## Project Overview\n\nApache bRPC is an industrial-grade C++ RPC framework supporting multiple protocols (baidu_std, HTTP/H2, gRPC, thrift, redis, memcached, RTMP, RDMA) on the same port. Used in high-performance systems: search, storage, ML, ads, recommendations. Current version: 1.17.0.\n\n## Build Commands\n\n### Make (primary)\n\n```bash\n# Generate config (required before first build)\n./config_brpc.sh --headers=/usr/include --libs=/usr/lib\n\n# Build library (produces libbrpc.a and libbrpc.so/dylib)\nmake -j$(nproc)\n\n# Build debug version (with UNIT_TEST flag, no NDEBUG)\nmake debug\n```\n\nConfig options: `--with-glog`, `--with-thrift`, `--with-rdma`, `--with-asan`, `--werror`\n\n### CMake\n\n```bash\nmkdir build && cd build\ncmake .. -DCMAKE_BUILD_TYPE=Release\nmake -j$(nproc)\n```\n\nKey CMake options: `-DWITH_GLOG=ON`, `-DWITH_THRIFT=ON`, `-DWITH_RDMA=ON`, `-DWITH_ASAN=ON`, `-DBUILD_UNIT_TESTS=ON`, `-DDOWNLOAD_GTEST=ON`\n\n### Bazel\n\n```bash\nbazel build -- //... -//example/...\n```\n\n## Running Tests\n\nTests use Google Test. Build and run with Make:\n\n```bash\ncd test\nmake -j$(nproc)\n./run_tests.sh          # runs all: test_butil, test_bvar, bthread_*unittest, brpc_*unittest\n```\n\nRun a single test binary:\n\n```bash\ncd test\n./<test_binary>                    # e.g. ./test_butil\n./<test_binary> --gtest_filter='TestSuite.TestName'   # single test case\n```\n\nWith CMake:\n\n```bash\ncmake .. -DBUILD_UNIT_TESTS=ON -DDOWNLOAD_GTEST=ON\nmake -j$(nproc) && ctest\n```\n\nASAN is used in CI: `ASAN_OPTIONS=\"detect_leaks=0:detect_stack_use_after_return=1\" ./<test_binary>`\n\n## Architecture\n\n### Core Libraries (under `src/`)\n\n- **brpc/** — The RPC framework. Three core abstractions:\n  - `Server` — listens on a port, dispatches requests to registered services. Supports multiple protocols on the same port via protocol detection.\n  - `Channel` — client-side stub for sending RPCs. Configured with naming service, load balancer, timeout, retry policies via `ChannelOptions`.\n  - `Controller` — per-RPC context carrying request metadata, error state, timeout, attachments. Extends `google::protobuf::RpcController`.\n  - `Socket` (`socket.h`) — low-level connection abstraction managing fd lifecycle, SSL, and write buffering. Uses `VersionedRefWithId` for safe concurrent access.\n\n- **bthread/** — M:N user-level threading (the concurrency foundation of brpc)\n  - `TaskControl` manages a pool of worker pthreads, each running a `TaskGroup`\n  - `TaskGroup` owns a local run queue + work-stealing queue (`work_stealing_queue.h`, lock-free CAS-based)\n  - `bthread_start_urgent()` runs task immediately on current worker; `bthread_start_background()` enqueues for later scheduling\n  - Most brpc callbacks execute in bthreads, not pthreads\n\n- **butil/** — Base utility library (originally forked from Chromium)\n  - `IOBuf` (`iobuf.h`) — zero-copy buffer using reference-counted blocks with SmallView (2 inline BlockRefs) / BigView (heap) optimization. Core data structure for network I/O.\n  - Also: FlatMap, logging, string utils, time, files, containers\n  - `third_party/` — Bundled snappy, murmurhash3, symbolize, etc.\n\n- **bvar/** — Multi-dimensional statistics variables\n  - Thread-local aggregation via `AgentCombiner` for lock-free counters\n  - Types: `Adder`, `Recorder`, `LatencyRecorder`, `PassiveStatus`\n  - Composable windows: `PerSecond<Adder<>>`, `Window<>`\n  - Auto-exposed via builtin `/vars` endpoint\n\n- **json2pb/** — Bidirectional JSON <-> Protobuf conversion\n\n- **mcpack2pb/** — MCPack format <-> Protobuf conversion (Baidu legacy)\n\n### Key Design Patterns\n\n- **Protocol plugins** (`src/brpc/policy/`): Each protocol implements the `Protocol` struct (function pointers for Parse/Serialize/Pack/Process/Verify in `protocol.h`), registered via `RegisterProtocol()`. 18 protocols implemented. Adding a new protocol does not touch core files — see `docs/en/new_protocol.md`.\n- **Naming services / Load balancers**: Pluggable via `NamingService` and `LoadBalancer` interfaces (DNS, ZK, etcd, round-robin, consistent hashing, locality-aware, etc.)\n- **Builtin services** (`src/brpc/builtin/`): Every brpc server auto-exposes debug endpoints — `/status`, `/vars`, `/flags`, `/rpcz`, `/hotspots` (cpu/heap/contention profilers).\n- **Error model**: Functions return 0/-1 with errno; `Controller::SetFailed()` for RPC-level errors; custom error codes defined in `errno.proto`.\n- **Memory patterns**: `ResourcePool` / `ObjectPool` for socket and bthread recycling; `butil::intrusive_ptr` for hot-path reference counting; IOBuf for zero-copy I/O.\n\n## Code Style\n\n- Google C++ Style Guide with **4-space indentation**\n- Protocol-specific code goes in `src/brpc/policy/`, not in core files like `server.cpp` or `channel.cpp`\n- General modifications should not be hidden inside protocol-specific files\n- All changes require unit tests\n- CI runs on GitHub Actions (Linux gcc/clang, macOS) — must pass before merge\n- Uses C++14 minimum; some C++17 features with compiler guards. Legacy patterns (`DISALLOW_COPY_AND_ASSIGN` macro) still prevalent.\n\n## Dependencies\n\nRequired: protobuf (3.x–21.x), gflags, leveldb, openssl. Optional: glog, thrift, gperftools (tcmalloc/profiler), gtest (for tests), libunwind, abseil-cpp, BoringSSL (alternative to openssl).\n\n## Examples\n\n30+ examples in `example/` covering echo, HTTP, gRPC, streaming, redis, memcache, thrift, RDMA, coroutine, etc. Each has its own Makefile/CMakeLists.txt/BUILD.\n","category":"root","tokens":1381}]}