gRPC migration
Change-Id: Ib390f6dde0d5a8d6db12ccd7da41135570ad1354
diff --git a/vendor/google.golang.org/protobuf/encoding/prototext/decode.go b/vendor/google.golang.org/protobuf/encoding/prototext/decode.go
index 77dbe1b..179d6e8 100644
--- a/vendor/google.golang.org/protobuf/encoding/prototext/decode.go
+++ b/vendor/google.golang.org/protobuf/encoding/prototext/decode.go
@@ -6,14 +6,13 @@
import (
"fmt"
- "strings"
"unicode/utf8"
"google.golang.org/protobuf/internal/encoding/messageset"
"google.golang.org/protobuf/internal/encoding/text"
"google.golang.org/protobuf/internal/errors"
- "google.golang.org/protobuf/internal/fieldnum"
"google.golang.org/protobuf/internal/flags"
+ "google.golang.org/protobuf/internal/genid"
"google.golang.org/protobuf/internal/pragma"
"google.golang.org/protobuf/internal/set"
"google.golang.org/protobuf/internal/strs"
@@ -23,6 +22,7 @@
)
// Unmarshal reads the given []byte into the given proto.Message.
+// The provided message must be mutable (e.g., a non-nil pointer to a message).
func Unmarshal(b []byte, m proto.Message) error {
return UnmarshalOptions{}.Unmarshal(b, m)
}
@@ -51,9 +51,17 @@
}
}
-// Unmarshal reads the given []byte and populates the given proto.Message using options in
-// UnmarshalOptions object.
+// Unmarshal reads the given []byte and populates the given proto.Message
+// using options in the UnmarshalOptions object.
+// The provided message must be mutable (e.g., a non-nil pointer to a message).
func (o UnmarshalOptions) Unmarshal(b []byte, m proto.Message) error {
+ return o.unmarshal(b, m)
+}
+
+// unmarshal is a centralized function that all unmarshal operations go through.
+// For profiling purposes, avoid changing the name of this function or
+// introducing other code paths for unmarshal that do not go through this.
+func (o UnmarshalOptions) unmarshal(b []byte, m proto.Message) error {
proto.Reset(m)
if o.Resolver == nil {
@@ -101,7 +109,7 @@
return errors.New("no support for proto1 MessageSets")
}
- if messageDesc.FullName() == "google.protobuf.Any" {
+ if messageDesc.FullName() == genid.Any_message_fullname {
return d.unmarshalAny(m, checkDelims)
}
@@ -151,21 +159,11 @@
switch tok.NameKind() {
case text.IdentName:
name = pref.Name(tok.IdentName())
- fd = fieldDescs.ByName(name)
- if fd == nil {
- // The proto name of a group field is in all lowercase,
- // while the textproto field name is the group message name.
- gd := fieldDescs.ByName(pref.Name(strings.ToLower(string(name))))
- if gd != nil && gd.Kind() == pref.GroupKind && gd.Message().Name() == name {
- fd = gd
- }
- } else if fd.Kind() == pref.GroupKind && fd.Message().Name() != name {
- fd = nil // reset since field name is actually the message name
- }
+ fd = fieldDescs.ByTextName(string(name))
case text.TypeName:
// Handle extensions only. This code path is not for Any.
- xt, xtErr = d.findExtension(pref.FullName(tok.TypeName()))
+ xt, xtErr = d.opts.Resolver.FindExtensionByName(pref.FullName(tok.TypeName()))
case text.FieldNumber:
isFieldNumberName = true
@@ -262,15 +260,6 @@
return nil
}
-// findExtension returns protoreflect.ExtensionType from the Resolver if found.
-func (d decoder) findExtension(xtName pref.FullName) (pref.ExtensionType, error) {
- xt, err := d.opts.Resolver.FindExtensionByName(xtName)
- if err == nil {
- return xt, nil
- }
- return messageset.FindMessageSetExtension(d.opts.Resolver, xtName)
-}
-
// unmarshalSingular unmarshals a non-repeated field value specified by the
// given FieldDescriptor.
func (d decoder) unmarshalSingular(fd pref.FieldDescriptor, m pref.Message) error {
@@ -531,14 +520,13 @@
return d.unexpectedTokenError(tok)
}
- name := tok.IdentName()
- switch name {
- case "key":
+ switch name := pref.Name(tok.IdentName()); name {
+ case genid.MapEntry_Key_field_name:
if !tok.HasSeparator() {
return d.syntaxError(tok.Pos(), "missing field separator :")
}
if key.IsValid() {
- return d.newError(tok.Pos(), `map entry "key" cannot be repeated`)
+ return d.newError(tok.Pos(), "map entry %q cannot be repeated", name)
}
val, err := d.unmarshalScalar(fd.MapKey())
if err != nil {
@@ -546,14 +534,14 @@
}
key = val.MapKey()
- case "value":
+ case genid.MapEntry_Value_field_name:
if kind := fd.MapValue().Kind(); (kind != pref.MessageKind) && (kind != pref.GroupKind) {
if !tok.HasSeparator() {
return d.syntaxError(tok.Pos(), "missing field separator :")
}
}
if pval.IsValid() {
- return d.newError(tok.Pos(), `map entry "value" cannot be repeated`)
+ return d.newError(tok.Pos(), "map entry %q cannot be repeated", name)
}
pval, err = unmarshalMapValue()
if err != nil {
@@ -590,13 +578,9 @@
func (d decoder) unmarshalAny(m pref.Message, checkDelims bool) error {
var typeURL string
var bValue []byte
-
- // hasFields tracks which valid fields have been seen in the loop below in
- // order to flag an error if there are duplicates or conflicts. It may
- // contain the strings "type_url", "value" and "expanded". The literal
- // "expanded" is used to indicate that the expanded form has been
- // encountered already.
- hasFields := map[string]bool{}
+ var seenTypeUrl bool
+ var seenValue bool
+ var isExpanded bool
if checkDelims {
tok, err := d.Read()
@@ -635,12 +619,12 @@
return d.syntaxError(tok.Pos(), "missing field separator :")
}
- switch tok.IdentName() {
- case "type_url":
- if hasFields["type_url"] {
- return d.newError(tok.Pos(), "duplicate Any type_url field")
+ switch name := pref.Name(tok.IdentName()); name {
+ case genid.Any_TypeUrl_field_name:
+ if seenTypeUrl {
+ return d.newError(tok.Pos(), "duplicate %v field", genid.Any_TypeUrl_field_fullname)
}
- if hasFields["expanded"] {
+ if isExpanded {
return d.newError(tok.Pos(), "conflict with [%s] field", typeURL)
}
tok, err := d.Read()
@@ -650,15 +634,15 @@
var ok bool
typeURL, ok = tok.String()
if !ok {
- return d.newError(tok.Pos(), "invalid Any type_url: %v", tok.RawString())
+ return d.newError(tok.Pos(), "invalid %v field value: %v", genid.Any_TypeUrl_field_fullname, tok.RawString())
}
- hasFields["type_url"] = true
+ seenTypeUrl = true
- case "value":
- if hasFields["value"] {
- return d.newError(tok.Pos(), "duplicate Any value field")
+ case genid.Any_Value_field_name:
+ if seenValue {
+ return d.newError(tok.Pos(), "duplicate %v field", genid.Any_Value_field_fullname)
}
- if hasFields["expanded"] {
+ if isExpanded {
return d.newError(tok.Pos(), "conflict with [%s] field", typeURL)
}
tok, err := d.Read()
@@ -667,22 +651,22 @@
}
s, ok := tok.String()
if !ok {
- return d.newError(tok.Pos(), "invalid Any value: %v", tok.RawString())
+ return d.newError(tok.Pos(), "invalid %v field value: %v", genid.Any_Value_field_fullname, tok.RawString())
}
bValue = []byte(s)
- hasFields["value"] = true
+ seenValue = true
default:
if !d.opts.DiscardUnknown {
- return d.newError(tok.Pos(), "invalid field name %q in google.protobuf.Any message", tok.RawString())
+ return d.newError(tok.Pos(), "invalid field name %q in %v message", tok.RawString(), genid.Any_message_fullname)
}
}
case text.TypeName:
- if hasFields["expanded"] {
+ if isExpanded {
return d.newError(tok.Pos(), "cannot have more than one type")
}
- if hasFields["type_url"] {
+ if seenTypeUrl {
return d.newError(tok.Pos(), "conflict with type_url field")
}
typeURL = tok.TypeName()
@@ -691,21 +675,21 @@
if err != nil {
return err
}
- hasFields["expanded"] = true
+ isExpanded = true
default:
if !d.opts.DiscardUnknown {
- return d.newError(tok.Pos(), "invalid field name %q in google.protobuf.Any message", tok.RawString())
+ return d.newError(tok.Pos(), "invalid field name %q in %v message", tok.RawString(), genid.Any_message_fullname)
}
}
}
fds := m.Descriptor().Fields()
if len(typeURL) > 0 {
- m.Set(fds.ByNumber(fieldnum.Any_TypeUrl), pref.ValueOfString(typeURL))
+ m.Set(fds.ByNumber(genid.Any_TypeUrl_field_number), pref.ValueOfString(typeURL))
}
if len(bValue) > 0 {
- m.Set(fds.ByNumber(fieldnum.Any_Value), pref.ValueOfBytes(bValue))
+ m.Set(fds.ByNumber(genid.Any_Value_field_number), pref.ValueOfBytes(bValue))
}
return nil
}
@@ -760,9 +744,6 @@
// Skip items. This will not validate whether skipped values are
// of the same type or not, same behavior as C++
// TextFormat::Parser::AllowUnknownField(true) version 3.8.0.
- if err := d.skipValue(); err != nil {
- return err
- }
}
}
}