(fd protoreflect.FieldDescriptor, v protoreflect.Value, indent string)
| 512 | } |
| 513 | |
| 514 | func (w *jsonWriter) marshalSingularValue(fd protoreflect.FieldDescriptor, v protoreflect.Value, indent string) error { |
| 515 | switch { |
| 516 | case !v.IsValid(): |
| 517 | w.write("null") |
| 518 | return nil |
| 519 | case fd.Message() != nil: |
| 520 | return w.marshalMessage(v.Message(), indent+w.Indent, "") |
| 521 | case fd.Enum() != nil: |
| 522 | if fd.Enum().FullName() == "google.protobuf.NullValue" { |
| 523 | w.write("null") |
| 524 | return nil |
| 525 | } |
| 526 | |
| 527 | vd := fd.Enum().Values().ByNumber(v.Enum()) |
| 528 | if vd == nil || w.EnumsAsInts { |
| 529 | w.write(strconv.Itoa(int(v.Enum()))) |
| 530 | } else { |
| 531 | w.write(`"` + string(vd.Name()) + `"`) |
| 532 | } |
| 533 | return nil |
| 534 | default: |
| 535 | switch v.Interface().(type) { |
| 536 | case float32, float64: |
| 537 | switch { |
| 538 | case math.IsInf(v.Float(), +1): |
| 539 | w.write(`"Infinity"`) |
| 540 | return nil |
| 541 | case math.IsInf(v.Float(), -1): |
| 542 | w.write(`"-Infinity"`) |
| 543 | return nil |
| 544 | case math.IsNaN(v.Float()): |
| 545 | w.write(`"NaN"`) |
| 546 | return nil |
| 547 | } |
| 548 | case int64, uint64: |
| 549 | w.write(fmt.Sprintf(`"%d"`, v.Interface())) |
| 550 | return nil |
| 551 | } |
| 552 | |
| 553 | b, err := json.Marshal(v.Interface()) |
| 554 | if err != nil { |
| 555 | return err |
| 556 | } |
| 557 | w.write(string(b)) |
| 558 | return nil |
| 559 | } |
| 560 | } |
no test coverage detected