Skip to content

Commit

Permalink
all: reformat with go1.19 gofmt
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Lasse Folger <[email protected]>
  • Loading branch information
neild committed Jul 21, 2022
1 parent c1bbc5d commit b0a9446
Show file tree
Hide file tree
Showing 22 changed files with 118 additions and 103 deletions.
1 change: 1 addition & 0 deletions cmd/protoc-gen-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions encoding/protowire/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,27 +516,31 @@ 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 {
return int64(x>>1) ^ int64(x)<<63>>63
}

// 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 {
return uint64(x<<1) ^ uint64(x>>63)
}

// DecodeBool decodes a uint64 as a bool.
//
// Input: { 0, 1, 2, …}
// Output: {false, true, true, …}
func DecodeBool(x uint64) bool {
return x != 0
}

// EncodeBool encodes a bool as a uint64.
//
// Input: {false, true}
// Output: { 0, 1}
func EncodeBool(x bool) uint64 {
Expand Down
1 change: 1 addition & 0 deletions internal/encoding/messageset/messageset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions internal/encoding/text/decode_number.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]?)
//
// 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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/encoding/text/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions internal/filetype/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions internal/impl/message_reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -351,12 +350,11 @@ 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,
// even though they are different Go types.
// - 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
pragma.DoNotCompare
Expand Down
52 changes: 26 additions & 26 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,43 @@ 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
// contains "devel".
// * The set of all commits in this repository where String
// does not contain "devel" must have a unique 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
// 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.
// PreRelease must not contain the string "devel".
// 1. Create a new CL.
//
// 3. Since the last released minor version, have there been any changes to
// generator that relies on new functionality in the runtime?
// If yes, then increment RequiredGenerated.
// 2. Update Minor, Patch, and/or PreRelease as necessary.
// PreRelease must not contain the string "devel".
//
// 4. Since the last released minor version, have there been any changes to
// the runtime that removes support for old .pb.go source code?
// If yes, then increment SupportMinimum.
// 3. Since the last released minor version, have there been any changes to
// generator that relies on new functionality in the runtime?
// If yes, then increment RequiredGenerated.
//
// 5. Send out the CL for review and submit it.
// Note that the next CL in step 8 must be submitted after this CL
// without any other CLs in-between.
// 4. Since the last released minor version, have there been any changes to
// the runtime that removes support for old .pb.go source code?
// If yes, then increment SupportMinimum.
//
// 6. Tag a new version, where the tag is is the current String.
// 5. Send out the CL for review and submit it.
// Note that the next CL in step 8 must be submitted after this CL
// without any other CLs in-between.
//
// 7. Write release notes for all notable changes
// between this release and the last release.
// 6. Tag a new version, where the tag is is the current String.
//
// 8. Create a new CL.
// 7. Write release notes for all notable changes
// between this release and the last release.
//
// 9. Update PreRelease to include the string "devel".
// For example: "" -> "devel" or "rc.1" -> "rc.1.devel"
// 8. Create a new CL.
//
// 10. Send out the CL for review and submit it.
// 9. Update PreRelease to include the string "devel".
// For example: "" -> "devel" or "rc.1" -> "rc.1.devel"
//
// 10. Send out the CL for review and submit it.
const (
Major = 1
Minor = 28
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion proto/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import (
// UnmarshalOptions configures the unmarshaler.
//
// Example usage:
// err := UnmarshalOptions{DiscardUnknown: true}.Unmarshal(b, m)
//
// err := UnmarshalOptions{DiscardUnknown: true}.Unmarshal(b, m)
type UnmarshalOptions struct {
pragma.NoUnkeyedLiterals

Expand Down
21 changes: 8 additions & 13 deletions proto/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
//
// For documentation on protocol buffers in general, see:
//
// https://developers.google.com/protocol-buffers
// https://developers.google.com/protocol-buffers
//
// For a tutorial on using protocol buffers with Go, see:
//
// https://developers.google.com/protocol-buffers/docs/gotutorial
// https://developers.google.com/protocol-buffers/docs/gotutorial
//
// For a guide to generated Go protocol buffer code, see:
//
// https://developers.google.com/protocol-buffers/docs/reference/go-generated
// 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.
Expand All @@ -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.
//
Expand All @@ -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
Expand All @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion proto/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
// MarshalOptions configures the marshaler.
//
// Example usage:
// b, err := MarshalOptions{Deterministic: true}.Marshal(m)
//
// b, err := MarshalOptions{Deterministic: true}.Marshal(m)
type MarshalOptions struct {
pragma.NoUnkeyedLiterals

Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions reflect/protodesc/desc_resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions reflect/protopath/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions reflect/protorange/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 4 additions & 11 deletions reflect/protoreflect/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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) ─────────────┐ │
Expand All @@ -83,7 +78,6 @@
//
// • An Enum is a concrete enum instance. Generated enums implement Enum.
//
//
// ┌──────────────── New() ─────────────────┐
// │ │
// │ ┌─── Descriptor() ─────┐ │ ┌── Interface() ───┐
Expand Down Expand Up @@ -115,7 +109,6 @@
// calling reflect.ValueOf, and the Message.Interface method is similar to
// calling reflect.Value.Interface.
//
//
// ┌── TypeDescriptor() ──┐ ┌───── Descriptor() ─────┐
// │ V │ V
// ╔═══════════════╗ ╔═════════════════════════╗ ╔═════════════════════╗
Expand Down
1 change: 1 addition & 0 deletions reflect/protoreflect/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions reflect/protoreflect/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ type ExtensionDescriptors interface {
// relative to the parent that it is declared within.
//
// For example:
//
// syntax = "proto2";
// package example;
// message FooMessage {
Expand Down
2 changes: 2 additions & 0 deletions reflect/protoreflect/value_union.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
//
Expand Down
Loading

0 comments on commit b0a9446

Please sign in to comment.