ussd-data-connect/pkg/event/event.go

33 lines
497 B
Go
Raw Permalink Normal View History

package event
import "encoding/json"
type (
Event struct {
Timestamp int64 `json:"timestamp"`
Type uint16 `json:"type"`
Value string `json:"payload"`
}
)
func (e Event) Serialize() ([]byte, error) {
jsonData, err := json.Marshal(e)
if err != nil {
return nil, err
}
return jsonData, err
}
func Deserialize(jsonData []byte) (Event, error) {
var (
event Event
)
if err := json.Unmarshal(jsonData, &event); err != nil {
return event, err
}
return event, nil
}