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
- }
}
}
}
diff --git a/vendor/google.golang.org/protobuf/encoding/prototext/encode.go b/vendor/google.golang.org/protobuf/encoding/prototext/encode.go
index dece229..8d5304d 100644
--- a/vendor/google.golang.org/protobuf/encoding/prototext/encode.go
+++ b/vendor/google.golang.org/protobuf/encoding/prototext/encode.go
@@ -6,7 +6,6 @@
import (
"fmt"
- "sort"
"strconv"
"unicode/utf8"
@@ -14,12 +13,13 @@
"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/mapsort"
+ "google.golang.org/protobuf/internal/genid"
+ "google.golang.org/protobuf/internal/order"
"google.golang.org/protobuf/internal/pragma"
"google.golang.org/protobuf/internal/strs"
"google.golang.org/protobuf/proto"
+ "google.golang.org/protobuf/reflect/protoreflect"
pref "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
)
@@ -102,6 +102,13 @@
// MarshalOptions object. Do not depend on the output being stable. It may
// change over time across different versions of the program.
func (o MarshalOptions) Marshal(m proto.Message) ([]byte, error) {
+ return o.marshal(m)
+}
+
+// marshal is a centralized function that all marshal operations go through.
+// For profiling purposes, avoid changing the name of this function or
+// introducing other code paths for marshal that do not go through this.
+func (o MarshalOptions) marshal(m proto.Message) ([]byte, error) {
var delims = [2]byte{'{', '}'}
if o.Multiline && o.Indent == "" {
@@ -155,42 +162,22 @@
}
// Handle Any expansion.
- if messageDesc.FullName() == "google.protobuf.Any" {
+ if messageDesc.FullName() == genid.Any_message_fullname {
if e.marshalAny(m) {
return nil
}
// If unable to expand, continue on to marshal Any as a regular message.
}
- // Marshal known fields.
- fieldDescs := messageDesc.Fields()
- size := fieldDescs.Len()
- for i := 0; i < size; {
- fd := fieldDescs.Get(i)
- if od := fd.ContainingOneof(); od != nil {
- fd = m.WhichOneof(od)
- i += od.Fields().Len()
- } else {
- i++
+ // Marshal fields.
+ var err error
+ order.RangeFields(m, order.IndexNameFieldOrder, func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
+ if err = e.marshalField(fd.TextName(), v, fd); err != nil {
+ return false
}
-
- if fd == nil || !m.Has(fd) {
- continue
- }
-
- name := fd.Name()
- // Use type name for group field name.
- if fd.Kind() == pref.GroupKind {
- name = fd.Message().Name()
- }
- val := m.Get(fd)
- if err := e.marshalField(string(name), val, fd); err != nil {
- return err
- }
- }
-
- // Marshal extensions.
- if err := e.marshalExtensions(m); err != nil {
+ return true
+ })
+ if err != nil {
return err
}
@@ -283,18 +270,18 @@
// marshalMap marshals the given protoreflect.Map as multiple name-value fields.
func (e encoder) marshalMap(name string, mmap pref.Map, fd pref.FieldDescriptor) error {
var err error
- mapsort.Range(mmap, fd.MapKey().Kind(), func(key pref.MapKey, val pref.Value) bool {
+ order.RangeEntries(mmap, order.GenericKeyOrder, func(key pref.MapKey, val pref.Value) bool {
e.WriteName(name)
e.StartMessage()
defer e.EndMessage()
- e.WriteName("key")
+ e.WriteName(string(genid.MapEntry_Key_field_name))
err = e.marshalSingular(key.Value(), fd.MapKey())
if err != nil {
return false
}
- e.WriteName("value")
+ e.WriteName(string(genid.MapEntry_Value_field_name))
err = e.marshalSingular(val, fd.MapValue())
if err != nil {
return false
@@ -304,48 +291,6 @@
return err
}
-// marshalExtensions marshals extension fields.
-func (e encoder) marshalExtensions(m pref.Message) error {
- type entry struct {
- key string
- value pref.Value
- desc pref.FieldDescriptor
- }
-
- // Get a sorted list based on field key first.
- var entries []entry
- m.Range(func(fd pref.FieldDescriptor, v pref.Value) bool {
- if !fd.IsExtension() {
- return true
- }
- // For MessageSet extensions, the name used is the parent message.
- name := fd.FullName()
- if messageset.IsMessageSetExtension(fd) {
- name = name.Parent()
- }
- entries = append(entries, entry{
- key: string(name),
- value: v,
- desc: fd,
- })
- return true
- })
- // Sort extensions lexicographically.
- sort.Slice(entries, func(i, j int) bool {
- return entries[i].key < entries[j].key
- })
-
- // Write out sorted list.
- for _, entry := range entries {
- // Extension field name is the proto field name enclosed in [].
- name := "[" + entry.key + "]"
- if err := e.marshalField(name, entry.value, entry.desc); err != nil {
- return err
- }
- }
- return nil
-}
-
// marshalUnknown parses the given []byte and marshals fields out.
// This function assumes proper encoding in the given []byte.
func (e encoder) marshalUnknown(b []byte) {
@@ -392,7 +337,7 @@
func (e encoder) marshalAny(any pref.Message) bool {
// Construct the embedded message.
fds := any.Descriptor().Fields()
- fdType := fds.ByNumber(fieldnum.Any_TypeUrl)
+ fdType := fds.ByNumber(genid.Any_TypeUrl_field_number)
typeURL := any.Get(fdType).String()
mt, err := e.opts.Resolver.FindMessageByURL(typeURL)
if err != nil {
@@ -401,7 +346,7 @@
m := mt.New().Interface()
// Unmarshal bytes into embedded message.
- fdValue := fds.ByNumber(fieldnum.Any_Value)
+ fdValue := fds.ByNumber(genid.Any_Value_field_number)
value := any.Get(fdValue)
err = proto.UnmarshalOptions{
AllowPartial: true,