parseExperimentState unmarshals raw JSON into an ExperimentState. Returns an empty state when parsing fails or the data is invalid.
(data []byte)
| 644 | // parseExperimentState unmarshals raw JSON into an ExperimentState. |
| 645 | // Returns an empty state when parsing fails or the data is invalid. |
| 646 | func parseExperimentState(data []byte) *ExperimentState { |
| 647 | var state ExperimentState |
| 648 | if err := json.Unmarshal(data, &state); err != nil { |
| 649 | return emptyExperimentState() |
| 650 | } |
| 651 | // Validate: state.json must have a counts object. |
| 652 | if state.Counts == nil { |
| 653 | state.Counts = map[string]map[string]int{} |
| 654 | } |
| 655 | return &state |
| 656 | } |
| 657 | |
| 658 | // emptyExperimentState returns a zero-value ExperimentState with an initialised Counts map. |
| 659 | func emptyExperimentState() *ExperimentState { |