transdep/messages/zonecut/result.go

36 lines
759 B
Go
Raw Permalink Normal View History

2018-01-23 20:25:00 +00:00
package zonecut
import (
"encoding/json"
"github.com/ANSSI-FR/transdep/errors"
)
type serializedResult struct {
Result *Entry `json:"result,omitempty"`
Err *errors.ErrorStack `json:"error,omitempty"`
}
// result is used for serialization of entries/errors for caching purposes as well as for transmission between
// goroutines using channels
type result struct {
Result *Entry
Err *errors.ErrorStack
}
func (r *result) MarshalJSON() ([]byte, error) {
sr := new(serializedResult)
sr.Result = r.Result
sr.Err = r.Err
return json.Marshal(sr)
}
func (r *result) UnmarshalJSON(bstr []byte) error {
sr := new(serializedResult)
if err := json.Unmarshal(bstr, sr) ; err != nil {
return err
}
r.Result = sr.Result
r.Err = sr.Err
return nil
}