Преглед на файлове

internal/typefmt: move descriptor formatting logic to typefmt

Custom descriptor types would want to benefit from descriptor formatting.
As such, move the logic out from prototype into an internal package for
the benefit of usages outside the prototype package.

Change-Id: I4bb2144221e656aa36909d33a77189fe084f700b
Reviewed-on: https://go-review.googlesource.com/c/152777
Reviewed-by: Herbie Ong <herbie@google.com>
Joe Tsai преди 7 години
родител
ревизия
b3960a7de0

+ 2 - 1
internal/cmd/generate-types/main.go

@@ -180,7 +180,7 @@ var listTypesTemplate = template.Must(template.New("").Funcs(template.FuncMap{
 		return {{$nameDesc}}{t}
 	}
 	{{- end}}
-	func (p *{{$nameList}}) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+	func (p *{{$nameList}}) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 	func (p *{{$nameList}}) ProtoInternal(pragma.DoNotImplement) {}
 	{{- end}}
 `))
@@ -201,6 +201,7 @@ func writeSource(file, src string) {
 		"sync",
 		"",
 		"github.com/golang/protobuf/v2/internal/pragma",
+		"github.com/golang/protobuf/v2/internal/typefmt",
 		"github.com/golang/protobuf/v2/reflect/protoreflect",
 	} {
 		if pkg == "" {

+ 2 - 2
internal/legacy/extension.go

@@ -12,6 +12,7 @@ import (
 	papi "github.com/golang/protobuf/protoapi"
 	ptag "github.com/golang/protobuf/v2/internal/encoding/tag"
 	pimpl "github.com/golang/protobuf/v2/internal/impl"
+	pfmt "github.com/golang/protobuf/v2/internal/typefmt"
 	pvalue "github.com/golang/protobuf/v2/internal/value"
 	pref "github.com/golang/protobuf/v2/reflect/protoreflect"
 	ptype "github.com/golang/protobuf/v2/reflect/prototype"
@@ -248,5 +249,4 @@ func (x *extensionType) GoType() reflect.Type                 { return x.typ }
 func (x *extensionType) New() interface{}                     { return x.new() }
 func (x *extensionType) ValueOf(v interface{}) pref.Value     { return x.valueOf(v) }
 func (x *extensionType) InterfaceOf(v pref.Value) interface{} { return x.interfaceOf(v) }
-
-// TODO: Provide custom stringer with the new GoType.
+func (x *extensionType) Format(s fmt.State, r rune)           { pfmt.FormatDesc(s, r, x) }

+ 53 - 0
internal/typefmt/desc_test.go

@@ -0,0 +1,53 @@
+// Copyright 2018 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 typefmt
+
+import (
+	"reflect"
+	"testing"
+
+	pref "github.com/golang/protobuf/v2/reflect/protoreflect"
+)
+
+// TestDescriptorAccessors tests that descriptorAccessors is up-to-date.
+func TestDescriptorAccessors(t *testing.T) {
+	ignore := map[string]bool{
+		"DefaultEnumValue": true,
+		"DescriptorByName": true,
+		"ProtoType":        true,
+	}
+	rt := reflect.TypeOf((*pref.Descriptor)(nil)).Elem()
+	for i := 0; i < rt.NumMethod(); i++ {
+		ignore[rt.Method(i).Name] = true
+	}
+
+	for rt, m := range descriptorAccessors {
+		got := map[string]bool{}
+		for _, s := range m {
+			got[s] = true
+		}
+		want := map[string]bool{}
+		for i := 0; i < rt.NumMethod(); i++ {
+			want[rt.Method(i).Name] = true
+		}
+
+		// Check if descriptorAccessors contains a non-existent accessor.
+		// If this test fails, remove the accessor from descriptorAccessors.
+		for s := range got {
+			if !want[s] && !ignore[s] {
+				t.Errorf("%v.%v does not exist", rt, s)
+			}
+		}
+
+		// Check if there are new protoreflect interface methods that are not
+		// handled by the formatter. If this fails, either add the method to
+		// ignore or add them to descriptorAccessors.
+		for s := range want {
+			if !got[s] && !ignore[s] {
+				t.Errorf("%v.%v is not called by formatter", rt, s)
+			}
+		}
+	}
+}

+ 4 - 3
reflect/prototype/stringer.go → internal/typefmt/stringer.go

@@ -2,7 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package prototype
+// Package typefmt provides functionality to format descriptors.
+package typefmt
 
 import (
 	"fmt"
@@ -21,7 +22,7 @@ type list interface {
 	pragma.DoNotImplement
 }
 
-func formatList(s fmt.State, r rune, vs list) {
+func FormatList(s fmt.State, r rune, vs list) {
 	io.WriteString(s, formatListOpt(vs, true, r == 'v' && (s.Flag('+') || s.Flag('#'))))
 }
 func formatListOpt(vs list, isRoot, allowMulti bool) string {
@@ -94,7 +95,7 @@ var descriptorAccessors = map[reflect.Type][]string{
 	reflect.TypeOf((*pref.MethodDescriptor)(nil)).Elem():    {"InputType", "OutputType", "IsStreamingClient", "IsStreamingServer"},
 }
 
-func formatDesc(s fmt.State, r rune, t pref.Descriptor) {
+func FormatDesc(s fmt.State, r rune, t pref.Descriptor) {
 	io.WriteString(s, formatDescOpt(t, true, r == 'v' && (s.Flag('+') || s.Flag('#'))))
 }
 func formatDescOpt(t pref.Descriptor, isRoot, allowMulti bool) string {

+ 0 - 41
reflect/prototype/desc_test.go

@@ -57,44 +57,3 @@ func TestDescriptors(t *testing.T) {
 		}
 	}
 }
-
-// TestDescriptorAccessors tests that descriptorAccessors is up-to-date.
-func TestDescriptorAccessors(t *testing.T) {
-	ignore := map[string]bool{
-		"DefaultEnumValue": true,
-		"DescriptorByName": true,
-		"ProtoType":        true,
-	}
-	rt := reflect.TypeOf((*pref.Descriptor)(nil)).Elem()
-	for i := 0; i < rt.NumMethod(); i++ {
-		ignore[rt.Method(i).Name] = true
-	}
-
-	for rt, m := range descriptorAccessors {
-		got := map[string]bool{}
-		for _, s := range m {
-			got[s] = true
-		}
-		want := map[string]bool{}
-		for i := 0; i < rt.NumMethod(); i++ {
-			want[rt.Method(i).Name] = true
-		}
-
-		// Check if descriptorAccessors contains a non-existent accessor.
-		// If this test fails, remove the accessor from descriptorAccessors.
-		for s := range got {
-			if !want[s] && !ignore[s] {
-				t.Errorf("%v.%v does not exist", rt, s)
-			}
-		}
-
-		// Check if there are new protoreflect interface methods that are not
-		// handled by the formatter. If this fails, either add the method to
-		// ignore or add them to descriptorAccessors.
-		for s := range want {
-			if !got[s] && !ignore[s] {
-				t.Errorf("%v.%v is not called by formatter", rt, s)
-			}
-		}
-	}
-}

+ 4 - 3
reflect/prototype/go_type.go

@@ -9,6 +9,7 @@ import (
 	"reflect"
 	"sync"
 
+	"github.com/golang/protobuf/v2/internal/typefmt"
 	"github.com/golang/protobuf/v2/internal/value"
 	"github.com/golang/protobuf/v2/reflect/protoreflect"
 )
@@ -43,7 +44,7 @@ func (t *goEnum) New(n protoreflect.EnumNumber) protoreflect.ProtoEnum {
 	return e
 }
 func (t *goEnum) Format(s fmt.State, r rune) {
-	formatDesc(s, r, t)
+	typefmt.FormatDesc(s, r, t)
 }
 
 // GoMessage creates a new protoreflect.MessageType by combining the provided
@@ -78,7 +79,7 @@ func (t *goMessage) New() protoreflect.ProtoMessage {
 	return m
 }
 func (t *goMessage) Format(s fmt.State, r rune) {
-	formatDesc(s, r, t)
+	typefmt.FormatDesc(s, r, t)
 }
 
 // GoExtension creates a new protoreflect.ExtensionType.
@@ -194,7 +195,7 @@ func (t *goExtension) InterfaceOf(pv protoreflect.Value) interface{} {
 	return v
 }
 func (t *goExtension) Format(s fmt.State, r rune) {
-	formatDesc(s, r, t)
+	typefmt.FormatDesc(s, r, t)
 }
 func (t *goExtension) lazyInit() {
 	t.once.Do(func() {

+ 4 - 3
reflect/prototype/placeholder_type.go

@@ -8,6 +8,7 @@ import (
 	"fmt"
 
 	pragma "github.com/golang/protobuf/v2/internal/pragma"
+	pfmt "github.com/golang/protobuf/v2/internal/typefmt"
 	pref "github.com/golang/protobuf/v2/reflect/protoreflect"
 )
 
@@ -49,7 +50,7 @@ func (t placeholderFile) Enums() pref.EnumDescriptors                    { retur
 func (t placeholderFile) Extensions() pref.ExtensionDescriptors          { return &emptyExtensions }
 func (t placeholderFile) Services() pref.ServiceDescriptors              { return &emptyServices }
 func (t placeholderFile) DescriptorByName(pref.FullName) pref.Descriptor { return nil }
-func (t placeholderFile) Format(s fmt.State, r rune)                     { formatDesc(s, r, t) }
+func (t placeholderFile) Format(s fmt.State, r rune)                     { pfmt.FormatDesc(s, r, t) }
 func (t placeholderFile) ProtoType(pref.FileDescriptor)                  {}
 
 type placeholderMessage struct {
@@ -65,7 +66,7 @@ func (t placeholderMessage) ExtensionRanges() pref.FieldRanges     { return &emp
 func (t placeholderMessage) Messages() pref.MessageDescriptors     { return &emptyMessages }
 func (t placeholderMessage) Enums() pref.EnumDescriptors           { return &emptyEnums }
 func (t placeholderMessage) Extensions() pref.ExtensionDescriptors { return &emptyExtensions }
-func (t placeholderMessage) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t placeholderMessage) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t placeholderMessage) ProtoType(pref.MessageDescriptor)      {}
 
 type placeholderEnum struct {
@@ -74,5 +75,5 @@ type placeholderEnum struct {
 
 func (t placeholderEnum) Options() pref.ProtoMessage        { return nil }
 func (t placeholderEnum) Values() pref.EnumValueDescriptors { return &emptyEnumValues }
-func (t placeholderEnum) Format(s fmt.State, r rune)        { formatDesc(s, r, t) }
+func (t placeholderEnum) Format(s fmt.State, r rune)        { pfmt.FormatDesc(s, r, t) }
 func (t placeholderEnum) ProtoType(pref.EnumDescriptor)     {}

+ 5 - 4
reflect/prototype/protofile_list.go

@@ -10,6 +10,7 @@ import (
 
 	pragma "github.com/golang/protobuf/v2/internal/pragma"
 	pset "github.com/golang/protobuf/v2/internal/set"
+	pfmt "github.com/golang/protobuf/v2/internal/typefmt"
 	pref "github.com/golang/protobuf/v2/reflect/protoreflect"
 )
 
@@ -34,7 +35,7 @@ func (p *numbersMeta) lazyInit(fs []Field) *numbers {
 func (p *numbers) Len() int                            { return len(p.ns) }
 func (p *numbers) Get(i int) pref.FieldNumber          { return p.ns[i] }
 func (p *numbers) Has(n pref.FieldNumber) bool         { return p.nss.Has(uint64(n)) }
-func (p *numbers) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *numbers) Format(s fmt.State, r rune)          { pfmt.FormatList(s, r, p) }
 func (p *numbers) ProtoInternal(pragma.DoNotImplement) {}
 
 type ranges [][2]pref.FieldNumber
@@ -49,14 +50,14 @@ func (p *ranges) Has(n pref.FieldNumber) bool {
 	}
 	return false
 }
-func (p *ranges) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *ranges) Format(s fmt.State, r rune)          { pfmt.FormatList(s, r, p) }
 func (p *ranges) ProtoInternal(pragma.DoNotImplement) {}
 
 type fileImports []pref.FileImport
 
 func (p *fileImports) Len() int                            { return len(*p) }
 func (p *fileImports) Get(i int) pref.FileImport           { return (*p)[i] }
-func (p *fileImports) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *fileImports) Format(s fmt.State, r rune)          { pfmt.FormatList(s, r, p) }
 func (p *fileImports) ProtoInternal(pragma.DoNotImplement) {}
 
 type oneofFieldsMeta struct {
@@ -96,5 +97,5 @@ func (p *oneofFields) Get(i int) pref.FieldDescriptor                   { return
 func (p *oneofFields) ByName(s pref.Name) pref.FieldDescriptor          { return p.byName[s] }
 func (p *oneofFields) ByJSONName(s string) pref.FieldDescriptor         { return p.byJSON[s] }
 func (p *oneofFields) ByNumber(n pref.FieldNumber) pref.FieldDescriptor { return p.byNum[n] }
-func (p *oneofFields) Format(s fmt.State, r rune)                       { formatList(s, r, p) }
+func (p *oneofFields) Format(s fmt.State, r rune)                       { pfmt.FormatList(s, r, p) }
 func (p *oneofFields) ProtoInternal(pragma.DoNotImplement)              {}

+ 9 - 8
reflect/prototype/protofile_list_gen.go

@@ -11,6 +11,7 @@ import (
 	"sync"
 
 	"github.com/golang/protobuf/v2/internal/pragma"
+	"github.com/golang/protobuf/v2/internal/typefmt"
 	"github.com/golang/protobuf/v2/reflect/protoreflect"
 )
 
@@ -57,7 +58,7 @@ func (p *messages) ByName(s protoreflect.Name) protoreflect.MessageDescriptor {
 	}
 	return messageDesc{t}
 }
-func (p *messages) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *messages) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 func (p *messages) ProtoInternal(pragma.DoNotImplement) {}
 
 type fieldsMeta struct {
@@ -144,7 +145,7 @@ func (p *fields) ByNumber(n protoreflect.FieldNumber) protoreflect.FieldDescript
 	}
 	return fieldDesc{t}
 }
-func (p *fields) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *fields) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 func (p *fields) ProtoInternal(pragma.DoNotImplement) {}
 
 type oneofsMeta struct {
@@ -190,7 +191,7 @@ func (p *oneofs) ByName(s protoreflect.Name) protoreflect.OneofDescriptor {
 	}
 	return oneofDesc{t}
 }
-func (p *oneofs) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *oneofs) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 func (p *oneofs) ProtoInternal(pragma.DoNotImplement) {}
 
 type extensionsMeta struct {
@@ -236,7 +237,7 @@ func (p *extensions) ByName(s protoreflect.Name) protoreflect.ExtensionDescripto
 	}
 	return extensionDesc{t}
 }
-func (p *extensions) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *extensions) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 func (p *extensions) ProtoInternal(pragma.DoNotImplement) {}
 
 type enumsMeta struct {
@@ -282,7 +283,7 @@ func (p *enums) ByName(s protoreflect.Name) protoreflect.EnumDescriptor {
 	}
 	return enumDesc{t}
 }
-func (p *enums) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *enums) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 func (p *enums) ProtoInternal(pragma.DoNotImplement) {}
 
 type enumValuesMeta struct {
@@ -348,7 +349,7 @@ func (p *enumValues) ByNumber(n protoreflect.EnumNumber) protoreflect.EnumValueD
 	}
 	return enumValueDesc{t}
 }
-func (p *enumValues) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *enumValues) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 func (p *enumValues) ProtoInternal(pragma.DoNotImplement) {}
 
 type servicesMeta struct {
@@ -394,7 +395,7 @@ func (p *services) ByName(s protoreflect.Name) protoreflect.ServiceDescriptor {
 	}
 	return serviceDesc{t}
 }
-func (p *services) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *services) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 func (p *services) ProtoInternal(pragma.DoNotImplement) {}
 
 type methodsMeta struct {
@@ -440,5 +441,5 @@ func (p *methods) ByName(s protoreflect.Name) protoreflect.MethodDescriptor {
 	}
 	return methodDesc{t}
 }
-func (p *methods) Format(s fmt.State, r rune)          { formatList(s, r, p) }
+func (p *methods) Format(s fmt.State, r rune)          { typefmt.FormatList(s, r, p) }
 func (p *methods) ProtoInternal(pragma.DoNotImplement) {}

+ 10 - 9
reflect/prototype/protofile_type.go

@@ -11,6 +11,7 @@ import (
 	"sync"
 
 	pragma "github.com/golang/protobuf/v2/internal/pragma"
+	pfmt "github.com/golang/protobuf/v2/internal/typefmt"
 	pref "github.com/golang/protobuf/v2/reflect/protoreflect"
 )
 
@@ -69,7 +70,7 @@ func (t fileDesc) Enums() pref.EnumDescriptors                      { return t.f
 func (t fileDesc) Extensions() pref.ExtensionDescriptors            { return t.f.xs.lazyInit(t, t.f.Extensions) }
 func (t fileDesc) Services() pref.ServiceDescriptors                { return t.f.ss.lazyInit(t, t.f.Services) }
 func (t fileDesc) DescriptorByName(s pref.FullName) pref.Descriptor { return t.f.ds.lookup(t, s) }
-func (t fileDesc) Format(s fmt.State, r rune)                       { formatDesc(s, r, t) }
+func (t fileDesc) Format(s fmt.State, r rune)                       { pfmt.FormatDesc(s, r, t) }
 func (t fileDesc) ProtoType(pref.FileDescriptor)                    {}
 func (t fileDesc) ProtoInternal(pragma.DoNotImplement)              {}
 
@@ -177,7 +178,7 @@ func (t messageDesc) ExtensionRanges() pref.FieldRanges     { return (*ranges)(&
 func (t messageDesc) Messages() pref.MessageDescriptors     { return t.m.ms.lazyInit(t, t.m.Messages) }
 func (t messageDesc) Enums() pref.EnumDescriptors           { return t.m.es.lazyInit(t, t.m.Enums) }
 func (t messageDesc) Extensions() pref.ExtensionDescriptors { return t.m.xs.lazyInit(t, t.m.Extensions) }
-func (t messageDesc) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t messageDesc) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t messageDesc) ProtoType(pref.MessageDescriptor)      {}
 func (t messageDesc) ProtoInternal(pragma.DoNotImplement)   {}
 
@@ -231,7 +232,7 @@ func (t fieldDesc) OneofType() pref.OneofDescriptor            { return t.f.ot.l
 func (t fieldDesc) ExtendedType() pref.MessageDescriptor       { return nil }
 func (t fieldDesc) MessageType() pref.MessageDescriptor        { return t.f.mt.lazyInit(t, &t.f.MessageType) }
 func (t fieldDesc) EnumType() pref.EnumDescriptor              { return t.f.et.lazyInit(t, &t.f.EnumType) }
-func (t fieldDesc) Format(s fmt.State, r rune)                 { formatDesc(s, r, t) }
+func (t fieldDesc) Format(s fmt.State, r rune)                 { pfmt.FormatDesc(s, r, t) }
 func (t fieldDesc) ProtoType(pref.FieldDescriptor)             {}
 func (t fieldDesc) ProtoInternal(pragma.DoNotImplement)        {}
 
@@ -367,7 +368,7 @@ func (t oneofDesc) IsPlaceholder() bool                   { return false }
 func (t oneofDesc) DescriptorProto() (pref.Message, bool) { return nil, false }
 func (t oneofDesc) Options() pref.ProtoMessage            { return t.o.Options }
 func (t oneofDesc) Fields() pref.FieldDescriptors         { return t.o.fs.lazyInit(t) }
-func (t oneofDesc) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t oneofDesc) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t oneofDesc) ProtoType(pref.OneofDescriptor)        {}
 func (t oneofDesc) ProtoInternal(pragma.DoNotImplement)   {}
 
@@ -407,7 +408,7 @@ func (t extensionDesc) MessageType() pref.MessageDescriptor {
 	return t.x.mt.lazyInit(t, &t.x.MessageType)
 }
 func (t extensionDesc) EnumType() pref.EnumDescriptor       { return t.x.et.lazyInit(t, &t.x.EnumType) }
-func (t extensionDesc) Format(s fmt.State, r rune)          { formatDesc(s, r, t) }
+func (t extensionDesc) Format(s fmt.State, r rune)          { pfmt.FormatDesc(s, r, t) }
 func (t extensionDesc) ProtoType(pref.FieldDescriptor)      {}
 func (t extensionDesc) ProtoInternal(pragma.DoNotImplement) {}
 
@@ -427,7 +428,7 @@ func (t enumDesc) IsPlaceholder() bool                   { return false }
 func (t enumDesc) DescriptorProto() (pref.Message, bool) { return nil, false }
 func (t enumDesc) Options() pref.ProtoMessage            { return t.e.Options }
 func (t enumDesc) Values() pref.EnumValueDescriptors     { return t.e.vs.lazyInit(t, t.e.Values) }
-func (t enumDesc) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t enumDesc) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t enumDesc) ProtoType(pref.EnumDescriptor)         {}
 func (t enumDesc) ProtoInternal(pragma.DoNotImplement)   {}
 
@@ -445,7 +446,7 @@ func (t enumValueDesc) IsPlaceholder() bool                   { return false }
 func (t enumValueDesc) DescriptorProto() (pref.Message, bool) { return nil, false }
 func (t enumValueDesc) Options() pref.ProtoMessage            { return t.v.Options }
 func (t enumValueDesc) Number() pref.EnumNumber               { return t.v.Number }
-func (t enumValueDesc) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t enumValueDesc) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t enumValueDesc) ProtoType(pref.EnumValueDescriptor)    {}
 func (t enumValueDesc) ProtoInternal(pragma.DoNotImplement)   {}
 
@@ -465,7 +466,7 @@ func (t serviceDesc) IsPlaceholder() bool                   { return false }
 func (t serviceDesc) DescriptorProto() (pref.Message, bool) { return nil, false }
 func (t serviceDesc) Options() pref.ProtoMessage            { return t.s.Options }
 func (t serviceDesc) Methods() pref.MethodDescriptors       { return t.s.ms.lazyInit(t, t.s.Methods) }
-func (t serviceDesc) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t serviceDesc) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t serviceDesc) ProtoType(pref.ServiceDescriptor)      {}
 func (t serviceDesc) ProtoInternal(pragma.DoNotImplement)   {}
 
@@ -489,7 +490,7 @@ func (t methodDesc) InputType() pref.MessageDescriptor     { return t.m.mit.lazy
 func (t methodDesc) OutputType() pref.MessageDescriptor    { return t.m.mot.lazyInit(t, &t.m.OutputType) }
 func (t methodDesc) IsStreamingClient() bool               { return t.m.IsStreamingClient }
 func (t methodDesc) IsStreamingServer() bool               { return t.m.IsStreamingServer }
-func (t methodDesc) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t methodDesc) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t methodDesc) ProtoType(pref.MethodDescriptor)       {}
 func (t methodDesc) ProtoInternal(pragma.DoNotImplement)   {}
 

+ 5 - 4
reflect/prototype/standalone_type.go

@@ -7,7 +7,8 @@ package prototype
 import (
 	"fmt"
 
-	"github.com/golang/protobuf/v2/internal/pragma"
+	pragma "github.com/golang/protobuf/v2/internal/pragma"
+	pfmt "github.com/golang/protobuf/v2/internal/typefmt"
 	pref "github.com/golang/protobuf/v2/reflect/protoreflect"
 )
 
@@ -29,7 +30,7 @@ func (t standaloneMessage) ExtensionRanges() pref.FieldRanges     { return (*ran
 func (t standaloneMessage) Messages() pref.MessageDescriptors     { return &emptyMessages }
 func (t standaloneMessage) Enums() pref.EnumDescriptors           { return &emptyEnums }
 func (t standaloneMessage) Extensions() pref.ExtensionDescriptors { return &emptyExtensions }
-func (t standaloneMessage) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t standaloneMessage) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t standaloneMessage) ProtoType(pref.MessageDescriptor)      {}
 func (t standaloneMessage) ProtoInternal(pragma.DoNotImplement)   {}
 
@@ -44,7 +45,7 @@ func (t standaloneEnum) IsPlaceholder() bool                   { return false }
 func (t standaloneEnum) DescriptorProto() (pref.Message, bool) { return nil, false }
 func (t standaloneEnum) Options() pref.ProtoMessage            { return t.e.Options }
 func (t standaloneEnum) Values() pref.EnumValueDescriptors     { return t.e.vals.lazyInit(t, t.e.Values) }
-func (t standaloneEnum) Format(s fmt.State, r rune)            { formatDesc(s, r, t) }
+func (t standaloneEnum) Format(s fmt.State, r rune)            { pfmt.FormatDesc(s, r, t) }
 func (t standaloneEnum) ProtoType(pref.EnumDescriptor)         {}
 func (t standaloneEnum) ProtoInternal(pragma.DoNotImplement)   {}
 
@@ -74,6 +75,6 @@ func (t standaloneExtension) OneofType() pref.OneofDescriptor      { return nil
 func (t standaloneExtension) MessageType() pref.MessageDescriptor  { return t.x.MessageType }
 func (t standaloneExtension) EnumType() pref.EnumDescriptor        { return t.x.EnumType }
 func (t standaloneExtension) ExtendedType() pref.MessageDescriptor { return t.x.ExtendedType }
-func (t standaloneExtension) Format(s fmt.State, r rune)           { formatDesc(s, r, t) }
+func (t standaloneExtension) Format(s fmt.State, r rune)           { pfmt.FormatDesc(s, r, t) }
 func (t standaloneExtension) ProtoType(pref.FieldDescriptor)       {}
 func (t standaloneExtension) ProtoInternal(pragma.DoNotImplement)  {}