(dst *ParsedMeasurement, src *structpb.Struct, prefix string)
| 546 | } |
| 547 | |
| 548 | func parse(dst *ParsedMeasurement, src *structpb.Struct, prefix string) error { |
| 549 | for k, v := range src.GetFields() { |
| 550 | path := fmt.Sprintf("%s%s", prefix, k) |
| 551 | parser, ok := fieldParsers[path] |
| 552 | if !ok { |
| 553 | return errUnknownField.WithAttributes("path", path) |
| 554 | } |
| 555 | if errs := parser(&dst.Measurement, v, path); errs != nil { |
| 556 | for _, err := range errs { |
| 557 | if !errors.IsDataLoss(err) { |
| 558 | return err |
| 559 | } |
| 560 | dst.ValidationErrors = append(dst.ValidationErrors, err) |
| 561 | } |
| 562 | continue |
| 563 | } |
| 564 | if s, ok := v.Kind.(*structpb.Value_StructValue); ok { |
| 565 | nested := &ParsedMeasurement{ |
| 566 | Measurement: dst.Measurement, |
| 567 | Valid: &structpb.Struct{ |
| 568 | Fields: make(map[string]*structpb.Value), |
| 569 | }, |
| 570 | } |
| 571 | if err := parse(nested, s.StructValue, path+"."); err != nil { |
| 572 | return err |
| 573 | } |
| 574 | dst.Measurement = nested.Measurement |
| 575 | dst.ValidationErrors = append(dst.ValidationErrors, nested.ValidationErrors...) |
| 576 | if len(nested.Valid.Fields) > 0 { |
| 577 | dst.Valid.Fields[k] = &structpb.Value{ |
| 578 | Kind: &structpb.Value_StructValue{ |
| 579 | StructValue: nested.Valid, |
| 580 | }, |
| 581 | } |
| 582 | } |
| 583 | } else { |
| 584 | dst.Valid.Fields[k] = v |
| 585 | } |
| 586 | } |
| 587 | return nil |
| 588 | } |
no test coverage detected