all: reformat with go1.19 gofmt

Apply go1.19 gofmt to non-generated files.

Generated .pb.go files are created by generate.bash using Go 1.18,
so leave them unchanged for now.

Change-Id: Ied36c83cf99704988d059bf0412e677f0fbc71b0
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/418676
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
This commit is contained in:
Damien Neil 2022-07-20 14:33:57 -07:00
parent c1bbc5d45b
commit b0a944684d
22 changed files with 118 additions and 103 deletions

View File

@ -6,6 +6,7 @@
// both proto2 and proto3 versions of the protocol buffer language.
//
// For more information about the usage of this plugin, see:
//
// https://developers.google.com/protocol-buffers/docs/reference/go-generated
package main

View File

@ -516,6 +516,7 @@ func EncodeTag(num Number, typ Type) uint64 {
}
// DecodeZigZag decodes a zig-zag-encoded uint64 as an int64.
//
// Input: {…, 5, 3, 1, 0, 2, 4, 6, …}
// Output: {…, -3, -2, -1, 0, +1, +2, +3, …}
func DecodeZigZag(x uint64) int64 {
@ -523,6 +524,7 @@ func DecodeZigZag(x uint64) int64 {
}
// EncodeZigZag encodes an int64 as a zig-zag-encoded uint64.
//
// Input: {…, -3, -2, -1, 0, +1, +2, +3, …}
// Output: {…, 5, 3, 1, 0, 2, 4, 6, …}
func EncodeZigZag(x int64) uint64 {
@ -530,6 +532,7 @@ func EncodeZigZag(x int64) uint64 {
}
// DecodeBool decodes a uint64 as a bool.
//
// Input: { 0, 1, 2, …}
// Output: {false, true, true, …}
func DecodeBool(x uint64) bool {
@ -537,6 +540,7 @@ func DecodeBool(x uint64) bool {
}
// EncodeBool encodes a bool as a uint64.
//
// Input: {false, true}
// Output: { 0, 1}
func EncodeBool(x bool) uint64 {

View File

@ -33,6 +33,7 @@ const (
// ExtensionName is the field name for extensions of MessageSet.
//
// A valid MessageSet extension must be of the form:
//
// message MyMessage {
// extend proto2.bridge.MessageSet {
// optional MyMessage message_set_extension = 1234;

View File

@ -50,8 +50,10 @@ type number struct {
// parseNumber constructs a number object from given input. It allows for the
// following patterns:
//
// integer: ^-?([1-9][0-9]*|0[xX][0-9a-fA-F]+|0[0-7]*)
// float: ^-?((0|[1-9][0-9]*)?([.][0-9]*)?([eE][+-]?[0-9]+)?[fF]?)
//
// It also returns the number of parsed bytes for the given number, 0 if it is
// not a number.
func parseNumber(input []byte) number {

View File

@ -24,6 +24,6 @@
// the Go implementation should as well.
//
// The text format is almost a superset of JSON except:
// * message keys are not quoted strings, but identifiers
// * the top-level value must be a message without the delimiters
// - message keys are not quoted strings, but identifiers
// - the top-level value must be a message without the delimiters
package text

View File

@ -19,8 +19,7 @@ import (
// Builder constructs type descriptors from a raw file descriptor
// and associated Go types for each enum and message declaration.
//
//
// Flattened Ordering
// # Flattened Ordering
//
// The protobuf type system represents declarations as a tree. Certain nodes in
// the tree require us to either associate it with a concrete Go type or to

View File

@ -320,7 +320,6 @@ func (m *extensionMap) Mutable(xt protoreflect.ExtensionType) protoreflect.Value
// in an allocation-free way without needing to have a shadow Go type generated
// for every message type. This technique only works using unsafe.
//
//
// Example generated code:
//
// type M struct {
@ -351,11 +350,10 @@ func (m *extensionMap) Mutable(xt protoreflect.ExtensionType) protoreflect.Value
// It has access to the message info as its first field, and a pointer to the
// MessageState is identical to a pointer to the concrete message value.
//
//
// Requirements:
// The type M must implement protoreflect.ProtoMessage.
// The address of m must not be nil.
// The address of m and the address of m.state must be equal,
// - The type M must implement protoreflect.ProtoMessage.
// - The address of m must not be nil.
// - The address of m and the address of m.state must be equal,
// even though they are different Go types.
type MessageState struct {
pragma.NoUnkeyedLiterals

View File

@ -12,16 +12,15 @@ import (
// These constants determine the current version of this module.
//
//
// For our release process, we enforce the following rules:
// * Tagged releases use a tag that is identical to String.
// * Tagged releases never reference a commit where the String
// - Tagged releases use a tag that is identical to String.
// - Tagged releases never reference a commit where the String
// contains "devel".
// * The set of all commits in this repository where String
// - The set of all commits in this repository where String
// does not contain "devel" must have a unique String.
//
//
// Steps for tagging a new release:
//
// 1. Create a new CL.
//
// 2. Update Minor, Patch, and/or PreRelease as necessary.
@ -60,6 +59,7 @@ const (
// String formats the version string for this module in semver format.
//
// Examples:
//
// v1.20.1
// v1.21.0-rc.1
func String() string {

View File

@ -19,6 +19,7 @@ import (
// UnmarshalOptions configures the unmarshaler.
//
// Example usage:
//
// err := UnmarshalOptions{DiscardUnknown: true}.Unmarshal(b, m)
type UnmarshalOptions struct {
pragma.NoUnkeyedLiterals

View File

@ -16,8 +16,7 @@
//
// https://developers.google.com/protocol-buffers/docs/reference/go-generated
//
//
// Binary serialization
// # Binary serialization
//
// This package contains functions to convert to and from the wire format,
// an efficient binary serialization of protocol buffers.
@ -30,8 +29,7 @@
// • Unmarshal converts a message from the wire format.
// The UnmarshalOptions type provides more control over wire unmarshaling.
//
//
// Basic message operations
// # Basic message operations
//
// • Clone makes a deep copy of a message.
//
@ -45,8 +43,7 @@
//
// • CheckInitialized reports whether all required fields in a message are set.
//
//
// Optional scalar constructors
// # Optional scalar constructors
//
// The API for some generated messages represents optional scalar fields
// as pointers to a value. For example, an optional string field has the
@ -61,16 +58,14 @@
//
// Optional scalar fields are only supported in proto2.
//
//
// Extension accessors
// # Extension accessors
//
// • HasExtension, GetExtension, SetExtension, and ClearExtension
// access extension field values in a protocol buffer message.
//
// Extension fields are only supported in proto2.
//
//
// Related packages
// # Related packages
//
// • Package "google.golang.org/protobuf/encoding/protojson" converts messages to
// and from JSON.

View File

@ -16,6 +16,7 @@ import (
// MarshalOptions configures the marshaler.
//
// Example usage:
//
// b, err := MarshalOptions{Deterministic: true}.Marshal(m)
type MarshalOptions struct {
pragma.NoUnkeyedLiterals
@ -101,7 +102,9 @@ func (o MarshalOptions) Marshal(m Message) ([]byte, error) {
// otherwise it returns a non-nil empty buffer.
//
// This is to assist the edge-case where user-code does the following:
//
// m1.OptionalBytes, _ = proto.Marshal(m2)
//
// where they expect the proto2 "optional_bytes" field to be populated
// if any only if m2 is a valid message.
func emptyBytesForMessage(m Message) []byte {

View File

@ -155,9 +155,9 @@ func (r *resolver) findTarget(k protoreflect.Kind, scope protoreflect.FullName,
//
// Suppose the scope was "fizz.buzz" and the reference was "Foo.Bar",
// then the following full names are searched:
// * fizz.buzz.Foo.Bar
// * fizz.Foo.Bar
// * Foo.Bar
// - fizz.buzz.Foo.Bar
// - fizz.Foo.Bar
// - Foo.Bar
func (r *resolver) findDescriptor(scope protoreflect.FullName, ref partialName) (protoreflect.Descriptor, error) {
if !ref.IsValid() {
return nil, errors.New("invalid name reference: %q", ref)

View File

@ -99,6 +99,7 @@ func (p Values) Index(i int) (out struct {
// Do not depend on the output being stable.
//
// For example:
//
// (path.to.MyMessage).list_field[5].map_field["hello"] = {hello: "world"}
func (p Values) String() string {
n := p.Len()

View File

@ -300,6 +300,7 @@ func popStep(p *protopath.Values) {
// amendError amends the previous error with the current error if it is
// considered more serious. The precedence order for errors is:
//
// nil < Break < Terminate < previous non-nil < current non-nil
func amendError(prev, curr error) error {
switch {

View File

@ -8,8 +8,7 @@
// defined in proto source files and value interfaces which provide the
// ability to examine and manipulate the contents of messages.
//
//
// Protocol Buffer Descriptors
// # Protocol Buffer Descriptors
//
// Protobuf descriptors (e.g., EnumDescriptor or MessageDescriptor)
// are immutable objects that represent protobuf type information.
@ -26,8 +25,7 @@
// The "google.golang.org/protobuf/reflect/protodesc" package converts between
// google.protobuf.DescriptorProto messages and protobuf descriptors.
//
//
// Go Type Descriptors
// # Go Type Descriptors
//
// A type descriptor (e.g., EnumType or MessageType) is a constructor for
// a concrete Go type that represents the associated protobuf descriptor.
@ -41,8 +39,7 @@
// The "google.golang.org/protobuf/types/dynamicpb" package can be used to
// create Go type descriptors from protobuf descriptors.
//
//
// Value Interfaces
// # Value Interfaces
//
// The Enum and Message interfaces provide a reflective view over an
// enum or message instance. For enums, it provides the ability to retrieve
@ -55,13 +52,11 @@
// The "github.com/golang/protobuf/proto".MessageReflect function can be used
// to obtain a reflective view on older messages.
//
//
// Relationships
// # Relationships
//
// The following diagrams demonstrate the relationships between
// various types declared in this package.
//
//
// ┌───────────────────────────────────┐
// V │
// ┌────────────── New(n) ─────────────┐ │
@ -83,7 +78,6 @@
//
// • An Enum is a concrete enum instance. Generated enums implement Enum.
//
//
// ┌──────────────── New() ─────────────────┐
// │ │
// │ ┌─── Descriptor() ─────┐ │ ┌── Interface() ───┐
@ -115,7 +109,6 @@
// calling reflect.ValueOf, and the Message.Interface method is similar to
// calling reflect.Value.Interface.
//
//
// ┌── TypeDescriptor() ──┐ ┌───── Descriptor() ─────┐
// │ V │ V
// ╔═══════════════╗ ╔═════════════════════════╗ ╔═════════════════════╗

View File

@ -87,6 +87,7 @@ func (p1 SourcePath) Equal(p2 SourcePath) bool {
// in a future version of this module.
//
// Example output:
//
// .message_type[6].nested_type[15].field[3]
func (p SourcePath) String() string {
b := p.appendFileDescriptorProto(nil)

View File

@ -480,6 +480,7 @@ type ExtensionDescriptors interface {
// relative to the parent that it is declared within.
//
// For example:
//
// syntax = "proto2";
// package example;
// message FooMessage {

View File

@ -50,6 +50,7 @@ import (
// always references the source object.
//
// For example:
//
// // Append a 0 to a "repeated int32" field.
// // Since the Value returned by Mutable is guaranteed to alias
// // the source message, modifying the Value modifies the message.
@ -392,6 +393,7 @@ func (v Value) MapKey() MapKey {
// ╚═════════╧═════════════════════════════════════╝
//
// A MapKey is constructed and accessed through a Value:
//
// k := ValueOf("hash").MapKey() // convert string to MapKey
// s := k.String() // convert MapKey to string
//

View File

@ -30,9 +30,11 @@ import (
// conflictPolicy configures the policy for handling registration conflicts.
//
// It can be over-written at compile time with a linker-initialized variable:
//
// go build -ldflags "-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn"
//
// It can be over-written at program execution with an environment variable:
//
// GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn ./main
//
// Neither of the above are covered by the compatibility promise and

View File

@ -26,16 +26,19 @@ const (
// EnforceVersion is used by code generated by protoc-gen-go
// to statically enforce minimum and maximum versions of this package.
// A compilation failure implies either that:
// * the runtime package is too old and needs to be updated OR
// * the generated code is too old and needs to be regenerated.
// - the runtime package is too old and needs to be updated OR
// - the generated code is too old and needs to be regenerated.
//
// The runtime package can be upgraded by running:
//
// go get google.golang.org/protobuf
//
// The generated code can be regenerated by running:
//
// protoc --go_out=${PROTOC_GEN_GO_ARGS} ${PROTO_FILES}
//
// Example usage by generated code:
//
// const (
// // Verify that this generated code is sufficiently up-to-date.
// _ = protoimpl.EnforceVersion(genVersion - protoimpl.MinVersion)
@ -49,6 +52,7 @@ const (
type EnforceVersion uint
// This enforces the following invariant:
//
// MinVersion ≤ GenVersion ≤ MaxVersion
const (
_ = EnforceVersion(GenVersion - MinVersion)

View File

@ -28,11 +28,11 @@ var (
// where the enum is the same type as the specified enum.
//
// The Go type of the last path step may be an:
// Enum for singular fields, elements of a repeated field,
// - Enum for singular fields, elements of a repeated field,
// values of a map field, or standalone Enums
// []Enum for list fields
// map[K]Enum for map fields
// interface{} for a Message map entry value
// - []Enum for list fields
// - map[K]Enum for map fields
// - interface{} for a Message map entry value
//
// This must be used in conjunction with Transform.
func FilterEnum(enum protoreflect.Enum, opt cmp.Option) cmp.Option {
@ -44,11 +44,11 @@ func FilterEnum(enum protoreflect.Enum, opt cmp.Option) cmp.Option {
// message values, where the message is the same type as the specified message.
//
// The Go type of the last path step may be an:
// Message for singular fields, elements of a repeated field,
// - Message for singular fields, elements of a repeated field,
// values of a map field, or standalone Messages
// []Message for list fields
// map[K]Message for map fields
// interface{} for a Message map entry value
// - []Message for list fields
// - map[K]Message for map fields
// - interface{} for a Message map entry value
//
// This must be used in conjunction with Transform.
func FilterMessage(message proto.Message, opt cmp.Option) cmp.Option {
@ -59,10 +59,10 @@ func FilterMessage(message proto.Message, opt cmp.Option) cmp.Option {
// in the message. It panics if a field of the given name does not exist.
//
// The Go type of the last path step may be an:
// T for singular fields
// []T for list fields
// map[K]T for map fields
// interface{} for a Message map entry value
// - T for singular fields
// - []T for list fields
// - map[K]T for map fields
// - interface{} for a Message map entry value
//
// This must be used in conjunction with Transform.
func FilterField(message proto.Message, name protoreflect.Name, opt cmp.Option) cmp.Option {
@ -75,10 +75,10 @@ func FilterField(message proto.Message, name protoreflect.Name, opt cmp.Option)
// does not exist.
//
// The Go type of the last path step may be an:
// T for singular fields
// []T for list fields
// map[K]T for map fields
// interface{} for a Message map entry value
// - T for singular fields
// - []T for list fields
// - map[K]T for map fields
// - interface{} for a Message map entry value
//
// This must be used in conjunction with Transform.
func FilterOneof(message proto.Message, name protoreflect.Name, opt cmp.Option) cmp.Option {
@ -89,10 +89,10 @@ func FilterOneof(message proto.Message, name protoreflect.Name, opt cmp.Option)
// FilterDescriptor ignores the specified descriptor.
//
// The following descriptor types may be specified:
// protoreflect.EnumDescriptor
// protoreflect.MessageDescriptor
// protoreflect.FieldDescriptor
// protoreflect.OneofDescriptor
// - protoreflect.EnumDescriptor
// - protoreflect.MessageDescriptor
// - protoreflect.FieldDescriptor
// - protoreflect.OneofDescriptor
//
// For the behavior of each, see the corresponding filter function.
// Since this filter accepts a protoreflect.FieldDescriptor, it can be used
@ -513,10 +513,10 @@ func IgnoreUnknown() cmp.Option {
// Go element type for the repeated field kind.
//
// The element type T can be one of the following:
// Go type for a protobuf scalar kind except for an enum
// - Go type for a protobuf scalar kind except for an enum
// (i.e., bool, int32, int64, uint32, uint64, float32, float64, string, and []byte)
// E where E is a concrete enum type that implements protoreflect.Enum
// M where M is a concrete message type that implement proto.Message
// - E where E is a concrete enum type that implements protoreflect.Enum
// - M where M is a concrete message type that implement proto.Message
//
// This option only applies to repeated fields within a protobuf message.
// It does not operate on higher-order Go types that seem like a repeated field.
@ -608,13 +608,13 @@ func checkTTBFunc(lessFunc interface{}) (reflect.Type, bool) {
// It panics if the field does not exist or is not a repeated field.
//
// The sort ordering is as follows:
// Booleans are sorted where false is sorted before true.
// Integers are sorted in ascending order.
// Floating-point numbers are sorted in ascending order according to
// - Booleans are sorted where false is sorted before true.
// - Integers are sorted in ascending order.
// - Floating-point numbers are sorted in ascending order according to
// the total ordering defined by IEEE-754 (section 5.10).
// Strings and bytes are sorted lexicographically in ascending order.
// Enums are sorted in ascending order based on its numeric value.
// Messages are sorted according to some arbitrary ordering
// - Strings and bytes are sorted lexicographically in ascending order.
// - Enums are sorted in ascending order based on its numeric value.
// - Messages are sorted according to some arbitrary ordering
// which is undefined and may change in future implementations.
//
// The ordering chosen for repeated messages is unlikely to be aesthetically

View File

@ -173,6 +173,7 @@ func (m Message) Size() int {
// Marshal encodes a syntax tree into the protobuf wire format.
//
// Example message definition:
//
// message MyMessage {
// string field1 = 1;
// int64 field2 = 2;
@ -180,6 +181,7 @@ func (m Message) Size() int {
// }
//
// Example encoded message:
//
// b := Message{
// Tag{1, BytesType}, String("Hello, world!"),
// Tag{2, VarintType}, Varint(-10),
@ -189,6 +191,7 @@ func (m Message) Size() int {
// }.Marshal()
//
// Resulting wire data:
//
// 0x0000 0a 0d 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21 10 |..Hello, world!.|
// 0x0010 f6 ff ff ff ff ff ff ff ff 01 1a 0c cd cc 8c 3f |...............?|
// 0x0020 cd cc 0c 40 33 33 53 40 |...@33S@|
@ -252,6 +255,7 @@ func (m Message) Marshal() []byte {
// inserted into the syntax tree as a Tag.
//
// The contents of each wire type is mapped to the following Go types:
//
// VarintType => Uvarint
// Fixed32Type => Uint32
// Fixed64Type => Uint64
@ -261,6 +265,7 @@ func (m Message) Marshal() []byte {
// Since the wire format is not self-describing, this function cannot parse
// sub-messages and will leave them as the Bytes type. Further manual parsing
// can be performed as such:
//
// var m, m1, m2 Message
// m.Unmarshal(b)
// m1.Unmarshal(m[3].(Bytes))
@ -279,6 +284,7 @@ func (m *Message) Unmarshal(in []byte) {
// represent the wire data.
//
// The contents of each wire type is mapped to one of the following Go types:
//
// VarintType => Bool, Varint, Svarint, Uvarint
// Fixed32Type => Int32, Uint32, Float32
// Fixed64Type => Uint32, Uint64, Float64