rebase: bump google.golang.org/protobuf from 1.28.1 to 1.30.0

Bumps google.golang.org/protobuf from 1.28.1 to 1.30.0.

---
updated-dependencies:
- dependency-name: google.golang.org/protobuf
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot] 2023-04-24 21:02:04 +00:00 committed by mergify[bot]
parent b71beb7ad0
commit a0213a94fe
27 changed files with 1506 additions and 1002 deletions

2
go.mod
View File

@ -31,7 +31,7 @@ require (
golang.org/x/net v0.8.0 golang.org/x/net v0.8.0
golang.org/x/sys v0.7.0 golang.org/x/sys v0.7.0
google.golang.org/grpc v1.54.0 google.golang.org/grpc v1.54.0
google.golang.org/protobuf v1.28.1 google.golang.org/protobuf v1.30.0
// //
// when updating k8s.io/kubernetes, make sure to update the replace section too // when updating k8s.io/kubernetes, make sure to update the replace section too
// //

3
go.sum
View File

@ -1676,8 +1676,9 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw= gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -4,7 +4,7 @@
// Package protojson marshals and unmarshals protocol buffer messages as JSON // Package protojson marshals and unmarshals protocol buffer messages as JSON
// format. It follows the guide at // format. It follows the guide at
// https://developers.google.com/protocol-buffers/docs/proto3#json. // https://protobuf.dev/programming-guides/proto3#json.
// //
// This package produces a different output than the standard "encoding/json" // This package produces a different output than the standard "encoding/json"
// package, which does not operate correctly on protocol buffer messages. // package, which does not operate correctly on protocol buffer messages.

View File

@ -814,16 +814,22 @@ func (d decoder) unmarshalTimestamp(m protoreflect.Message) error {
return d.unexpectedTokenError(tok) return d.unexpectedTokenError(tok)
} }
t, err := time.Parse(time.RFC3339Nano, tok.ParsedString()) s := tok.ParsedString()
t, err := time.Parse(time.RFC3339Nano, s)
if err != nil { if err != nil {
return d.newError(tok.Pos(), "invalid %v value %v", genid.Timestamp_message_fullname, tok.RawString()) return d.newError(tok.Pos(), "invalid %v value %v", genid.Timestamp_message_fullname, tok.RawString())
} }
// Validate seconds. No need to validate nanos because time.Parse would have // Validate seconds.
// covered that already.
secs := t.Unix() secs := t.Unix()
if secs < minTimestampSeconds || secs > maxTimestampSeconds { if secs < minTimestampSeconds || secs > maxTimestampSeconds {
return d.newError(tok.Pos(), "%v value out of range: %v", genid.Timestamp_message_fullname, tok.RawString()) return d.newError(tok.Pos(), "%v value out of range: %v", genid.Timestamp_message_fullname, tok.RawString())
} }
// Validate subseconds.
i := strings.LastIndexByte(s, '.') // start of subsecond field
j := strings.LastIndexAny(s, "Z-+") // start of timezone field
if i >= 0 && j >= i && j-i > len(".999999999") {
return d.newError(tok.Pos(), "invalid %v value %v", genid.Timestamp_message_fullname, tok.RawString())
}
fds := m.Descriptor().Fields() fds := m.Descriptor().Fields()
fdSeconds := fds.ByNumber(genid.Timestamp_Seconds_field_number) fdSeconds := fds.ByNumber(genid.Timestamp_Seconds_field_number)

View File

@ -3,7 +3,7 @@
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Package protowire parses and formats the raw wire encoding. // Package protowire parses and formats the raw wire encoding.
// See https://developers.google.com/protocol-buffers/docs/encoding. // See https://protobuf.dev/programming-guides/encoding.
// //
// For marshaling and unmarshaling entire protobuf messages, // For marshaling and unmarshaling entire protobuf messages,
// use the "google.golang.org/protobuf/proto" package instead. // use the "google.golang.org/protobuf/proto" package instead.
@ -29,12 +29,8 @@ const (
) )
// IsValid reports whether the field number is semantically valid. // IsValid reports whether the field number is semantically valid.
//
// Note that while numbers within the reserved range are semantically invalid,
// they are syntactically valid in the wire format.
// Implementations may treat records with reserved field numbers as unknown.
func (n Number) IsValid() bool { func (n Number) IsValid() bool {
return MinValidNumber <= n && n < FirstReservedNumber || LastReservedNumber < n && n <= MaxValidNumber return MinValidNumber <= n && n <= MaxValidNumber
} }
// Type represents the wire type. // Type represents the wire type.

View File

@ -294,7 +294,7 @@ func (d *Decoder) isValueNext() bool {
} }
// consumeToken constructs a Token for given Kind with raw value derived from // consumeToken constructs a Token for given Kind with raw value derived from
// current d.in and given size, and consumes the given size-lenght of it. // current d.in and given size, and consumes the given size-length of it.
func (d *Decoder) consumeToken(kind Kind, size int) Token { func (d *Decoder) consumeToken(kind Kind, size int) Token {
tok := Token{ tok := Token{
kind: kind, kind: kind,

View File

@ -412,12 +412,13 @@ func (d *Decoder) parseFieldName() (tok Token, err error) {
// Field number. Identify if input is a valid number that is not negative // Field number. Identify if input is a valid number that is not negative
// and is decimal integer within 32-bit range. // and is decimal integer within 32-bit range.
if num := parseNumber(d.in); num.size > 0 { if num := parseNumber(d.in); num.size > 0 {
str := num.string(d.in)
if !num.neg && num.kind == numDec { if !num.neg && num.kind == numDec {
if _, err := strconv.ParseInt(string(d.in[:num.size]), 10, 32); err == nil { if _, err := strconv.ParseInt(str, 10, 32); err == nil {
return d.consumeToken(Name, num.size, uint8(FieldNumber)), nil return d.consumeToken(Name, num.size, uint8(FieldNumber)), nil
} }
} }
return Token{}, d.newSyntaxError("invalid field number: %s", d.in[:num.size]) return Token{}, d.newSyntaxError("invalid field number: %s", str)
} }
return Token{}, d.newSyntaxError("invalid field name: %s", errId(d.in)) return Token{}, d.newSyntaxError("invalid field name: %s", errId(d.in))

View File

@ -15,17 +15,12 @@ func (d *Decoder) parseNumberValue() (Token, bool) {
if num.neg { if num.neg {
numAttrs |= isNegative numAttrs |= isNegative
} }
strSize := num.size
last := num.size - 1
if num.kind == numFloat && (d.in[last] == 'f' || d.in[last] == 'F') {
strSize = last
}
tok := Token{ tok := Token{
kind: Scalar, kind: Scalar,
attrs: numberValue, attrs: numberValue,
pos: len(d.orig) - len(d.in), pos: len(d.orig) - len(d.in),
raw: d.in[:num.size], raw: d.in[:num.size],
str: string(d.in[:strSize]), str: num.string(d.in),
numAttrs: numAttrs, numAttrs: numAttrs,
} }
d.consume(num.size) d.consume(num.size)
@ -46,6 +41,27 @@ type number struct {
kind uint8 kind uint8
neg bool neg bool
size int size int
// if neg, this is the length of whitespace and comments between
// the minus sign and the rest fo the number literal
sep int
}
func (num number) string(data []byte) string {
strSize := num.size
last := num.size - 1
if num.kind == numFloat && (data[last] == 'f' || data[last] == 'F') {
strSize = last
}
if num.neg && num.sep > 0 {
// strip whitespace/comments between negative sign and the rest
strLen := strSize - num.sep
str := make([]byte, strLen)
str[0] = data[0]
copy(str[1:], data[num.sep+1:strSize])
return string(str)
}
return string(data[:strSize])
} }
// parseNumber constructs a number object from given input. It allows for the // parseNumber constructs a number object from given input. It allows for the
@ -67,19 +83,22 @@ func parseNumber(input []byte) number {
} }
// Optional - // Optional -
var sep int
if s[0] == '-' { if s[0] == '-' {
neg = true neg = true
s = s[1:] s = s[1:]
size++ size++
// Consume any whitespace or comments between the
// negative sign and the rest of the number
lenBefore := len(s)
s = consume(s, 0)
sep = lenBefore - len(s)
size += sep
if len(s) == 0 { if len(s) == 0 {
return number{} return number{}
} }
} }
// C++ allows for whitespace and comments in between the negative sign and
// the rest of the number. This logic currently does not but is consistent
// with v1.
switch { switch {
case s[0] == '0': case s[0] == '0':
if len(s) > 1 { if len(s) > 1 {
@ -116,7 +135,7 @@ func parseNumber(input []byte) number {
if len(s) > 0 && !isDelim(s[0]) { if len(s) > 0 && !isDelim(s[0]) {
return number{} return number{}
} }
return number{kind: kind, neg: neg, size: size} return number{kind: kind, neg: neg, size: size, sep: sep}
} }
} }
s = s[1:] s = s[1:]
@ -188,5 +207,5 @@ func parseNumber(input []byte) number {
return number{} return number{}
} }
return number{kind: kind, neg: neg, size: size} return number{kind: kind, neg: neg, size: size, sep: sep}
} }

View File

@ -50,6 +50,7 @@ const (
FileDescriptorProto_Options_field_name protoreflect.Name = "options" FileDescriptorProto_Options_field_name protoreflect.Name = "options"
FileDescriptorProto_SourceCodeInfo_field_name protoreflect.Name = "source_code_info" FileDescriptorProto_SourceCodeInfo_field_name protoreflect.Name = "source_code_info"
FileDescriptorProto_Syntax_field_name protoreflect.Name = "syntax" FileDescriptorProto_Syntax_field_name protoreflect.Name = "syntax"
FileDescriptorProto_Edition_field_name protoreflect.Name = "edition"
FileDescriptorProto_Name_field_fullname protoreflect.FullName = "google.protobuf.FileDescriptorProto.name" FileDescriptorProto_Name_field_fullname protoreflect.FullName = "google.protobuf.FileDescriptorProto.name"
FileDescriptorProto_Package_field_fullname protoreflect.FullName = "google.protobuf.FileDescriptorProto.package" FileDescriptorProto_Package_field_fullname protoreflect.FullName = "google.protobuf.FileDescriptorProto.package"
@ -63,6 +64,7 @@ const (
FileDescriptorProto_Options_field_fullname protoreflect.FullName = "google.protobuf.FileDescriptorProto.options" FileDescriptorProto_Options_field_fullname protoreflect.FullName = "google.protobuf.FileDescriptorProto.options"
FileDescriptorProto_SourceCodeInfo_field_fullname protoreflect.FullName = "google.protobuf.FileDescriptorProto.source_code_info" FileDescriptorProto_SourceCodeInfo_field_fullname protoreflect.FullName = "google.protobuf.FileDescriptorProto.source_code_info"
FileDescriptorProto_Syntax_field_fullname protoreflect.FullName = "google.protobuf.FileDescriptorProto.syntax" FileDescriptorProto_Syntax_field_fullname protoreflect.FullName = "google.protobuf.FileDescriptorProto.syntax"
FileDescriptorProto_Edition_field_fullname protoreflect.FullName = "google.protobuf.FileDescriptorProto.edition"
) )
// Field numbers for google.protobuf.FileDescriptorProto. // Field numbers for google.protobuf.FileDescriptorProto.
@ -79,6 +81,7 @@ const (
FileDescriptorProto_Options_field_number protoreflect.FieldNumber = 8 FileDescriptorProto_Options_field_number protoreflect.FieldNumber = 8
FileDescriptorProto_SourceCodeInfo_field_number protoreflect.FieldNumber = 9 FileDescriptorProto_SourceCodeInfo_field_number protoreflect.FieldNumber = 9
FileDescriptorProto_Syntax_field_number protoreflect.FieldNumber = 12 FileDescriptorProto_Syntax_field_number protoreflect.FieldNumber = 12
FileDescriptorProto_Edition_field_number protoreflect.FieldNumber = 13
) )
// Names for google.protobuf.DescriptorProto. // Names for google.protobuf.DescriptorProto.
@ -498,12 +501,14 @@ const (
MessageOptions_NoStandardDescriptorAccessor_field_name protoreflect.Name = "no_standard_descriptor_accessor" MessageOptions_NoStandardDescriptorAccessor_field_name protoreflect.Name = "no_standard_descriptor_accessor"
MessageOptions_Deprecated_field_name protoreflect.Name = "deprecated" MessageOptions_Deprecated_field_name protoreflect.Name = "deprecated"
MessageOptions_MapEntry_field_name protoreflect.Name = "map_entry" MessageOptions_MapEntry_field_name protoreflect.Name = "map_entry"
MessageOptions_DeprecatedLegacyJsonFieldConflicts_field_name protoreflect.Name = "deprecated_legacy_json_field_conflicts"
MessageOptions_UninterpretedOption_field_name protoreflect.Name = "uninterpreted_option" MessageOptions_UninterpretedOption_field_name protoreflect.Name = "uninterpreted_option"
MessageOptions_MessageSetWireFormat_field_fullname protoreflect.FullName = "google.protobuf.MessageOptions.message_set_wire_format" MessageOptions_MessageSetWireFormat_field_fullname protoreflect.FullName = "google.protobuf.MessageOptions.message_set_wire_format"
MessageOptions_NoStandardDescriptorAccessor_field_fullname protoreflect.FullName = "google.protobuf.MessageOptions.no_standard_descriptor_accessor" MessageOptions_NoStandardDescriptorAccessor_field_fullname protoreflect.FullName = "google.protobuf.MessageOptions.no_standard_descriptor_accessor"
MessageOptions_Deprecated_field_fullname protoreflect.FullName = "google.protobuf.MessageOptions.deprecated" MessageOptions_Deprecated_field_fullname protoreflect.FullName = "google.protobuf.MessageOptions.deprecated"
MessageOptions_MapEntry_field_fullname protoreflect.FullName = "google.protobuf.MessageOptions.map_entry" MessageOptions_MapEntry_field_fullname protoreflect.FullName = "google.protobuf.MessageOptions.map_entry"
MessageOptions_DeprecatedLegacyJsonFieldConflicts_field_fullname protoreflect.FullName = "google.protobuf.MessageOptions.deprecated_legacy_json_field_conflicts"
MessageOptions_UninterpretedOption_field_fullname protoreflect.FullName = "google.protobuf.MessageOptions.uninterpreted_option" MessageOptions_UninterpretedOption_field_fullname protoreflect.FullName = "google.protobuf.MessageOptions.uninterpreted_option"
) )
@ -513,6 +518,7 @@ const (
MessageOptions_NoStandardDescriptorAccessor_field_number protoreflect.FieldNumber = 2 MessageOptions_NoStandardDescriptorAccessor_field_number protoreflect.FieldNumber = 2
MessageOptions_Deprecated_field_number protoreflect.FieldNumber = 3 MessageOptions_Deprecated_field_number protoreflect.FieldNumber = 3
MessageOptions_MapEntry_field_number protoreflect.FieldNumber = 7 MessageOptions_MapEntry_field_number protoreflect.FieldNumber = 7
MessageOptions_DeprecatedLegacyJsonFieldConflicts_field_number protoreflect.FieldNumber = 11
MessageOptions_UninterpretedOption_field_number protoreflect.FieldNumber = 999 MessageOptions_UninterpretedOption_field_number protoreflect.FieldNumber = 999
) )
@ -528,16 +534,24 @@ const (
FieldOptions_Packed_field_name protoreflect.Name = "packed" FieldOptions_Packed_field_name protoreflect.Name = "packed"
FieldOptions_Jstype_field_name protoreflect.Name = "jstype" FieldOptions_Jstype_field_name protoreflect.Name = "jstype"
FieldOptions_Lazy_field_name protoreflect.Name = "lazy" FieldOptions_Lazy_field_name protoreflect.Name = "lazy"
FieldOptions_UnverifiedLazy_field_name protoreflect.Name = "unverified_lazy"
FieldOptions_Deprecated_field_name protoreflect.Name = "deprecated" FieldOptions_Deprecated_field_name protoreflect.Name = "deprecated"
FieldOptions_Weak_field_name protoreflect.Name = "weak" FieldOptions_Weak_field_name protoreflect.Name = "weak"
FieldOptions_DebugRedact_field_name protoreflect.Name = "debug_redact"
FieldOptions_Retention_field_name protoreflect.Name = "retention"
FieldOptions_Target_field_name protoreflect.Name = "target"
FieldOptions_UninterpretedOption_field_name protoreflect.Name = "uninterpreted_option" FieldOptions_UninterpretedOption_field_name protoreflect.Name = "uninterpreted_option"
FieldOptions_Ctype_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.ctype" FieldOptions_Ctype_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.ctype"
FieldOptions_Packed_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.packed" FieldOptions_Packed_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.packed"
FieldOptions_Jstype_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.jstype" FieldOptions_Jstype_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.jstype"
FieldOptions_Lazy_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.lazy" FieldOptions_Lazy_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.lazy"
FieldOptions_UnverifiedLazy_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.unverified_lazy"
FieldOptions_Deprecated_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.deprecated" FieldOptions_Deprecated_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.deprecated"
FieldOptions_Weak_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.weak" FieldOptions_Weak_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.weak"
FieldOptions_DebugRedact_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.debug_redact"
FieldOptions_Retention_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.retention"
FieldOptions_Target_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.target"
FieldOptions_UninterpretedOption_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.uninterpreted_option" FieldOptions_UninterpretedOption_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.uninterpreted_option"
) )
@ -547,8 +561,12 @@ const (
FieldOptions_Packed_field_number protoreflect.FieldNumber = 2 FieldOptions_Packed_field_number protoreflect.FieldNumber = 2
FieldOptions_Jstype_field_number protoreflect.FieldNumber = 6 FieldOptions_Jstype_field_number protoreflect.FieldNumber = 6
FieldOptions_Lazy_field_number protoreflect.FieldNumber = 5 FieldOptions_Lazy_field_number protoreflect.FieldNumber = 5
FieldOptions_UnverifiedLazy_field_number protoreflect.FieldNumber = 15
FieldOptions_Deprecated_field_number protoreflect.FieldNumber = 3 FieldOptions_Deprecated_field_number protoreflect.FieldNumber = 3
FieldOptions_Weak_field_number protoreflect.FieldNumber = 10 FieldOptions_Weak_field_number protoreflect.FieldNumber = 10
FieldOptions_DebugRedact_field_number protoreflect.FieldNumber = 16
FieldOptions_Retention_field_number protoreflect.FieldNumber = 17
FieldOptions_Target_field_number protoreflect.FieldNumber = 18
FieldOptions_UninterpretedOption_field_number protoreflect.FieldNumber = 999 FieldOptions_UninterpretedOption_field_number protoreflect.FieldNumber = 999
) )
@ -564,6 +582,18 @@ const (
FieldOptions_JSType_enum_name = "JSType" FieldOptions_JSType_enum_name = "JSType"
) )
// Full and short names for google.protobuf.FieldOptions.OptionRetention.
const (
FieldOptions_OptionRetention_enum_fullname = "google.protobuf.FieldOptions.OptionRetention"
FieldOptions_OptionRetention_enum_name = "OptionRetention"
)
// Full and short names for google.protobuf.FieldOptions.OptionTargetType.
const (
FieldOptions_OptionTargetType_enum_fullname = "google.protobuf.FieldOptions.OptionTargetType"
FieldOptions_OptionTargetType_enum_name = "OptionTargetType"
)
// Names for google.protobuf.OneofOptions. // Names for google.protobuf.OneofOptions.
const ( const (
OneofOptions_message_name protoreflect.Name = "OneofOptions" OneofOptions_message_name protoreflect.Name = "OneofOptions"
@ -592,10 +622,12 @@ const (
const ( const (
EnumOptions_AllowAlias_field_name protoreflect.Name = "allow_alias" EnumOptions_AllowAlias_field_name protoreflect.Name = "allow_alias"
EnumOptions_Deprecated_field_name protoreflect.Name = "deprecated" EnumOptions_Deprecated_field_name protoreflect.Name = "deprecated"
EnumOptions_DeprecatedLegacyJsonFieldConflicts_field_name protoreflect.Name = "deprecated_legacy_json_field_conflicts"
EnumOptions_UninterpretedOption_field_name protoreflect.Name = "uninterpreted_option" EnumOptions_UninterpretedOption_field_name protoreflect.Name = "uninterpreted_option"
EnumOptions_AllowAlias_field_fullname protoreflect.FullName = "google.protobuf.EnumOptions.allow_alias" EnumOptions_AllowAlias_field_fullname protoreflect.FullName = "google.protobuf.EnumOptions.allow_alias"
EnumOptions_Deprecated_field_fullname protoreflect.FullName = "google.protobuf.EnumOptions.deprecated" EnumOptions_Deprecated_field_fullname protoreflect.FullName = "google.protobuf.EnumOptions.deprecated"
EnumOptions_DeprecatedLegacyJsonFieldConflicts_field_fullname protoreflect.FullName = "google.protobuf.EnumOptions.deprecated_legacy_json_field_conflicts"
EnumOptions_UninterpretedOption_field_fullname protoreflect.FullName = "google.protobuf.EnumOptions.uninterpreted_option" EnumOptions_UninterpretedOption_field_fullname protoreflect.FullName = "google.protobuf.EnumOptions.uninterpreted_option"
) )
@ -603,6 +635,7 @@ const (
const ( const (
EnumOptions_AllowAlias_field_number protoreflect.FieldNumber = 2 EnumOptions_AllowAlias_field_number protoreflect.FieldNumber = 2
EnumOptions_Deprecated_field_number protoreflect.FieldNumber = 3 EnumOptions_Deprecated_field_number protoreflect.FieldNumber = 3
EnumOptions_DeprecatedLegacyJsonFieldConflicts_field_number protoreflect.FieldNumber = 6
EnumOptions_UninterpretedOption_field_number protoreflect.FieldNumber = 999 EnumOptions_UninterpretedOption_field_number protoreflect.FieldNumber = 999
) )
@ -813,11 +846,13 @@ const (
GeneratedCodeInfo_Annotation_SourceFile_field_name protoreflect.Name = "source_file" GeneratedCodeInfo_Annotation_SourceFile_field_name protoreflect.Name = "source_file"
GeneratedCodeInfo_Annotation_Begin_field_name protoreflect.Name = "begin" GeneratedCodeInfo_Annotation_Begin_field_name protoreflect.Name = "begin"
GeneratedCodeInfo_Annotation_End_field_name protoreflect.Name = "end" GeneratedCodeInfo_Annotation_End_field_name protoreflect.Name = "end"
GeneratedCodeInfo_Annotation_Semantic_field_name protoreflect.Name = "semantic"
GeneratedCodeInfo_Annotation_Path_field_fullname protoreflect.FullName = "google.protobuf.GeneratedCodeInfo.Annotation.path" GeneratedCodeInfo_Annotation_Path_field_fullname protoreflect.FullName = "google.protobuf.GeneratedCodeInfo.Annotation.path"
GeneratedCodeInfo_Annotation_SourceFile_field_fullname protoreflect.FullName = "google.protobuf.GeneratedCodeInfo.Annotation.source_file" GeneratedCodeInfo_Annotation_SourceFile_field_fullname protoreflect.FullName = "google.protobuf.GeneratedCodeInfo.Annotation.source_file"
GeneratedCodeInfo_Annotation_Begin_field_fullname protoreflect.FullName = "google.protobuf.GeneratedCodeInfo.Annotation.begin" GeneratedCodeInfo_Annotation_Begin_field_fullname protoreflect.FullName = "google.protobuf.GeneratedCodeInfo.Annotation.begin"
GeneratedCodeInfo_Annotation_End_field_fullname protoreflect.FullName = "google.protobuf.GeneratedCodeInfo.Annotation.end" GeneratedCodeInfo_Annotation_End_field_fullname protoreflect.FullName = "google.protobuf.GeneratedCodeInfo.Annotation.end"
GeneratedCodeInfo_Annotation_Semantic_field_fullname protoreflect.FullName = "google.protobuf.GeneratedCodeInfo.Annotation.semantic"
) )
// Field numbers for google.protobuf.GeneratedCodeInfo.Annotation. // Field numbers for google.protobuf.GeneratedCodeInfo.Annotation.
@ -826,4 +861,11 @@ const (
GeneratedCodeInfo_Annotation_SourceFile_field_number protoreflect.FieldNumber = 2 GeneratedCodeInfo_Annotation_SourceFile_field_number protoreflect.FieldNumber = 2
GeneratedCodeInfo_Annotation_Begin_field_number protoreflect.FieldNumber = 3 GeneratedCodeInfo_Annotation_Begin_field_number protoreflect.FieldNumber = 3
GeneratedCodeInfo_Annotation_End_field_number protoreflect.FieldNumber = 4 GeneratedCodeInfo_Annotation_End_field_number protoreflect.FieldNumber = 4
GeneratedCodeInfo_Annotation_Semantic_field_number protoreflect.FieldNumber = 5
)
// Full and short names for google.protobuf.GeneratedCodeInfo.Annotation.Semantic.
const (
GeneratedCodeInfo_Annotation_Semantic_enum_fullname = "google.protobuf.GeneratedCodeInfo.Annotation.Semantic"
GeneratedCodeInfo_Annotation_Semantic_enum_name = "Semantic"
) )

View File

@ -59,7 +59,6 @@ func NewConverter(t reflect.Type, fd protoreflect.FieldDescriptor) Converter {
default: default:
return newSingularConverter(t, fd) return newSingularConverter(t, fd)
} }
panic(fmt.Sprintf("invalid Go type %v for field %v", t, fd.FullName()))
} }
var ( var (

View File

@ -87,7 +87,7 @@ func (sb *Builder) grow(n int) {
// Unlike strings.Builder, we do not need to copy over the contents // Unlike strings.Builder, we do not need to copy over the contents
// of the old buffer since our builder provides no API for // of the old buffer since our builder provides no API for
// retrieving previously created strings. // retrieving previously created strings.
sb.buf = make([]byte, 2*(cap(sb.buf)+n)) sb.buf = make([]byte, 0, 2*(cap(sb.buf)+n))
} }
func (sb *Builder) last(n int) string { func (sb *Builder) last(n int) string {

View File

@ -51,8 +51,8 @@ import (
// 10. Send out the CL for review and submit it. // 10. Send out the CL for review and submit it.
const ( const (
Major = 1 Major = 1
Minor = 28 Minor = 30
Patch = 1 Patch = 0
PreRelease = "" PreRelease = ""
) )

View File

@ -5,16 +5,13 @@
// Package proto provides functions operating on protocol buffer messages. // Package proto provides functions operating on protocol buffer messages.
// //
// For documentation on protocol buffers in general, see: // For documentation on protocol buffers in general, see:
// // https://protobuf.dev.
// https://developers.google.com/protocol-buffers
// //
// For a tutorial on using protocol buffers with Go, see: // For a tutorial on using protocol buffers with Go, see:
// // https://protobuf.dev/getting-started/gotutorial.
// https://developers.google.com/protocol-buffers/docs/gotutorial
// //
// For a guide to generated Go protocol buffer code, see: // For a guide to generated Go protocol buffer code, see:
// // https://protobuf.dev/reference/go/go-generated.
// https://developers.google.com/protocol-buffers/docs/reference/go-generated
// //
// # Binary serialization // # Binary serialization
// //

View File

@ -5,30 +5,39 @@
package proto package proto
import ( import (
"bytes"
"math"
"reflect" "reflect"
"google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoreflect"
) )
// Equal reports whether two messages are equal. // Equal reports whether two messages are equal,
// If two messages marshal to the same bytes under deterministic serialization, // by recursively comparing the fields of the message.
// then Equal is guaranteed to report true.
// //
// Two messages are equal if they belong to the same message descriptor, // - Bytes fields are equal if they contain identical bytes.
// have the same set of populated known and extension field values, // Empty bytes (regardless of nil-ness) are considered equal.
// and the same set of unknown fields values. If either of the top-level
// messages are invalid, then Equal reports true only if both are invalid.
// //
// Scalar values are compared with the equivalent of the == operator in Go, // - Floating-point fields are equal if they contain the same value.
// except bytes values which are compared using bytes.Equal and // Unlike the == operator, a NaN is equal to another NaN.
// floating point values which specially treat NaNs as equal. //
// Message values are compared by recursively calling Equal. // - Other scalar fields are equal if they contain the same value.
// Lists are equal if each element value is also equal. //
// Maps are equal if they have the same set of keys, where the pair of values // - Message fields are equal if they have
// for each key is also equal. // the same set of populated known and extension field values, and
// the same set of unknown fields values.
//
// - Lists are equal if they are the same length and
// each corresponding element is equal.
//
// - Maps are equal if they have the same set of keys and
// the corresponding value for each key is equal.
//
// An invalid message is not equal to a valid message.
// An invalid message is only equal to another invalid message of the
// same type. An invalid message often corresponds to a nil pointer
// of the concrete message type. For example, (*pb.M)(nil) is not equal
// to &pb.M{}.
// If two valid messages marshal to the same bytes under deterministic
// serialization, then Equal is guaranteed to report true.
func Equal(x, y Message) bool { func Equal(x, y Message) bool {
if x == nil || y == nil { if x == nil || y == nil {
return x == nil && y == nil return x == nil && y == nil
@ -42,130 +51,7 @@ func Equal(x, y Message) bool {
if mx.IsValid() != my.IsValid() { if mx.IsValid() != my.IsValid() {
return false return false
} }
return equalMessage(mx, my) vx := protoreflect.ValueOfMessage(mx)
} vy := protoreflect.ValueOfMessage(my)
return vx.Equal(vy)
// equalMessage compares two messages.
func equalMessage(mx, my protoreflect.Message) bool {
if mx.Descriptor() != my.Descriptor() {
return false
}
nx := 0
equal := true
mx.Range(func(fd protoreflect.FieldDescriptor, vx protoreflect.Value) bool {
nx++
vy := my.Get(fd)
equal = my.Has(fd) && equalField(fd, vx, vy)
return equal
})
if !equal {
return false
}
ny := 0
my.Range(func(fd protoreflect.FieldDescriptor, vx protoreflect.Value) bool {
ny++
return true
})
if nx != ny {
return false
}
return equalUnknown(mx.GetUnknown(), my.GetUnknown())
}
// equalField compares two fields.
func equalField(fd protoreflect.FieldDescriptor, x, y protoreflect.Value) bool {
switch {
case fd.IsList():
return equalList(fd, x.List(), y.List())
case fd.IsMap():
return equalMap(fd, x.Map(), y.Map())
default:
return equalValue(fd, x, y)
}
}
// equalMap compares two maps.
func equalMap(fd protoreflect.FieldDescriptor, x, y protoreflect.Map) bool {
if x.Len() != y.Len() {
return false
}
equal := true
x.Range(func(k protoreflect.MapKey, vx protoreflect.Value) bool {
vy := y.Get(k)
equal = y.Has(k) && equalValue(fd.MapValue(), vx, vy)
return equal
})
return equal
}
// equalList compares two lists.
func equalList(fd protoreflect.FieldDescriptor, x, y protoreflect.List) bool {
if x.Len() != y.Len() {
return false
}
for i := x.Len() - 1; i >= 0; i-- {
if !equalValue(fd, x.Get(i), y.Get(i)) {
return false
}
}
return true
}
// equalValue compares two singular values.
func equalValue(fd protoreflect.FieldDescriptor, x, y protoreflect.Value) bool {
switch fd.Kind() {
case protoreflect.BoolKind:
return x.Bool() == y.Bool()
case protoreflect.EnumKind:
return x.Enum() == y.Enum()
case protoreflect.Int32Kind, protoreflect.Sint32Kind,
protoreflect.Int64Kind, protoreflect.Sint64Kind,
protoreflect.Sfixed32Kind, protoreflect.Sfixed64Kind:
return x.Int() == y.Int()
case protoreflect.Uint32Kind, protoreflect.Uint64Kind,
protoreflect.Fixed32Kind, protoreflect.Fixed64Kind:
return x.Uint() == y.Uint()
case protoreflect.FloatKind, protoreflect.DoubleKind:
fx := x.Float()
fy := y.Float()
if math.IsNaN(fx) || math.IsNaN(fy) {
return math.IsNaN(fx) && math.IsNaN(fy)
}
return fx == fy
case protoreflect.StringKind:
return x.String() == y.String()
case protoreflect.BytesKind:
return bytes.Equal(x.Bytes(), y.Bytes())
case protoreflect.MessageKind, protoreflect.GroupKind:
return equalMessage(x.Message(), y.Message())
default:
return x.Interface() == y.Interface()
}
}
// equalUnknown compares unknown fields by direct comparison on the raw bytes
// of each individual field number.
func equalUnknown(x, y protoreflect.RawFields) bool {
if len(x) != len(y) {
return false
}
if bytes.Equal([]byte(x), []byte(y)) {
return true
}
mx := make(map[protoreflect.FieldNumber]protoreflect.RawFields)
my := make(map[protoreflect.FieldNumber]protoreflect.RawFields)
for len(x) > 0 {
fnum, _, n := protowire.ConsumeField(x)
mx[fnum] = append(mx[fnum], x[:n]...)
x = x[n:]
}
for len(y) > 0 {
fnum, _, n := protowire.ConsumeField(y)
my[fnum] = append(my[fnum], y[:n]...)
y = y[n:]
}
return reflect.DeepEqual(mx, my)
} }

View File

@ -35,6 +35,8 @@ func (p *SourcePath) appendFileDescriptorProto(b []byte) []byte {
b = p.appendSingularField(b, "source_code_info", (*SourcePath).appendSourceCodeInfo) b = p.appendSingularField(b, "source_code_info", (*SourcePath).appendSourceCodeInfo)
case 12: case 12:
b = p.appendSingularField(b, "syntax", nil) b = p.appendSingularField(b, "syntax", nil)
case 13:
b = p.appendSingularField(b, "edition", nil)
} }
return b return b
} }
@ -236,6 +238,8 @@ func (p *SourcePath) appendMessageOptions(b []byte) []byte {
b = p.appendSingularField(b, "deprecated", nil) b = p.appendSingularField(b, "deprecated", nil)
case 7: case 7:
b = p.appendSingularField(b, "map_entry", nil) b = p.appendSingularField(b, "map_entry", nil)
case 11:
b = p.appendSingularField(b, "deprecated_legacy_json_field_conflicts", nil)
case 999: case 999:
b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption) b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption)
} }
@ -279,6 +283,8 @@ func (p *SourcePath) appendEnumOptions(b []byte) []byte {
b = p.appendSingularField(b, "allow_alias", nil) b = p.appendSingularField(b, "allow_alias", nil)
case 3: case 3:
b = p.appendSingularField(b, "deprecated", nil) b = p.appendSingularField(b, "deprecated", nil)
case 6:
b = p.appendSingularField(b, "deprecated_legacy_json_field_conflicts", nil)
case 999: case 999:
b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption) b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption)
} }
@ -345,10 +351,18 @@ func (p *SourcePath) appendFieldOptions(b []byte) []byte {
b = p.appendSingularField(b, "jstype", nil) b = p.appendSingularField(b, "jstype", nil)
case 5: case 5:
b = p.appendSingularField(b, "lazy", nil) b = p.appendSingularField(b, "lazy", nil)
case 15:
b = p.appendSingularField(b, "unverified_lazy", nil)
case 3: case 3:
b = p.appendSingularField(b, "deprecated", nil) b = p.appendSingularField(b, "deprecated", nil)
case 10: case 10:
b = p.appendSingularField(b, "weak", nil) b = p.appendSingularField(b, "weak", nil)
case 16:
b = p.appendSingularField(b, "debug_redact", nil)
case 17:
b = p.appendSingularField(b, "retention", nil)
case 18:
b = p.appendSingularField(b, "target", nil)
case 999: case 999:
b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption) b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption)
} }

View File

@ -148,7 +148,7 @@ type Message interface {
// be preserved in marshaling or other operations. // be preserved in marshaling or other operations.
IsValid() bool IsValid() bool
// ProtoMethods returns optional fast-path implementions of various operations. // ProtoMethods returns optional fast-path implementations of various operations.
// This method may return nil. // This method may return nil.
// //
// The returned methods type is identical to // The returned methods type is identical to

View File

@ -0,0 +1,168 @@
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package protoreflect
import (
"bytes"
"fmt"
"math"
"reflect"
"google.golang.org/protobuf/encoding/protowire"
)
// Equal reports whether v1 and v2 are recursively equal.
//
// - Values of different types are always unequal.
//
// - Bytes values are equal if they contain identical bytes.
// Empty bytes (regardless of nil-ness) are considered equal.
//
// - Floating point values are equal if they contain the same value.
// Unlike the == operator, a NaN is equal to another NaN.
//
// - Enums are equal if they contain the same number.
// Since Value does not contain an enum descriptor,
// enum values do not consider the type of the enum.
//
// - Other scalar values are equal if they contain the same value.
//
// - Message values are equal if they belong to the same message descriptor,
// have the same set of populated known and extension field values,
// and the same set of unknown fields values.
//
// - Lists are equal if they are the same length and
// each corresponding element is equal.
//
// - Maps are equal if they have the same set of keys and
// the corresponding value for each key is equal.
func (v1 Value) Equal(v2 Value) bool {
return equalValue(v1, v2)
}
func equalValue(x, y Value) bool {
eqType := x.typ == y.typ
switch x.typ {
case nilType:
return eqType
case boolType:
return eqType && x.Bool() == y.Bool()
case int32Type, int64Type:
return eqType && x.Int() == y.Int()
case uint32Type, uint64Type:
return eqType && x.Uint() == y.Uint()
case float32Type, float64Type:
return eqType && equalFloat(x.Float(), y.Float())
case stringType:
return eqType && x.String() == y.String()
case bytesType:
return eqType && bytes.Equal(x.Bytes(), y.Bytes())
case enumType:
return eqType && x.Enum() == y.Enum()
default:
switch x := x.Interface().(type) {
case Message:
y, ok := y.Interface().(Message)
return ok && equalMessage(x, y)
case List:
y, ok := y.Interface().(List)
return ok && equalList(x, y)
case Map:
y, ok := y.Interface().(Map)
return ok && equalMap(x, y)
default:
panic(fmt.Sprintf("unknown type: %T", x))
}
}
}
// equalFloat compares two floats, where NaNs are treated as equal.
func equalFloat(x, y float64) bool {
if math.IsNaN(x) || math.IsNaN(y) {
return math.IsNaN(x) && math.IsNaN(y)
}
return x == y
}
// equalMessage compares two messages.
func equalMessage(mx, my Message) bool {
if mx.Descriptor() != my.Descriptor() {
return false
}
nx := 0
equal := true
mx.Range(func(fd FieldDescriptor, vx Value) bool {
nx++
vy := my.Get(fd)
equal = my.Has(fd) && equalValue(vx, vy)
return equal
})
if !equal {
return false
}
ny := 0
my.Range(func(fd FieldDescriptor, vx Value) bool {
ny++
return true
})
if nx != ny {
return false
}
return equalUnknown(mx.GetUnknown(), my.GetUnknown())
}
// equalList compares two lists.
func equalList(x, y List) bool {
if x.Len() != y.Len() {
return false
}
for i := x.Len() - 1; i >= 0; i-- {
if !equalValue(x.Get(i), y.Get(i)) {
return false
}
}
return true
}
// equalMap compares two maps.
func equalMap(x, y Map) bool {
if x.Len() != y.Len() {
return false
}
equal := true
x.Range(func(k MapKey, vx Value) bool {
vy := y.Get(k)
equal = y.Has(k) && equalValue(vx, vy)
return equal
})
return equal
}
// equalUnknown compares unknown fields by direct comparison on the raw bytes
// of each individual field number.
func equalUnknown(x, y RawFields) bool {
if len(x) != len(y) {
return false
}
if bytes.Equal([]byte(x), []byte(y)) {
return true
}
mx := make(map[FieldNumber]RawFields)
my := make(map[FieldNumber]RawFields)
for len(x) > 0 {
fnum, _, n := protowire.ConsumeField(x)
mx[fnum] = append(mx[fnum], x[:n]...)
x = x[n:]
}
for len(y) > 0 {
fnum, _, n := protowire.ConsumeField(y)
my[fnum] = append(my[fnum], y[:n]...)
y = y[n:]
}
return reflect.DeepEqual(mx, my)
}

View File

@ -54,11 +54,11 @@ import (
// // Append a 0 to a "repeated int32" field. // // Append a 0 to a "repeated int32" field.
// // Since the Value returned by Mutable is guaranteed to alias // // Since the Value returned by Mutable is guaranteed to alias
// // the source message, modifying the Value modifies the message. // // the source message, modifying the Value modifies the message.
// message.Mutable(fieldDesc).(List).Append(protoreflect.ValueOfInt32(0)) // message.Mutable(fieldDesc).List().Append(protoreflect.ValueOfInt32(0))
// //
// // Assign [0] to a "repeated int32" field by creating a new Value, // // Assign [0] to a "repeated int32" field by creating a new Value,
// // modifying it, and assigning it. // // modifying it, and assigning it.
// list := message.NewField(fieldDesc).(List) // list := message.NewField(fieldDesc).List()
// list.Append(protoreflect.ValueOfInt32(0)) // list.Append(protoreflect.ValueOfInt32(0))
// message.Set(fieldDesc, list) // message.Set(fieldDesc, list)
// // ERROR: Since it is not defined whether Set aliases the source, // // ERROR: Since it is not defined whether Set aliases the source,

View File

@ -46,7 +46,7 @@ var conflictPolicy = "panic" // "panic" | "warn" | "ignore"
// It is a variable so that the behavior is easily overridden in another file. // It is a variable so that the behavior is easily overridden in another file.
var ignoreConflict = func(d protoreflect.Descriptor, err error) bool { var ignoreConflict = func(d protoreflect.Descriptor, err error) bool {
const env = "GOLANG_PROTOBUF_REGISTRATION_CONFLICT" const env = "GOLANG_PROTOBUF_REGISTRATION_CONFLICT"
const faq = "https://developers.google.com/protocol-buffers/docs/reference/go/faq#namespace-conflict" const faq = "https://protobuf.dev/reference/go/faq#namespace-conflict"
policy := conflictPolicy policy := conflictPolicy
if v := os.Getenv(env); v != "" { if v := os.Getenv(env); v != "" {
policy = v policy = v

File diff suppressed because it is too large Load Diff

View File

@ -37,8 +37,7 @@
// It is functionally a tuple of the full name of the remote message type and // It is functionally a tuple of the full name of the remote message type and
// the serialized bytes of the remote message value. // the serialized bytes of the remote message value.
// //
// // # Constructing an Any
// Constructing an Any
// //
// An Any message containing another message value is constructed using New: // An Any message containing another message value is constructed using New:
// //
@ -48,8 +47,7 @@
// } // }
// ... // make use of any // ... // make use of any
// //
// // # Unmarshaling an Any
// Unmarshaling an Any
// //
// With a populated Any message, the underlying message can be serialized into // With a populated Any message, the underlying message can be serialized into
// a remote concrete message value in a few ways. // a remote concrete message value in a few ways.
@ -95,8 +93,7 @@
// listed in the case clauses are linked into the Go binary and therefore also // listed in the case clauses are linked into the Go binary and therefore also
// registered in the global registry. // registered in the global registry.
// //
// // # Type checking an Any
// Type checking an Any
// //
// In order to type check whether an Any message represents some other message, // In order to type check whether an Any message represents some other message,
// then use the MessageIs method: // then use the MessageIs method:
@ -115,7 +112,6 @@
// } // }
// ... // make use of m // ... // make use of m
// } // }
//
package anypb package anypb
import ( import (
@ -152,6 +148,10 @@ import (
// if (any.is(Foo.class)) { // if (any.is(Foo.class)) {
// foo = any.unpack(Foo.class); // foo = any.unpack(Foo.class);
// } // }
// // or ...
// if (any.isSameTypeAs(Foo.getDefaultInstance())) {
// foo = any.unpack(Foo.getDefaultInstance());
// }
// //
// Example 3: Pack and unpack a message in Python. // Example 3: Pack and unpack a message in Python.
// //
@ -182,9 +182,8 @@ import (
// in the type URL, for example "foo.bar.com/x/y.z" will yield type // in the type URL, for example "foo.bar.com/x/y.z" will yield type
// name "y.z". // name "y.z".
// //
// # JSON
// //
// JSON
// ====
// The JSON representation of an `Any` value uses the regular // The JSON representation of an `Any` value uses the regular
// representation of the deserialized, embedded message, with an // representation of the deserialized, embedded message, with an
// additional field `@type` which contains the type URL. Example: // additional field `@type` which contains the type URL. Example:
@ -210,7 +209,6 @@ import (
// "@type": "type.googleapis.com/google.protobuf.Duration", // "@type": "type.googleapis.com/google.protobuf.Duration",
// "value": "1.212s" // "value": "1.212s"
// } // }
//
type Any struct { type Any struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@ -228,10 +226,10 @@ type Any struct {
// scheme `http`, `https`, or no scheme, one can optionally set up a type // scheme `http`, `https`, or no scheme, one can optionally set up a type
// server that maps type URLs to message definitions as follows: // server that maps type URLs to message definitions as follows:
// //
// * If no scheme is provided, `https` is assumed. // - If no scheme is provided, `https` is assumed.
// * An HTTP GET on the URL must yield a [google.protobuf.Type][] // - An HTTP GET on the URL must yield a [google.protobuf.Type][]
// value in binary format, or produce an error. // value in binary format, or produce an error.
// * Applications are allowed to cache lookup results based on the // - Applications are allowed to cache lookup results based on the
// URL, or have them precompiled into a binary to avoid any // URL, or have them precompiled into a binary to avoid any
// lookup. Therefore, binary compatibility needs to be preserved // lookup. Therefore, binary compatibility needs to be preserved
// on changes to types. (Use versioned type names to manage // on changes to types. (Use versioned type names to manage
@ -243,7 +241,6 @@ type Any struct {
// //
// Schemes other than `http`, `https` (or the empty scheme) might be // Schemes other than `http`, `https` (or the empty scheme) might be
// used with implementation specific semantics. // used with implementation specific semantics.
//
TypeUrl string `protobuf:"bytes,1,opt,name=type_url,json=typeUrl,proto3" json:"type_url,omitempty"` TypeUrl string `protobuf:"bytes,1,opt,name=type_url,json=typeUrl,proto3" json:"type_url,omitempty"`
// Must be a valid serialized protocol buffer of the above specified type. // Must be a valid serialized protocol buffer of the above specified type.
Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`

View File

@ -35,8 +35,7 @@
// //
// The Duration message represents a signed span of time. // The Duration message represents a signed span of time.
// //
// // # Conversion to a Go Duration
// Conversion to a Go Duration
// //
// The AsDuration method can be used to convert a Duration message to a // The AsDuration method can be used to convert a Duration message to a
// standard Go time.Duration value: // standard Go time.Duration value:
@ -65,15 +64,13 @@
// the resulting value to the closest representable value (e.g., math.MaxInt64 // the resulting value to the closest representable value (e.g., math.MaxInt64
// for positive overflow and math.MinInt64 for negative overflow). // for positive overflow and math.MinInt64 for negative overflow).
// //
// // # Conversion from a Go Duration
// Conversion from a Go Duration
// //
// The durationpb.New function can be used to construct a Duration message // The durationpb.New function can be used to construct a Duration message
// from a standard Go time.Duration value: // from a standard Go time.Duration value:
// //
// dur := durationpb.New(d) // dur := durationpb.New(d)
// ... // make use of d as a *durationpb.Duration // ... // make use of d as a *durationpb.Duration
//
package durationpb package durationpb
import ( import (
@ -143,8 +140,6 @@ import (
// encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should // encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should
// be expressed in JSON format as "3.000000001s", and 3 seconds and 1 // be expressed in JSON format as "3.000000001s", and 3 seconds and 1
// microsecond should be expressed in JSON format as "3.000001s". // microsecond should be expressed in JSON format as "3.000001s".
//
//
type Duration struct { type Duration struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache

View File

@ -37,8 +37,7 @@
// The paths are specific to some target message type, // The paths are specific to some target message type,
// which is not stored within the FieldMask message itself. // which is not stored within the FieldMask message itself.
// //
// // # Constructing a FieldMask
// Constructing a FieldMask
// //
// The New function is used construct a FieldMask: // The New function is used construct a FieldMask:
// //
@ -61,8 +60,7 @@
// ... // handle error // ... // handle error
// } // }
// //
// // # Type checking a FieldMask
// Type checking a FieldMask
// //
// In order to verify that a FieldMask represents a set of fields that are // In order to verify that a FieldMask represents a set of fields that are
// reachable from some target message type, use the IsValid method: // reachable from some target message type, use the IsValid method:
@ -121,7 +119,6 @@ import (
// (their value will be set to the default, and omitted in proto text // (their value will be set to the default, and omitted in proto text
// output): // output):
// //
//
// f { // f {
// a : 22 // a : 22
// b { // b {

View File

@ -44,8 +44,7 @@
// "google.golang.org/protobuf/encoding/protojson" package // "google.golang.org/protobuf/encoding/protojson" package
// ensures that they will be serialized as their JSON equivalent. // ensures that they will be serialized as their JSON equivalent.
// //
// // # Conversion to and from a Go interface
// Conversion to and from a Go interface
// //
// The standard Go "encoding/json" package has functionality to serialize // The standard Go "encoding/json" package has functionality to serialize
// arbitrary types to a large degree. The Value.AsInterface, Struct.AsMap, and // arbitrary types to a large degree. The Value.AsInterface, Struct.AsMap, and
@ -58,8 +57,7 @@
// forms back as Value, Struct, and ListValue messages, use the NewStruct, // forms back as Value, Struct, and ListValue messages, use the NewStruct,
// NewList, and NewValue constructor functions. // NewList, and NewValue constructor functions.
// //
// // # Example usage
// Example usage
// //
// Consider the following example JSON object: // Consider the following example JSON object:
// //
@ -118,7 +116,6 @@
// ... // handle error // ... // handle error
// } // }
// ... // make use of m as a *structpb.Value // ... // make use of m as a *structpb.Value
//
package structpb package structpb
import ( import (
@ -218,8 +215,9 @@ func NewStruct(v map[string]interface{}) (*Struct, error) {
// AsMap converts x to a general-purpose Go map. // AsMap converts x to a general-purpose Go map.
// The map values are converted by calling Value.AsInterface. // The map values are converted by calling Value.AsInterface.
func (x *Struct) AsMap() map[string]interface{} { func (x *Struct) AsMap() map[string]interface{} {
vs := make(map[string]interface{}) f := x.GetFields()
for k, v := range x.GetFields() { vs := make(map[string]interface{}, len(f))
for k, v := range f {
vs[k] = v.AsInterface() vs[k] = v.AsInterface()
} }
return vs return vs
@ -274,8 +272,8 @@ func (x *Struct) GetFields() map[string]*Value {
// `Value` represents a dynamically typed value which can be either // `Value` represents a dynamically typed value which can be either
// null, a number, a string, a boolean, a recursive struct value, or a // null, a number, a string, a boolean, a recursive struct value, or a
// list of values. A producer of value is expected to set one of that // list of values. A producer of value is expected to set one of these
// variants, absence of any variant indicates an error. // variants. Absence of any variant indicates an error.
// //
// The JSON representation for `Value` is JSON value. // The JSON representation for `Value` is JSON value.
type Value struct { type Value struct {
@ -286,6 +284,7 @@ type Value struct {
// The kind of value. // The kind of value.
// //
// Types that are assignable to Kind: // Types that are assignable to Kind:
//
// *Value_NullValue // *Value_NullValue
// *Value_NumberValue // *Value_NumberValue
// *Value_StringValue // *Value_StringValue
@ -596,8 +595,9 @@ func NewList(v []interface{}) (*ListValue, error) {
// AsSlice converts x to a general-purpose Go slice. // AsSlice converts x to a general-purpose Go slice.
// The slice elements are converted by calling Value.AsInterface. // The slice elements are converted by calling Value.AsInterface.
func (x *ListValue) AsSlice() []interface{} { func (x *ListValue) AsSlice() []interface{} {
vs := make([]interface{}, len(x.GetValues())) vals := x.GetValues()
for i, v := range x.GetValues() { vs := make([]interface{}, len(vals))
for i, v := range vals {
vs[i] = v.AsInterface() vs[i] = v.AsInterface()
} }
return vs return vs

View File

@ -36,8 +36,7 @@
// The Timestamp message represents a timestamp, // The Timestamp message represents a timestamp,
// an instant in time since the Unix epoch (January 1st, 1970). // an instant in time since the Unix epoch (January 1st, 1970).
// //
// // # Conversion to a Go Time
// Conversion to a Go Time
// //
// The AsTime method can be used to convert a Timestamp message to a // The AsTime method can be used to convert a Timestamp message to a
// standard Go time.Time value in UTC: // standard Go time.Time value in UTC:
@ -59,8 +58,7 @@
// ... // handle error // ... // handle error
// } // }
// //
// // # Conversion from a Go Time
// Conversion from a Go Time
// //
// The timestamppb.New function can be used to construct a Timestamp message // The timestamppb.New function can be used to construct a Timestamp message
// from a standard Go time.Time value: // from a standard Go time.Time value:
@ -72,7 +70,6 @@
// //
// ts := timestamppb.Now() // ts := timestamppb.Now()
// ... // make use of ts as a *timestamppb.Timestamp // ... // make use of ts as a *timestamppb.Timestamp
//
package timestamppb package timestamppb
import ( import (
@ -133,7 +130,6 @@ import (
// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) // Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
// .setNanos((int) ((millis % 1000) * 1000000)).build(); // .setNanos((int) ((millis % 1000) * 1000000)).build();
// //
//
// Example 5: Compute Timestamp from Java `Instant.now()`. // Example 5: Compute Timestamp from Java `Instant.now()`.
// //
// Instant now = Instant.now(); // Instant now = Instant.now();
@ -142,7 +138,6 @@ import (
// Timestamp.newBuilder().setSeconds(now.getEpochSecond()) // Timestamp.newBuilder().setSeconds(now.getEpochSecond())
// .setNanos(now.getNano()).build(); // .setNanos(now.getNano()).build();
// //
//
// Example 6: Compute Timestamp from current time in Python. // Example 6: Compute Timestamp from current time in Python.
// //
// timestamp = Timestamp() // timestamp = Timestamp()
@ -174,8 +169,6 @@ import (
// the Joda Time's [`ISODateTimeFormat.dateTime()`]( // the Joda Time's [`ISODateTimeFormat.dateTime()`](
// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D // http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D
// ) to obtain a formatter capable of generating timestamps in this format. // ) to obtain a formatter capable of generating timestamps in this format.
//
//
type Timestamp struct { type Timestamp struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache

View File

@ -27,7 +27,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Wrappers for primitive (non-message) types. These types are useful // Wrappers for primitive (non-message) types. These types are useful
// for embedding primitives in the `google.protobuf.Any` type and for places // for embedding primitives in the `google.protobuf.Any` type and for places
// where we need to distinguish between the absence of a primitive // where we need to distinguish between the absence of a primitive

2
vendor/modules.txt vendored
View File

@ -686,7 +686,7 @@ google.golang.org/grpc/serviceconfig
google.golang.org/grpc/stats google.golang.org/grpc/stats
google.golang.org/grpc/status google.golang.org/grpc/status
google.golang.org/grpc/tap google.golang.org/grpc/tap
# google.golang.org/protobuf v1.28.1 # google.golang.org/protobuf v1.30.0
## explicit; go 1.11 ## explicit; go 1.11
google.golang.org/protobuf/encoding/protojson google.golang.org/protobuf/encoding/protojson
google.golang.org/protobuf/encoding/prototext google.golang.org/protobuf/encoding/prototext