(m protoreflect.Message)
| 259 | } |
| 260 | |
| 261 | func (w *textWriter) writeMessage(m protoreflect.Message) error { |
| 262 | md := m.Descriptor() |
| 263 | if w.expandAny && md.FullName() == "google.protobuf.Any" { |
| 264 | if canExpand, err := w.writeProto3Any(m); canExpand { |
| 265 | return err |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | fds := md.Fields() |
| 270 | for i := 0; i < fds.Len(); { |
| 271 | fd := fds.Get(i) |
| 272 | if od := fd.ContainingOneof(); od != nil { |
| 273 | fd = m.WhichOneof(od) |
| 274 | i += od.Fields().Len() |
| 275 | } else { |
| 276 | i++ |
| 277 | } |
| 278 | if fd == nil || !m.Has(fd) { |
| 279 | continue |
| 280 | } |
| 281 | |
| 282 | switch { |
| 283 | case fd.IsList(): |
| 284 | lv := m.Get(fd).List() |
| 285 | for j := 0; j < lv.Len(); j++ { |
| 286 | w.writeName(fd) |
| 287 | v := lv.Get(j) |
| 288 | if err := w.writeSingularValue(v, fd); err != nil { |
| 289 | return err |
| 290 | } |
| 291 | w.WriteByte('\n') |
| 292 | } |
| 293 | case fd.IsMap(): |
| 294 | kfd := fd.MapKey() |
| 295 | vfd := fd.MapValue() |
| 296 | mv := m.Get(fd).Map() |
| 297 | |
| 298 | type entry struct{ key, val protoreflect.Value } |
| 299 | var entries []entry |
| 300 | mv.Range(func(k protoreflect.MapKey, v protoreflect.Value) bool { |
| 301 | entries = append(entries, entry{k.Value(), v}) |
| 302 | return true |
| 303 | }) |
| 304 | sort.Slice(entries, func(i, j int) bool { |
| 305 | switch kfd.Kind() { |
| 306 | case protoreflect.BoolKind: |
| 307 | return !entries[i].key.Bool() && entries[j].key.Bool() |
| 308 | case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind, protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: |
| 309 | return entries[i].key.Int() < entries[j].key.Int() |
| 310 | case protoreflect.Uint32Kind, protoreflect.Fixed32Kind, protoreflect.Uint64Kind, protoreflect.Fixed64Kind: |
| 311 | return entries[i].key.Uint() < entries[j].key.Uint() |
| 312 | case protoreflect.StringKind: |
| 313 | return entries[i].key.String() < entries[j].key.String() |
| 314 | default: |
| 315 | panic("invalid kind") |
| 316 | } |
| 317 | }) |
| 318 | for _, entry := range entries { |
no test coverage detected