Skip to content

Commit c236fd6

Browse files
Protocol Buffer TeamLogofile
Protocol Buffer Team
authored andcommitted
Project import generated by Copybara.
PiperOrigin-RevId: 708039275 Change-Id: I4e48375a5098096a0d69a3620e4d9a74b279735e
1 parent 41c8ea6 commit c236fd6

File tree

9 files changed

+70
-16
lines changed

9 files changed

+70
-16
lines changed

content/news/2024-12-18.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
+++
2+
title = "Changes announced December 18, 2024"
3+
linkTitle = "December 18, 2024"
4+
toc_hide = "true"
5+
description = "Changes announced for Protocol Buffers on December 18, 2024."
6+
type = "docs"
7+
+++
8+
9+
## Go Protobuf: The new Opaque API
10+
11+
Back in March 2020, we released the `google.golang.org/protobuf` module,
12+
[a major overhaul of the Go Protobuf API](https://go.dev/blog/protobuf-apiv2).
13+
This package introduced first-class
14+
[support for reflection](https://pkg.go.dev/google.golang.org/protobuf/reflect/protoreflect),
15+
a [`dynamicpb`](https://pkg.go.dev/google.golang.org/protobuf/types/dynamicpb)
16+
implementation and the
17+
[`protocmp`](https://pkg.go.dev/google.golang.org/protobuf/testing/protocmp)
18+
package for easier testing.
19+
20+
That release introduced a new protobuf module with a new API. Today, we are
21+
releasing an additional API for generated code, meaning the Go code in the
22+
`.pb.go` files created by the protocol compiler (`protoc`). The blog post at
23+
https://go.dev/blog/protobuf-opaque explains our motivation for creating a new
24+
API and shows you how to use it in your projects.
25+
26+
To be clear: We are not removing anything. We will continue to support the
27+
existing API for generated code, just like we still support the older protobuf
28+
module (by wrapping the `google.golang.org/protobuf` implementation). Go is
29+
[committed to backwards compatibility](https://go.dev/blog/compat) and this
30+
applies to Go Protobuf, too!

content/news/_index.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ New news topics will also be published to the
2020
The following news topics provide information in the reverse order in which it
2121
was released.
2222

23+
* [December 18, 2024](/news/2024-12-18) - Go Protobuf:
24+
The new Opaque API
2325
* [December 13, 2024](/news/2024-12-13) - Removing
2426
`MutableRepeatedFieldRef<T>::Reserve()` in v30
2527
* [December 4, 2024](/news/2024-12-04) - `DebugString`

content/programming-guides/style.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ application that gets an unexpected enum value will mark the field as unset in
116116
the proto instance. The field accessor will then return the default value, which
117117
for enum fields is the first enum value. For more information on the unspecified
118118
enum value, see
119-
[the Proto Best Practices page](/programming-guides/dos-donts#unspecified-enum).
119+
[the Proto Best Practices page](/best-practices/dos-donts#unspecified-enum).
120120

121121
## Services {#services}
122122

@@ -131,11 +131,11 @@ service FooService {
131131
```
132132

133133
For more service-related guidance, see
134-
[Create Unique Protos per Method](/programming-guides/api#unique-protos)
134+
[Create Unique Protos per Method](/best-practices/api#unique-protos)
135135
and
136136
[Don't Include Primitive Types in a Top-level Request or Response Proto](/programming-guides/api#dont-include-primitive-types)
137137
in the API Best Practices topic, and
138-
[Define Messages in Separate Files](/programming-guides/dos-donts.md#separate-files)
138+
[Define Messages in Separate Files](/best-practices/dos-donts.md#separate-files)
139139
in Proto Best Practices.
140140

141141
## Things to Avoid {#avoid}

content/reference/cpp/abseil.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
+++
2-
title = "Asbseil Support"
2+
title = "Abseil Support"
33
weight = 530
4-
linkTitle = "Asbseil Support"
4+
linkTitle = "Abseil Support"
55
description = "The C++ implementation of Protocol Buffers has an explicit dependency on Abseil."
66
type = "docs"
77
+++

content/reference/rust/rust-generated.md

+26-6
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ emitted for the owned message type (`Foo`). A subset of these functions with
124124
functions with either `&self` or `&mut self` will also be included on the
125125
`FooMut<'msg>`.
126126

127+
To create an owned message type from a View / Mut type call `to_owned()`, which
128+
creates a deep copy.
129+
127130
## Nested Types {#nested-types}
128131

129132
Given the message declaration:
@@ -324,6 +327,8 @@ enum Bar {
324327
The compiler generates a struct where each variant is an associated constant:
325328

326329
```rust
330+
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
331+
#[repr(transparent)]
327332
pub struct Bar(i32);
328333

329334
impl Bar {
@@ -366,6 +371,20 @@ enum Bar {
366371
}
367372
```
368373

374+
The compiler generates a struct where each variant is an associated constant:
375+
376+
```rust
377+
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
378+
#[repr(transparent)]
379+
pub struct Bar(i32);
380+
381+
impl Bar {
382+
pub const Unspecified: Bar = Bar(0);
383+
pub const Value: Bar = Bar(1);
384+
pub const OtherValue: Bar = Bar(2);
385+
}
386+
```
387+
369388
For these field definitions:
370389

371390
```proto
@@ -536,14 +555,15 @@ enum FooBar {
536555
The compiler will generate:
537556

538557
```rust
539-
#[derive(Clone, Copy, PartialEq, Eq)]
540-
pub struct Foo(i32);
558+
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
559+
#[repr(transparent)]
560+
pub struct FooBar(i32);
541561

542562
impl FooBar {
543-
pub const Unknown: Foo = Foo(0);
544-
pub const A: Foo = Foo(1);
545-
pub const FooB: Foo = Foo(5);
546-
pub const ValueC: Foo = Foo(1234);
563+
pub const Unknown: FooBar = FooBar(0);
564+
pub const A: FooBar = FooBar(1);
565+
pub const FooB: FooBar = FooBar(5);
566+
pub const ValueC: FooBar = FooBar(1234);
547567
}
548568
```
549569

content/programming-guides/api.md renamed to eng/doc/devguide/proto/best-practices/api.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<!-- go/markdown -->
2+
13
+++
24
title = "API Best Practices"
35
weight = 100

content/programming-guides/dos-donts.md renamed to eng/doc/devguide/proto/best-practices/dos-donts.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ their own file with no dependencies. Then it's easy for anyone to use those
159159
types without introducing the transitive dependencies in your other proto files.
160160

161161
For more on this topic, see
162-
[1-1-1 Rule](/programming-guides/1-1-1).
162+
[1-1-1 Rule](/best-practices/1-1-1).
163163

164164
<a id="dont-change-the-default-value-of-a-field"></a>
165165

@@ -259,4 +259,4 @@ problems.
259259

260260
This document lists only changes that are extremely likely to cause breakage.
261261
For higher-level guidance on how to craft proto APIs that grow gracefully see
262-
[API Best Practices](/programming-guides/api).
262+
[API Best Practices](/best-practices/api).

content/programming-guides/best-practices.md renamed to eng/doc/devguide/proto/best-practices/index.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ no_list = "true"
99
Best practices content for defining and using protos exists in the following
1010
topics:
1111

12-
* [Proto Best Practices](/programming-guides/dos-donts)
13-
* [API Best Practices](/programming-guides/api)
14-
* [1-1-1 Rule](/programming-guides/1-1-1)
12+
* [Proto Best Practices](/best-practices/dos-donts)
13+
* [API Best Practices](/best-practices/api)
14+
* [1-1-1 Rule](/best-practices/1-1-1)

0 commit comments

Comments
 (0)