price-is-wrong/pkg/state/priceiswrong/internal/event.go

50 lines
805 B
Go

package priceiswrong
import (
"fmt"
"gitea/price-is-wrong/pkg/lib/event"
)
type Event interface{}
type Players struct {
IDs []int
}
type Host struct {
ID int
}
type Score struct {
ID int
Score int
}
type Item struct {
ImageURL string
Title string
Description string
Value string
}
type Guess struct {
ID int
Guess string
}
func ParseEvent(b []byte) (Event, error) {
typesToPointers := map[string]any{
"*priceiswrong.Players": &Players{},
"*priceiswrong.Host": &Host{},
"*priceiswrong.Score": &Score{},
"*priceiswrong.Item": &Item{},
"*priceiswrong.Guess": &Guess{},
}
t, err := event.Parse(b, typesToPointers)
return typesToPointers[t], err
}
func MarshalEvent(e Event) ([]byte, error) {
return event.Serialize(fmt.Sprintf("%T", e), e)
}