Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Protobuf Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-protobuf-knowledge-patch)
---
name: protobuf-knowledge-patch
description: Protocol Buffers
version: "36.2"
license: MIT
metadata:
author: Nevaberry
---
# Protocol Buffers compatibility guidance
Load when changing protobuf schemas, generated bindings, runtimes, or build rules.
Use the topic references for migration details, examples, and source attribution.
## Reference index
| Reference | Topics |
| --- | --- |
| [Build and tooling](references/build-and-tooling.md) | CMake dependencies, Bazel flags and toolchains, Python rules, compiler output, distributions |
| [Compatibility and lifecycle](references/compatibility-and-lifecycle.md) | Compiler/runtime pairing, generated-code guarantees, platform minimums, maintenance dates |
| [C++](references/cpp.md) | String views, removed APIs, arenas, repeated fields, reflection, JSON, TextFormat |
| [Editions and schema](references/editions-and-schema.md) | Naming, visibility, imports, limits, descriptors, custom enum JSON strings |
| [Java, C#, and Objective-C](references/java-csharp-objective-c.md) | Generated APIs, validation, cross-runtime recursion limits, unknown fields, Kotlin/Native names |
| [PHP and Ruby](references/php-and-ruby.md) | Runtime class names, setters, presence, JSON validation, binary limits, JRuby |
| [Python and upb](references/python.md) | Dynamic classes, assignment checks, descriptors, NumPy, buffers, parsing, free-threaded execution |
| [Rust and Go](references/rust-and-go.md) | Crate exports, generated names, traits, mutable iteration, Go API and enum migration |
## Breaking changes and deprecations
### Runtime and generated-code pairing
Upgrade the runtime before regenerating bindings, even for patch releases:
the generator can use APIs added in the same release. The default policy lets
code generated by `V.x.y` run on runtimes from `V.x.y` through the end of major `V+1`.
Security fixes can require updating the runtime and regenerating together.
C++ and Rust require generated code and runtime from the exact same release,
including the patch version. Rebuild C++ dependents when changing runtime
versions; there is no ABI stability guarantee even across patch releases.
Align transitive dependencies on one runtime major per process.
Platform, language, and tool support can be dropped in minor or patch releases.
Check the supported versions for your build and deployment targets when upgrading.
### C++ ownership, debug output, and removed APIs
String-valued descriptor accessors, `MessageLite::GetTypeName()`, and
`UnknownField::length_delimited()` return `absl::string_view`.
Make an owned copy when the data needs to outlive its backing storage.
Remove `PROTOBUF_FUTURE_STRING_VIEW_RETURN_TYPE` from build definitions.
`Message::DebugString()`, `ShortDebugString()`, `Utf8DebugString()`,
`AbslStringify`, `proto2::ShortFormat`, and `proto2::Utf8Format` redact
`debug_redact` fields. Their per-process randomized prefix makes output invalid
as TextFormat input. Use `TextFormat` to serialize messages for later parsing.
| Removed API | Migration |
| --- | --- |
| `Arena::CreateMessage` | `Arena::Create` |
| `Arena::GetArena(value)` | `value->GetArena()` |
| `JsonOptions` | `JsonPrintOptions` |
| `RepeatedPtrField::ClearedCount()` | Migrate to arena allocation |
| `MutableRepeatedFieldRef<T>::Reserve()` | Drop reflection-based capacity reservations |
| `PROTOBUF_CONSTEXPR` | `constexpr` |
Clearing an arena-allocated oneof message clears its contents in debug builds
and poisons its storage under AddressSanitizer. A retained pointer can trigger
a use-after-free error after clearing. Debug builds also reject copying a source
into its descendant; make an independent copy before copying into a submessage.
`ExtractSubrange()` and `DeleteSubrange()` check ranges; `AddAlreadyReserved()`
and `AddNAlreadyReserved()` check capacity. Check ranges or indexes for
`UnsafeArenaExtractSubrange()`, `ReleaseLast()`, and `SwapElements()`;
call `ReleaseLast()` only on a nonempty field.
### Descriptor cardinality and presence
Replace C++ `FieldDescriptor::label()` with `is_repeated()` or `is_required()`;
replace `is_optional()` with `!is_required() && !is_repeated()`.
Use `has_presence()` for presence checks instead of `has_optional_keyword()`.
Use `FieldDescriptor::cpp_string_type()` to query the C++ string representation.
For Python's `FieldDescriptor.label`, use `is_repeated` or `is_required`.
For PHP's `FieldDescriptor::getLabel()`, use `isRepeated()` or `isRequired()`.
PHP removes `hasOptionalKeyword()`; use `hasPresence()` for presence.
In Editions, Java `getLabel()` reports singular fields as `LABEL_OPTIONAL`
and repeated fields as `LABEL_REPEATED`; `hasOptionalKeyword()` is always `false`.
### Python API migration
Use `message_factory.GetMessageClass(descriptor)` instead of `reflection.MakeClass`
and the old `GetPrototype` and `CreatePrototype` methods on `MessageFactory`
and `SymbolDatabase`. For `reflection.ParseMessage`, parse using the returned
class. Replace factory and symbol database `GetMessages` with
`message_factory.GetMessageClassesForFiles()`.
Scalar maps require both arguments to `setdefault`, as in
`msg.counts.setdefault("hits", 0)`; message-valued maps reject `setdefault()`.
Python and upb reject invalid numeric closed-enum assignments under Edition 2023.
The v34 announcement plans rejection of boolean assignments to enum and integer
fields: explicitly convert intentional boolean-to-integer assignments and use
valid enum values. Wrong-type `Timestamp` and `Duration` conversions change
from `AttributeError` to `TypeError` in v34.
Before updating to Python 7.34, remove `float_precision` from `json_format`
serializer calls and `float_format` and `double_format` from `text_format` calls.
Treat descriptor `GetOptions()` results as read-only; copy before editing.
Protobuf 36.0 includes a future mutation warning and an upb `TypeError` path
for immutable scalar options.
### Build configuration migration
CMake checks installed packages first and fetches pinned missing dependencies.
Per-dependency provider options such as `protobuf_ABSL_PROVIDER` were removed.
```sh
cmake -S . -B build-local -Dprotobuf_LOCAL_DEPENDENCIES_ONLY=ON
cmake -S . -B build-fetched -Dprotobuf_FORCE_FETCH_DEPENDENCIES=ON
```
The first requires local packages; the second always fetches pinned versions.
CMake omits tests by default; use `-Dprotobuf_BUILD_TESTS=ON` to build them.
For a v34 upgrade from `WORKSPACE`, migrate dependencies to `MODULE.bazel`:
Bazel 8 defaults to Bzlmod. To build `protoc` from source instead of using the
preferred prebuilt compiler, set `--@protobuf//bazel/flags:prefer_prebuilt_protoc=false`.
Enable `--incompatible_enable_proto_toolchain_resolution` for toolchain
resolution; it is on by default in Bazel 9. Use `register_toolchain()` in
`MODULE.bazel` or `WORKSPACE`, or `--extra_toolchains`.
Protobuf 35.1 restores reading only Starlark `--proto_toolchain_for*` flags;
if a build relied on native flags in 35.0, switch to their Starlark equivalents.
The build reference contains the exact labels and version-dependent `protocopt` paths.
Load public `py_proto_library` from `bazel/py_proto_library.bzl`.
`internal_py_proto_library` warns ahead of planned Q1 2027 breaking changes;
migrate its callers to the public rule.
### Java, Objective-C, PHP, and Rust migration
Standard generated Java code can use the new runtime without `sun.misc.Unsafe`;
Lite runtime paths still use it. Java removes experimental `FieldOrder`.
Resolve reported `OneofDescriptor` collisions before the planned Q1 2027 changes.
Objective-C replaces `GPBUnknownFieldSet` with ordered `GPBUnknownFields`.
Extract with `initFromMessage:` and apply with
`mergeUnknownFields:extensionRegistry:error:`; call `clearUnknownFields`
before merging when replacing unknown fields. Generated root classes can no
longer be instantiated; use the class method for the extension registry.
PHP setters declare parameter types and use PHP argument checks instead of
redundant `GPBUtil` checks. Both runtimes accept optional binary recursion limits
in `mergeFromString()` and `serializeToString()`. Pure-PHP `CodedInputStream`
removes `total_bytes_limit`; enforce application byte limits before parsing.
Rust `*_opt()` accessors return standard `Option`; replace `protobuf::Optional`.
Replace `ProxiedInMapValue` bounds with `MapValue`; `f32` and `f64` cannot
satisfy the map-key bound. `RepeatedMutIter` drops iterator trait implementations;
use its inherent `next()` and `next_back()`, replacing `.rev()` with a loop
calling `next_back()` for reverse traversal.
## Schema and generated API features
### Editions naming, visibility, and imports
Edition 2024 defaults C++ strings to `VIEW`; set
`features.(pb.cpp).string_type = STRING` to retain previous accessors.
It replaces Java `java_multiple_files` with `nest_in_file_class` and defaults
top-level types to separate files. Pin `java_outer_classname` if callers depend
on the previous outer class name.
Edition 2024 defaults visibility to `EXPORT_TOP_LEVEL`; `local` types still get
generated classes. Use `import option` after other imports for custom options;
message-valued option types remain unavailable for field declarations.
Bazel 8 or later supports `proto_library.option_deps` for these dependencies.
Edition 2026 is slated to default naming to `STYLE2026` and visibility to `STRICT`.
The naming rule forbids `descriptor` as a field name and, alongside `x`, forbids
`has_x`, `set_x`, `get_x`, `clear_x`, and `x_value`.
Under `STRICT`, use `export` for importable top-level types. The guide permits
exporting a nested enum in a wrapper message declaring `reserved 1 to max;`.
`PROTO_LIMITS2026` caps messages at 1,500 fields and 1,000 oneofs, oneofs at
1,200 fields, and enums at 1,700 values. `LEGACY_NO_EXPLICIT_LIMITS` is a
declaration-scoped migration override. `STYLE_LEGACY` can preserve individual
legacy identifiers; `LEGACY_BEST_EFFORT` permits ambiguous JSON mappings on
a message or enum, whose runtime behavior can still be unspecified.
### Repeated-field proxies and generated features
Import `cpp_features.proto` and set `features.(pb.cpp).repeated_type = PROXY`
for C++ proxy accessors. `LEGACY` is the Edition 2026 default and can override
individual fields. A shallow proxy copy refers to the same repeated field.
`RepeatedFieldOrProxy` accepts proxies or legacy repeated-field references.
The C++ reference lists omitted APIs and gives accessor examples.
Set `(pb.enumvalue.json).string` to customize an enum value's JSON string.
C# enum aliases can serialize using a later alias's custom name for the same
numeric value. Java `large_enum` supports enums beyond usual constant limits;
callers must replace enum `switch` statements on those values with comparisons.
Go defaults to `API_OPEN` in Edition 2023 and `API_OPAQUE` from Edition 2024.
Pin `API_OPEN` at file scope for callers using struct fields directly;
use per-message `API_HYBRID` to retain exported fields and add accessors.
### Runtime data access and parsing
Use `Arena::UniquePtr<T>` and `Arena::Ptr<T>` for objects that may live on an
arena; keep the arena alive while pointers to its objects are used.
Rust repeated messages support `push_default()` and mutable element traversal.
Python repeated scalars support NumPy bindings and compatible buffer objects;
the upb runtime supports free-threaded CPython.
Java `JsonFormat` offers opt-in strict parsing. Nested payloads now count toward
depth limits on additional paths: Java and C# JSON `Any`, Python JSON `Any`,
`Struct`, and `Value`, and Objective-C binary `MessageSet` items.
The language references retain the individual parsing changes and limits.