summaryrefslogtreecommitdiffstats
path: root/vendor/google.golang.org/protobuf/encoding/prototext/encode.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2021-06-16 21:00:49 +0200
committerGitHub <noreply@github.com>2021-06-16 21:00:49 +0200
commitfb5a84212c491332504fcdd4b5f4a4b97705d2e3 (patch)
treebe03e973d30d040a49a90c47f1e6b73ed8922539 /vendor/google.golang.org/protobuf/encoding/prototext/encode.go
parentdedc1c45a113d8db373d9e4638f54a0f9d29624f (diff)
downloadmatterbridge-msglm-fb5a84212c491332504fcdd4b5f4a4b97705d2e3.tar.gz
matterbridge-msglm-fb5a84212c491332504fcdd4b5f4a4b97705d2e3.tar.bz2
matterbridge-msglm-fb5a84212c491332504fcdd4b5f4a4b97705d2e3.zip
Update dependencies (#1521)
Diffstat (limited to 'vendor/google.golang.org/protobuf/encoding/prototext/encode.go')
-rw-r--r--vendor/google.golang.org/protobuf/encoding/prototext/encode.go84
1 files changed, 11 insertions, 73 deletions
diff --git a/vendor/google.golang.org/protobuf/encoding/prototext/encode.go b/vendor/google.golang.org/protobuf/encoding/prototext/encode.go
index 0877d71c..8d5304dc 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 @@ package prototext
import (
"fmt"
- "sort"
"strconv"
"unicode/utf8"
@@ -16,10 +15,11 @@ import (
"google.golang.org/protobuf/internal/errors"
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/internal/genid"
- "google.golang.org/protobuf/internal/mapsort"
+ "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"
)
@@ -169,35 +169,15 @@ func (e encoder) marshalMessage(m pref.Message, inclDelims bool) error {
// 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++
- }
-
- 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 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
}
- }
-
- // Marshal extensions.
- if err := e.marshalExtensions(m); err != nil {
+ return true
+ })
+ if err != nil {
return err
}
@@ -290,7 +270,7 @@ func (e encoder) marshalList(name string, list pref.List, fd pref.FieldDescripto
// 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()
@@ -311,48 +291,6 @@ func (e encoder) marshalMap(name string, mmap pref.Map, fd pref.FieldDescriptor)
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) {