Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 1 | // Copyright 2018 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package legacy |
| 6 | |
| 7 | import ( |
| 8 | "fmt" |
| 9 | "reflect" |
Joe Tsai | 62517cc | 2018-12-04 14:00:01 -0800 | [diff] [blame] | 10 | "sync" |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 11 | |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 12 | ptag "github.com/golang/protobuf/v2/internal/encoding/tag" |
| 13 | pimpl "github.com/golang/protobuf/v2/internal/impl" |
Joe Tsai | 990b9f5 | 2019-03-13 12:56:39 -0700 | [diff] [blame] | 14 | ptype "github.com/golang/protobuf/v2/internal/prototype" |
Joe Tsai | b3960a7 | 2018-12-05 10:35:35 -0800 | [diff] [blame] | 15 | pfmt "github.com/golang/protobuf/v2/internal/typefmt" |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 16 | pvalue "github.com/golang/protobuf/v2/internal/value" |
| 17 | pref "github.com/golang/protobuf/v2/reflect/protoreflect" |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 18 | preg "github.com/golang/protobuf/v2/reflect/protoregistry" |
Joe Tsai | 4fddeba | 2019-03-20 18:29:32 -0700 | [diff] [blame] | 19 | piface "github.com/golang/protobuf/v2/runtime/protoiface" |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 20 | ) |
| 21 | |
Joe Tsai | 4fddeba | 2019-03-20 18:29:32 -0700 | [diff] [blame] | 22 | // extensionDescKey is a comparable version of protoiface.ExtensionDescV1 |
Joe Tsai | 62517cc | 2018-12-04 14:00:01 -0800 | [diff] [blame] | 23 | // suitable for use as a key in a map. |
| 24 | type extensionDescKey struct { |
| 25 | typeV2 pref.ExtensionType |
| 26 | extendedType reflect.Type |
| 27 | extensionType reflect.Type |
| 28 | field int32 |
| 29 | name string |
| 30 | tag string |
| 31 | filename string |
| 32 | } |
| 33 | |
Joe Tsai | 4fddeba | 2019-03-20 18:29:32 -0700 | [diff] [blame] | 34 | func extensionDescKeyOf(d *piface.ExtensionDescV1) extensionDescKey { |
Joe Tsai | 62517cc | 2018-12-04 14:00:01 -0800 | [diff] [blame] | 35 | return extensionDescKey{ |
| 36 | d.Type, |
| 37 | reflect.TypeOf(d.ExtendedType), |
| 38 | reflect.TypeOf(d.ExtensionType), |
| 39 | d.Field, d.Name, d.Tag, d.Filename, |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | var ( |
| 44 | extensionTypeCache sync.Map // map[extensionDescKey]protoreflect.ExtensionType |
Joe Tsai | 4fddeba | 2019-03-20 18:29:32 -0700 | [diff] [blame] | 45 | extensionDescCache sync.Map // map[protoreflect.ExtensionType]*protoiface.ExtensionDescV1 |
Joe Tsai | 62517cc | 2018-12-04 14:00:01 -0800 | [diff] [blame] | 46 | ) |
| 47 | |
Joe Tsai | 6dbffb7 | 2018-12-04 14:06:19 -0800 | [diff] [blame] | 48 | // extensionDescFromType converts a v2 protoreflect.ExtensionType to a |
Joe Tsai | 4fddeba | 2019-03-20 18:29:32 -0700 | [diff] [blame] | 49 | // protoiface.ExtensionDescV1. The returned ExtensionDesc must not be mutated. |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 50 | func extensionDescFromType(xt pref.ExtensionType) *piface.ExtensionDescV1 { |
Joe Tsai | afb455e | 2019-03-14 16:08:22 -0700 | [diff] [blame] | 51 | // Fast-path: check whether an extension desc is already nested within. |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 52 | if xt, ok := xt.(interface { |
Joe Tsai | 4fddeba | 2019-03-20 18:29:32 -0700 | [diff] [blame] | 53 | ProtoLegacyExtensionDesc() *piface.ExtensionDescV1 |
| 54 | }); ok { |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 55 | if d := xt.ProtoLegacyExtensionDesc(); d != nil { |
Joe Tsai | afb455e | 2019-03-14 16:08:22 -0700 | [diff] [blame] | 56 | return d |
| 57 | } |
| 58 | } |
| 59 | |
Joe Tsai | 62517cc | 2018-12-04 14:00:01 -0800 | [diff] [blame] | 60 | // Fast-path: check the cache for whether this ExtensionType has already |
| 61 | // been converted to a legacy descriptor. |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 62 | if d, ok := extensionDescCache.Load(xt); ok { |
Joe Tsai | 4fddeba | 2019-03-20 18:29:32 -0700 | [diff] [blame] | 63 | return d.(*piface.ExtensionDescV1) |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | // Determine the parent type if possible. |
Joe Tsai | 4fddeba | 2019-03-20 18:29:32 -0700 | [diff] [blame] | 67 | var parent piface.MessageV1 |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 68 | if mt, _ := preg.GlobalTypes.FindMessageByName(xt.Descriptor().Extendee().FullName()); mt != nil { |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 69 | // Create a new parent message and unwrap it if possible. |
Joe Tsai | 3bc7d6f | 2019-01-09 02:57:13 -0800 | [diff] [blame] | 70 | mv := mt.New().Interface() |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 71 | t := reflect.TypeOf(mv) |
| 72 | if mv, ok := mv.(pvalue.Unwrapper); ok { |
| 73 | t = reflect.TypeOf(mv.ProtoUnwrap()) |
| 74 | } |
| 75 | |
| 76 | // Check whether the message implements the legacy v1 Message interface. |
| 77 | mz := reflect.Zero(t).Interface() |
Joe Tsai | 4fddeba | 2019-03-20 18:29:32 -0700 | [diff] [blame] | 78 | if mz, ok := mz.(piface.MessageV1); ok { |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 79 | parent = mz |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | // Determine the v1 extension type, which is unfortunately not the same as |
| 84 | // the v2 ExtensionType.GoType. |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 85 | extType := xt.GoType() |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 86 | switch extType.Kind() { |
| 87 | case reflect.Bool, reflect.Int32, reflect.Int64, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64, reflect.String: |
| 88 | extType = reflect.PtrTo(extType) // T -> *T for singular scalar fields |
| 89 | case reflect.Ptr: |
| 90 | if extType.Elem().Kind() == reflect.Slice { |
| 91 | extType = extType.Elem() // *[]T -> []T for repeated fields |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // Reconstruct the legacy enum full name, which is an odd mixture of the |
| 96 | // proto package name with the Go type name. |
| 97 | var enumName string |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 98 | if xt.Descriptor().Kind() == pref.EnumKind { |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 99 | // Derive Go type name. |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 100 | t := extType |
| 101 | if t.Kind() == reflect.Ptr || t.Kind() == reflect.Slice { |
| 102 | t = t.Elem() |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 103 | } |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 104 | enumName = t.Name() |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 105 | |
| 106 | // Derive the proto package name. |
| 107 | // For legacy enums, obtain the proto package from the raw descriptor. |
| 108 | var protoPkg string |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 109 | if fd := parentFileDescriptor(xt.Descriptor().Enum()); fd != nil { |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 110 | protoPkg = string(fd.Package()) |
| 111 | } |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 112 | if ed, ok := reflect.Zero(t).Interface().(enumV1); ok && protoPkg == "" { |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 113 | b, _ := ed.EnumDescriptor() |
Damien Neil | 987d570 | 2019-04-10 11:06:53 -0700 | [diff] [blame] | 114 | protoPkg = loadFileDesc(b).GetPackage() |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | if protoPkg != "" { |
| 118 | enumName = protoPkg + "." + enumName |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // Derive the proto file that the extension was declared within. |
| 123 | var filename string |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 124 | if fd := parentFileDescriptor(xt.Descriptor()); fd != nil { |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 125 | filename = fd.Path() |
| 126 | } |
| 127 | |
Joe Tsai | 4fddeba | 2019-03-20 18:29:32 -0700 | [diff] [blame] | 128 | // Construct and return a ExtensionDescV1. |
| 129 | d := &piface.ExtensionDescV1{ |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 130 | Type: xt, |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 131 | ExtendedType: parent, |
| 132 | ExtensionType: reflect.Zero(extType).Interface(), |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 133 | Field: int32(xt.Descriptor().Number()), |
| 134 | Name: string(xt.Descriptor().FullName()), |
| 135 | Tag: ptag.Marshal(xt.Descriptor(), enumName), |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 136 | Filename: filename, |
| 137 | } |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 138 | if d, ok := extensionDescCache.LoadOrStore(xt, d); ok { |
Joe Tsai | 4fddeba | 2019-03-20 18:29:32 -0700 | [diff] [blame] | 139 | return d.(*piface.ExtensionDescV1) |
Joe Tsai | b936504 | 2019-03-19 14:14:29 -0700 | [diff] [blame] | 140 | } |
Joe Tsai | 62517cc | 2018-12-04 14:00:01 -0800 | [diff] [blame] | 141 | return d |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 142 | } |
| 143 | |
Joe Tsai | 4fddeba | 2019-03-20 18:29:32 -0700 | [diff] [blame] | 144 | // extensionTypeFromDesc converts a protoiface.ExtensionDescV1 to a |
Joe Tsai | 62517cc | 2018-12-04 14:00:01 -0800 | [diff] [blame] | 145 | // v2 protoreflect.ExtensionType. The returned descriptor type takes ownership |
| 146 | // of the input extension desc. The input must not be mutated so long as the |
| 147 | // returned type is still in use. |
Joe Tsai | 4fddeba | 2019-03-20 18:29:32 -0700 | [diff] [blame] | 148 | func extensionTypeFromDesc(d *piface.ExtensionDescV1) pref.ExtensionType { |
Joe Tsai | 62517cc | 2018-12-04 14:00:01 -0800 | [diff] [blame] | 149 | // Fast-path: check whether an extension type is already nested within. |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 150 | if d.Type != nil { |
Joe Tsai | 62517cc | 2018-12-04 14:00:01 -0800 | [diff] [blame] | 151 | return d.Type |
| 152 | } |
| 153 | |
| 154 | // Fast-path: check the cache for whether this ExtensionType has already |
| 155 | // been converted from a legacy descriptor. |
| 156 | dk := extensionDescKeyOf(d) |
| 157 | if t, ok := extensionTypeCache.Load(dk); ok { |
| 158 | return t.(pref.ExtensionType) |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | // Derive basic field information from the struct tag. |
| 162 | t := reflect.TypeOf(d.ExtensionType) |
| 163 | isOptional := t.Kind() == reflect.Ptr && t.Elem().Kind() != reflect.Struct |
| 164 | isRepeated := t.Kind() == reflect.Slice && t.Elem().Kind() != reflect.Uint8 |
| 165 | if isOptional || isRepeated { |
| 166 | t = t.Elem() |
| 167 | } |
| 168 | f := ptag.Unmarshal(d.Tag, t) |
| 169 | |
| 170 | // Construct a v2 ExtensionType. |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 171 | var ed pref.EnumDescriptor |
| 172 | var md pref.MessageDescriptor |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 173 | conv := pvalue.NewLegacyConverter(t, f.Kind, Export{}) |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 174 | if conv.EnumType != nil { |
| 175 | ed = conv.EnumType.Descriptor() |
| 176 | } |
| 177 | if conv.MessageType != nil { |
| 178 | md = conv.MessageType.Descriptor() |
| 179 | } |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 180 | xd, err := ptype.NewExtension(&ptype.StandaloneExtension{ |
| 181 | FullName: pref.FullName(d.Name), |
| 182 | Number: pref.FieldNumber(d.Field), |
| 183 | Cardinality: f.Cardinality, |
| 184 | Kind: f.Kind, |
| 185 | Default: f.Default, |
| 186 | Options: f.Options, |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 187 | EnumType: ed, |
| 188 | MessageType: md, |
| 189 | ExtendedType: pimpl.Export{}.MessageDescriptorOf(d.ExtendedType), |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 190 | }) |
| 191 | if err != nil { |
| 192 | panic(err) |
| 193 | } |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 194 | xt := ExtensionTypeOf(xd, t) |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 195 | |
Joe Tsai | 62517cc | 2018-12-04 14:00:01 -0800 | [diff] [blame] | 196 | // Cache the conversion for both directions. |
Joe Tsai | b936504 | 2019-03-19 14:14:29 -0700 | [diff] [blame] | 197 | extensionDescCache.LoadOrStore(xt, d) |
| 198 | if xt, ok := extensionTypeCache.LoadOrStore(dk, xt); ok { |
| 199 | return xt.(pref.ExtensionType) |
| 200 | } |
Joe Tsai | 62517cc | 2018-12-04 14:00:01 -0800 | [diff] [blame] | 201 | return xt |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 202 | } |
| 203 | |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 204 | // ExtensionTypeOf returns a protoreflect.ExtensionType where the type of the |
| 205 | // field is t. The type t must be provided if the field is an enum or message. |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 206 | // |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 207 | // This is exported for testing purposes. |
| 208 | func ExtensionTypeOf(xd pref.ExtensionDescriptor, t reflect.Type) pref.ExtensionType { |
| 209 | // Extension types for non-enums and non-messages are simple. |
| 210 | switch xd.Kind() { |
| 211 | case pref.EnumKind, pref.MessageKind, pref.GroupKind: |
| 212 | default: |
| 213 | return ptype.GoExtension(xd, nil, nil) |
| 214 | } |
| 215 | |
| 216 | // Create an ExtensionType where GoType is the wrapper type. |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 217 | conv := pvalue.NewLegacyConverter(t, xd.Kind(), Export{}) |
| 218 | xt := ptype.GoExtension(xd, conv.EnumType, conv.MessageType) |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 219 | if !conv.IsLegacy { |
| 220 | return xt |
| 221 | } |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 222 | |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 223 | // Wrap ExtensionType such that GoType presents the legacy Go type. |
Joe Tsai | 6dbffb7 | 2018-12-04 14:06:19 -0800 | [diff] [blame] | 224 | xt2 := &extensionType{ExtensionType: xt} |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 225 | if xd.Cardinality() != pref.Repeated { |
| 226 | xt2.typ = t |
Joe Tsai | d18bd31 | 2019-01-09 03:23:55 -0800 | [diff] [blame] | 227 | xt2.new = func() pref.Value { |
| 228 | return xt.New() |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 229 | } |
| 230 | xt2.valueOf = func(v interface{}) pref.Value { |
| 231 | if reflect.TypeOf(v) != xt2.typ { |
| 232 | panic(fmt.Sprintf("invalid type: got %T, want %v", v, xt2.typ)) |
| 233 | } |
| 234 | if xd.Kind() == pref.EnumKind { |
| 235 | return xt.ValueOf(Export{}.EnumOf(v)) |
| 236 | } else { |
Joe Tsai | 22b1ebd | 2019-03-11 13:45:14 -0700 | [diff] [blame] | 237 | return xt.ValueOf(Export{}.MessageOf(v).Interface()) |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | xt2.interfaceOf = func(v pref.Value) interface{} { |
| 241 | return xt.InterfaceOf(v).(pvalue.Unwrapper).ProtoUnwrap() |
| 242 | } |
| 243 | } else { |
| 244 | xt2.typ = reflect.PtrTo(reflect.SliceOf(t)) |
Joe Tsai | d18bd31 | 2019-01-09 03:23:55 -0800 | [diff] [blame] | 245 | xt2.new = func() pref.Value { |
| 246 | v := reflect.New(xt2.typ.Elem()).Interface() |
| 247 | return pref.ValueOf(pvalue.ListOf(v, conv)) |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 248 | } |
| 249 | xt2.valueOf = func(v interface{}) pref.Value { |
| 250 | if reflect.TypeOf(v) != xt2.typ { |
| 251 | panic(fmt.Sprintf("invalid type: got %T, want %v", v, xt2.typ)) |
| 252 | } |
| 253 | return pref.ValueOf(pvalue.ListOf(v, conv)) |
| 254 | } |
| 255 | xt2.interfaceOf = func(pv pref.Value) interface{} { |
| 256 | v := pv.List().(pvalue.Unwrapper).ProtoUnwrap() |
| 257 | if reflect.TypeOf(v) != xt2.typ { |
| 258 | panic(fmt.Sprintf("invalid type: got %T, want %v", v, xt2.typ)) |
| 259 | } |
| 260 | return v |
| 261 | } |
| 262 | } |
| 263 | return xt2 |
| 264 | } |
| 265 | |
Joe Tsai | 6dbffb7 | 2018-12-04 14:06:19 -0800 | [diff] [blame] | 266 | type extensionType struct { |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 267 | pref.ExtensionType |
| 268 | typ reflect.Type |
Joe Tsai | d18bd31 | 2019-01-09 03:23:55 -0800 | [diff] [blame] | 269 | new func() pref.Value |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 270 | valueOf func(interface{}) pref.Value |
| 271 | interfaceOf func(pref.Value) interface{} |
| 272 | } |
| 273 | |
Joe Tsai | 6dbffb7 | 2018-12-04 14:06:19 -0800 | [diff] [blame] | 274 | func (x *extensionType) GoType() reflect.Type { return x.typ } |
Joe Tsai | d18bd31 | 2019-01-09 03:23:55 -0800 | [diff] [blame] | 275 | func (x *extensionType) New() pref.Value { return x.new() } |
Joe Tsai | 6dbffb7 | 2018-12-04 14:06:19 -0800 | [diff] [blame] | 276 | func (x *extensionType) ValueOf(v interface{}) pref.Value { return x.valueOf(v) } |
| 277 | func (x *extensionType) InterfaceOf(v pref.Value) interface{} { return x.interfaceOf(v) } |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame^] | 278 | func (x *extensionType) Format(s fmt.State, r rune) { pfmt.FormatDesc(s, r, x.Descriptor()) } |