|
| 1 | +# Handle Protobuf - hbp |
| 2 | + |
| 3 | +go/hpb |
| 4 | + |
| 5 | +<!--* |
| 6 | +# Document freshness: For more information, see go/fresh-source. |
| 7 | +freshness: { owner: 'hongshin' reviewed: '2025-05-14' } |
| 8 | +*--> |
| 9 | + |
| 10 | +## What is hpb? |
| 11 | + |
| 12 | +hpb is a C++ Protobuf API that provides a familiar protobuf experience while |
| 13 | +hiding internal implementation details. This encapsulation allows for swapping |
| 14 | +out the backend without breaking user code. hpb wraps other protobuf |
| 15 | +implementations -- currently only upb is supported, but a proto2 C++ backend is |
| 16 | +in the early stages. |
| 17 | + |
| 18 | +hpb is designed to be a "free" wrapper, such that it adds no runtime overhead |
| 19 | +compared with using the underlying backend directly. The wrapping is all |
| 20 | +performed in header files that optimize away at compile time. |
| 21 | + |
| 22 | +hpb is the preferred solution for users who want to use upb protos in a C++ |
| 23 | +application. Unlike the upb C generated code, hpb provides a stable API and |
| 24 | +properly handles naming conflicts. hpb is also far more ergonomic than the upb |
| 25 | +generated code. |
| 26 | + |
| 27 | +## Why hpb? |
| 28 | + |
| 29 | +- As mentioned in go/upb, the upb C API is not stable, and not intended for |
| 30 | + use in applications. hpb fills this gap. |
| 31 | + - upbc gencode can change and break clients at any time. hpb is designed |
| 32 | + for user applications inside of g3 and has stronger guarantees of api |
| 33 | + stability |
| 34 | + - LSCs/cleanups are handled by the Protobuf team - less maintenance burden |
| 35 | +- Code will be more readable. Regular C++ method calls vs field accessors. No |
| 36 | + need to provide fully qualified names in terra hpb. |
| 37 | + - `my_project_MyMessage_set_x` vs `msg.set_x()` |
| 38 | +- [planned] Gives a transition path if your team wishes to move from proto2::cpp to upb |
| 39 | + via hpb(cpp) -> hpb(upb). All toggled statically with a BUILD flag |
| 40 | +- [planned] interop between hpb(upb) and hpb(cpp) |
| 41 | + |
| 42 | +## How can I get access? |
| 43 | + |
| 44 | +hpb is currently in special availability. If you think this would be a good |
| 45 | +fit for your team, please reach out to the Protobuf team. |
| 46 | + |
0 commit comments