Skip to content

Commit c8f5bcd

Browse files
Protocol Buffer TeamLogofile
authored andcommitted
This set of changes includes the following:
* Updates to enum values in the tutorials. This maps to https://github.com/protocolbuffers/protocolbuffers.github.io/pull/87/files * A news entry for upcoming breaking changes in Python. * Removing unnecessary weight metadata from a news entry. * Adding information about how `OuterClass` is added to Java filenames when using the v1 API. PiperOrigin-RevId: 558240789 Change-Id: Ic48d7e54a4b78fd649a477796939d10b357176e4
1 parent ab3e0ed commit c8f5bcd

File tree

10 files changed

+56
-39
lines changed

10 files changed

+56
-39
lines changed

content/getting-started/darttutorial.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,13 @@ Person promptForAddress() {
251251
String type = stdin.readLineSync();
252252
switch (type) {
253253
case 'mobile':
254-
phoneNumber.type = Person_PhoneType.MOBILE;
254+
phoneNumber.type = Person_PhoneType.PHONE_TYPE_MOBILE;
255255
break;
256256
case 'home':
257-
phoneNumber.type = Person_PhoneType.HOME;
257+
phoneNumber.type = Person_PhoneType.PHONE_TYPE_HOME;
258258
break;
259259
case 'work':
260-
phoneNumber.type = Person_PhoneType.WORK;
260+
phoneNumber.type = Person_PhoneType.PHONE_TYPE_WORK;
261261
break;
262262
default:
263263
print('Unknown phone type. Using default.');
@@ -312,13 +312,13 @@ void printAddressBook(AddressBook addressBook) {
312312
313313
for (Person_PhoneNumber phoneNumber in person.phones) {
314314
switch (phoneNumber.type) {
315-
case Person_PhoneType.MOBILE:
315+
case Person_PhoneType.PHONE_TYPE_MOBILE:
316316
print(' Mobile phone #: ');
317317
break;
318-
case Person_PhoneType.HOME:
318+
case Person_PhoneType.PHONE_TYPE_HOME:
319319
print(' Home phone #: ');
320320
break;
321-
case Person_PhoneType.WORK:
321+
case Person_PhoneType.PHONE_TYPE_WORK:
322322
print(' Work phone #: ');
323323
break;
324324
default:

content/getting-started/gotutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ p := pb.Person{
232232
Name: "John Doe",
233233
234234
Phones: []*pb.Person_PhoneNumber{
235-
{Number: "555-4321", Type: pb.Person_HOME},
235+
{Number: "555-4321", Type: pb.Person_PHONE_TYPE_HOME},
236236
},
237237
}
238238
```

content/getting-started/javatutorial.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ message Person {
100100
101101
message PhoneNumber {
102102
optional string number = 1;
103-
optional PhoneType type = 2 [default = HOME];
103+
optional PhoneType type = 2 [default = PHONE_TYPE_HOME];
104104
}
105105
106106
repeated PhoneNumber phones = 4;
@@ -350,7 +350,7 @@ Person john =
350350
.addPhones(
351351
Person.PhoneNumber.newBuilder()
352352
.setNumber("555-4321")
353-
.setType(Person.PhoneType.HOME))
353+
.setType(Person.PhoneType.PHONE_TYPE_HOME))
354354
.build();
355355
```
356356
@@ -460,11 +460,11 @@ class AddPerson {
460460
stdout.print("Is this a mobile, home, or work phone? ");
461461
String type = stdin.readLine();
462462
if (type.equals("mobile")) {
463-
phoneNumber.setType(Person.PhoneType.MOBILE);
463+
phoneNumber.setType(Person.PhoneType.PHONE_TYPE_MOBILE);
464464
} else if (type.equals("home")) {
465-
phoneNumber.setType(Person.PhoneType.HOME);
465+
phoneNumber.setType(Person.PhoneType.PHONE_TYPE_HOME);
466466
} else if (type.equals("work")) {
467-
phoneNumber.setType(Person.PhoneType.WORK);
467+
phoneNumber.setType(Person.PhoneType.PHONE_TYPE_WORK);
468468
} else {
469469
stdout.println("Unknown phone type. Using default.");
470470
}
@@ -531,13 +531,13 @@ class ListPeople {
531531
532532
for (Person.PhoneNumber phoneNumber : person.getPhonesList()) {
533533
switch (phoneNumber.getType()) {
534-
case MOBILE:
534+
case PHONE_TYPE_MOBILE:
535535
System.out.print(" Mobile phone #: ");
536536
break;
537-
case HOME:
537+
case PHONE_TYPE_HOME:
538538
System.out.print(" Home phone #: ");
539539
break;
540-
case WORK:
540+
case PHONE_TYPE_WORK:
541541
System.out.print(" Work phone #: ");
542542
break;
543543
}

content/getting-started/kotlintutorial.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,12 @@ fun promptPerson(): Person = person {
262262
263263
print("Is this a mobile, home, or work phone? ")
264264
val type = when (readLine()) {
265-
"mobile" -> Person.PhoneType.MOBILE
266-
"home" -> Person.PhoneType.HOME
267-
"work" -> Person.PhoneType.WORK
265+
"mobile" -> Person.PhoneType.PHONE_TYPE_MOBILE
266+
"home" -> Person.PhoneType.PHONE_TYPE_HOME
267+
"work" -> Person.PhoneType.PHONE_TYPE_WORK
268268
else -> {
269269
println("Unknown phone type. Using home.")
270-
Person.PhoneType.HOME
270+
Person.PhoneType.PHONE_TYPE_HOME
271271
}
272272
}
273273
phones += phoneNumber {
@@ -319,9 +319,9 @@ fun print(addressBook: AddressBook) {
319319
}
320320
for (phoneNumber in person.phonesList) {
321321
val modifier = when (phoneNumber.type) {
322-
Person.PhoneType.MOBILE -> "Mobile"
323-
Person.PhoneType.HOME -> "Home"
324-
Person.PhoneType.WORK -> "Work"
322+
Person.PhoneType.PHONE_TYPE_MOBILE -> "Mobile"
323+
Person.PhoneType.PHONE_TYPE_HOME -> "Home"
324+
Person.PhoneType.PHONE_TYPE_WORK -> "Work"
325325
else -> "Unknown"
326326
}
327327
println(" $modifier phone #: ${phoneNumber.number}")

content/getting-started/pythontutorial.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ message Person {
9494
9595
message PhoneNumber {
9696
optional string number = 1;
97-
optional PhoneType type = 2 [default = HOME];
97+
optional PhoneType type = 2 [default = PHONE_TYPE_HOME];
9898
}
9999
100100
repeated PhoneNumber phones = 4;
@@ -125,7 +125,7 @@ even define message types nested inside other messages -- as you can see, the
125125
`PhoneNumber` type is defined inside `Person`. You can also define `enum` types
126126
if you want one of your fields to have one of a predefined list of values --
127127
here you want to specify that a phone number can be one of the following phone
128-
types: `MOBILE`, `HOME`, or `WORK`.
128+
types: `PHONE_TYPE_MOBILE`, `PHONE_TYPE_HOME`, or `PHONE_TYPE_WORK`.
129129

130130
The " = 1", " = 2" markers on each element identify the unique "tag" that field
131131
uses in the binary encoding. Tag numbers 1-15 require one less byte to encode
@@ -240,7 +240,7 @@ person.name = "John Doe"
240240
person.email = "[email protected]"
241241
phone = person.phones.add()
242242
phone.number = "555-4321"
243-
phone.type = addressbook_pb2.Person.HOME
243+
phone.type = addressbook_pb2.Person.PHONE_TYPE_HOME
244244
```
245245

246246
Note that these assignments are not just adding arbitrary new fields to a
@@ -262,7 +262,7 @@ any particular field definition, see the
262262
263263
Enums are expanded by the metaclass into a set of symbolic constants with
264264
integer values. So, for example, the constant
265-
`addressbook_pb2.Person.PhoneType.WORK` has the value 2.
265+
`addressbook_pb2.Person.PhoneType.PHONE_TYPE_WORK` has the value 2.
266266
267267
### Standard Message Methods {#standard-message-methods}
268268
@@ -348,11 +348,11 @@ def PromptForAddress(person):
348348
349349
phone_type = input("Is this a mobile, home, or work phone? ")
350350
if phone_type == "mobile":
351-
phone_number.type = addressbook_pb2.Person.PhoneType.MOBILE
351+
phone_number.type = addressbook_pb2.Person.PhoneType.PHONE_TYPE_MOBILE
352352
elif phone_type == "home":
353-
phone_number.type = addressbook_pb2.Person.PhoneType.HOME
353+
phone_number.type = addressbook_pb2.Person.PhoneType.PHONE_TYPE_HOME
354354
elif phone_type == "work":
355-
phone_number.type = addressbook_pb2.Person.PhoneType.WORK
355+
phone_number.type = addressbook_pb2.Person.PhoneType.PHONE_TYPE_WORK
356356
else:
357357
print("Unknown phone type; leaving as default value.")
358358
@@ -401,11 +401,11 @@ def ListPeople(address_book):
401401
print(" E-mail address:", person.email)
402402
403403
for phone_number in person.phones:
404-
if phone_number.type == addressbook_pb2.Person.PhoneType.MOBILE:
404+
if phone_number.type == addressbook_pb2.Person.PhoneType.PHONE_TYPE_MOBILE:
405405
print(" Mobile phone #: ", end="")
406-
elif phone_number.type == addressbook_pb2.Person.PhoneType.HOME:
406+
elif phone_number.type == addressbook_pb2.Person.PhoneType.PHONE_TYPE_HOME:
407407
print(" Home phone #: ", end="")
408-
elif phone_number.type == addressbook_pb2.Person.PhoneType.WORK:
408+
elif phone_number.type == addressbook_pb2.Person.PhoneType.PHONE_TYPE_WORK:
409409
print(" Work phone #: ", end="")
410410
print(phone_number.number)
411411

content/news/2023-08-09.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
+++
22
title = "Changes Announced on August 9, 2023"
3-
weight = 21
43
linkTitle = "August 9, 2023"
54
toc_hide = "true"
65
description = "Changes announced for Protocol Buffers on August 9, 2023."

content/news/2023-08-15.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
+++
2+
title = "Changes Announced on August 15, 2023"
3+
linkTitle = "August 15, 2023"
4+
toc_hide = "true"
5+
description = "Changes announced for Protocol Buffers on August 15, 2023."
6+
type = "docs"
7+
+++
8+
9+
## Python Breaking Change
10+
11+
In v25
12+
[`message.UnknownFields()`](https://googleapis.dev/python/protobuf/latest/google/protobuf/message.html#google.protobuf.message.Message.UnknownFields)
13+
will be deprecated in pure Python and C++ extensions. It will be removed in v26.
14+
Use the new
15+
[`UnknownFieldSet(message)`](https://googleapis.dev/python/protobuf/latest/google/protobuf/unknown_fields.html)
16+
support in `unknown_fields.py` as a replacement.

content/news/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ type = "docs"
88
News topics provide information about past events and changes with Protocol
99
Buffers, and plans for upcoming changes.
1010

11+
* [August 15, 2023](/news/2023-08-15) - Breaking Python
12+
change with the replacement of `message.UnknownFields()``
1113
* [August 9, 2023](/news/2023-08-09) - Support policy
1214
for .NET
1315
* [July 17, 2023](/news/2023-07-17) - Dropping support

content/reference/java/java-generated.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ enum, or message (including nested types) in the file with the same name,
6363
`java_outer_classname` is also set to the string `FooService`, then the
6464
wrapper class will generate a class name of `FooServiceOuterClass`.
6565

66+
**Note:** If you are using the deprecated v1 of the protobuf API, `OuterClass`
67+
is added regardless of any collisions with message names.
68+
6669
In addition to any nested classes, the wrapper class itself will have the
6770
following API (assuming the wrapper class is named `Foo` and was generated from
6871
`foo.proto`):
@@ -108,11 +111,6 @@ provide an output location ending in `.jar`. Note that only the Java source code
108111
is placed in the archive; you must still compile it separately to produce Java
109112
class files.
110113

111-
## Packages {#package}
112-
113-
The generated class is placed in a Java package based on the `java_package`
114-
option. If the option is omitted, the `package` declaration is used instead.
115-
116114
For example, if the `.proto` file contains:
117115

118116
```proto

content/reference/java/java-proto-names.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ java_api_version | java_multiple_files | java_alt_api_package | java_package | j
4949
If the generated class name would be the same as one of the messages defined
5050
in the proto file, `derived_outer_class` has `OuterClass` appended to it.
5151
For example, if the proto is `foo_bar.proto` and contains a `FooBar`
52-
message, the `$derived_outer_class` value is `FooBarOuterClass`.
52+
message, the `$derived_outer_class` value is `FooBarOuterClass`. The same is
53+
true when using the v1 API, whether or not the class name would be the same
54+
as one of the messages defined.
5355

5456
* All other `$names` are the values of the corresponding proto2 file options
5557
defined in the proto file.

0 commit comments

Comments
 (0)