marshalField writes field description and value to the Writer.
(fd protoreflect.FieldDescriptor, v protoreflect.Value, indent string)
| 388 | |
| 389 | // marshalField writes field description and value to the Writer. |
| 390 | func (w *jsonWriter) marshalField(fd protoreflect.FieldDescriptor, v protoreflect.Value, indent string) error { |
| 391 | if w.Indent != "" { |
| 392 | w.write(indent) |
| 393 | w.write(w.Indent) |
| 394 | } |
| 395 | w.write(`"`) |
| 396 | switch { |
| 397 | case fd.IsExtension(): |
| 398 | // For message set, use the fname of the message as the extension name. |
| 399 | name := string(fd.FullName()) |
| 400 | if isMessageSet(fd.ContainingMessage()) { |
| 401 | name = strings.TrimSuffix(name, ".message_set_extension") |
| 402 | } |
| 403 | |
| 404 | w.write("[" + name + "]") |
| 405 | case w.OrigName: |
| 406 | name := string(fd.Name()) |
| 407 | if fd.Kind() == protoreflect.GroupKind { |
| 408 | name = string(fd.Message().Name()) |
| 409 | } |
| 410 | w.write(name) |
| 411 | default: |
| 412 | w.write(string(fd.JSONName())) |
| 413 | } |
| 414 | w.write(`":`) |
| 415 | if w.Indent != "" { |
| 416 | w.write(" ") |
| 417 | } |
| 418 | return w.marshalValue(fd, v, indent) |
| 419 | } |
| 420 | |
| 421 | func (w *jsonWriter) marshalValue(fd protoreflect.FieldDescriptor, v protoreflect.Value, indent string) error { |
| 422 | switch { |
no test coverage detected