Validate checks that v.Bytes is structurally consistent with v.Type. It does not check that the actual leaf values when parsed are type compatible with the leaf types.
()
| 478 | // with v.Type. It does not check that the actual leaf |
| 479 | // values when parsed are type compatible with the leaf types. |
| 480 | func (v Value) Validate() (err error) { |
| 481 | defer func() { |
| 482 | if r := recover(); r != nil { |
| 483 | err = fmt.Errorf("panic: %+v\n%s", r, debug.Stack()) |
| 484 | } |
| 485 | }() |
| 486 | return v.Walk(func(typ Type, body scode.Bytes) error { |
| 487 | if _, ok := typ.(*TypeSet); ok { |
| 488 | if err := checkSet(body); err != nil { |
| 489 | return err |
| 490 | } |
| 491 | return SkipContainer |
| 492 | } |
| 493 | if typ, ok := typ.(*TypeEnum); ok { |
| 494 | if err := checkEnum(typ, body); err != nil { |
| 495 | return err |
| 496 | } |
| 497 | return SkipContainer |
| 498 | } |
| 499 | return nil |
| 500 | }) |
| 501 | } |
| 502 | |
| 503 | func checkSet(body scode.Bytes) error { |
| 504 | it := body.Iter() |