(v protoreflect.Value, fd protoreflect.FieldDescriptor)
| 352 | } |
| 353 | |
| 354 | func (w *textWriter) writeSingularValue(v protoreflect.Value, fd protoreflect.FieldDescriptor) error { |
| 355 | switch fd.Kind() { |
| 356 | case protoreflect.FloatKind, protoreflect.DoubleKind: |
| 357 | switch vf := v.Float(); { |
| 358 | case math.IsInf(vf, +1): |
| 359 | w.Write(posInf) |
| 360 | case math.IsInf(vf, -1): |
| 361 | w.Write(negInf) |
| 362 | case math.IsNaN(vf): |
| 363 | w.Write(nan) |
| 364 | default: |
| 365 | fmt.Fprint(w, v.Interface()) |
| 366 | } |
| 367 | case protoreflect.StringKind: |
| 368 | // NOTE: This does not validate UTF-8 for historical reasons. |
| 369 | w.writeQuotedString(string(v.String())) |
| 370 | case protoreflect.BytesKind: |
| 371 | w.writeQuotedString(string(v.Bytes())) |
| 372 | case protoreflect.MessageKind, protoreflect.GroupKind: |
| 373 | var bra, ket byte = '<', '>' |
| 374 | if fd.Kind() == protoreflect.GroupKind { |
| 375 | bra, ket = '{', '}' |
| 376 | } |
| 377 | w.WriteByte(bra) |
| 378 | if !w.compact { |
| 379 | w.WriteByte('\n') |
| 380 | } |
| 381 | w.indent++ |
| 382 | m := v.Message() |
| 383 | if m2, ok := m.Interface().(encoding.TextMarshaler); ok { |
| 384 | b, err := m2.MarshalText() |
| 385 | if err != nil { |
| 386 | return err |
| 387 | } |
| 388 | w.Write(b) |
| 389 | } else { |
| 390 | w.writeMessage(m) |
| 391 | } |
| 392 | w.indent-- |
| 393 | w.WriteByte(ket) |
| 394 | case protoreflect.EnumKind: |
| 395 | if ev := fd.Enum().Values().ByNumber(v.Enum()); ev != nil { |
| 396 | fmt.Fprint(w, ev.Name()) |
| 397 | } else { |
| 398 | fmt.Fprint(w, v.Enum()) |
| 399 | } |
| 400 | default: |
| 401 | fmt.Fprint(w, v.Interface()) |
| 402 | } |
| 403 | return nil |
| 404 | } |
| 405 | |
| 406 | // writeQuotedString writes a quoted string in the protocol buffer text format. |
| 407 | func (w *textWriter) writeQuotedString(s string) { |
no test coverage detected