Unmarshal unmarshals the raw data (p.Raw) into v and prepares callbacks. v must be a struct that is the type of expected arguments.
(v interface{})
| 32 | // Unmarshal unmarshals the raw data (p.Raw) into v and prepares callbacks. |
| 33 | // v must be a struct that is the type of expected arguments. |
| 34 | func (p *Partial) Unmarshal(v interface{}) error { |
| 35 | if p == nil { |
| 36 | return fmt.Errorf("Cannot unmarshal nil argument") |
| 37 | } |
| 38 | |
| 39 | if err := json.Unmarshal(p.Raw, &v); err != nil { |
| 40 | return fmt.Errorf("%s. Data: %s", err.Error(), string(p.Raw)) |
| 41 | } |
| 42 | |
| 43 | value := reflect.ValueOf(v) |
| 44 | |
| 45 | for _, spec := range p.CallbackSpecs { |
| 46 | if err := setCallback(value, spec.Path, spec.Function.Caller.(functionReceived)); err != nil { |
| 47 | return err |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | return nil |
| 52 | } |
| 53 | |
| 54 | func (p *Partial) MustUnmarshal(v interface{}) { |
| 55 | err := p.Unmarshal(v) |