package websocket import "git.reya.zone/reya/hexmap/server/action" func (x *ServerCommandPB) ToGo() (ServerCommand, error) { switch msg := x.Command.(type) { case *ServerCommandPB_Hello: return msg.Hello.ToGo() case *ServerCommandPB_Refresh: return msg.Refresh.ToGo() case *ServerCommandPB_Ok: return msg.Ok.ToGo(), nil case *ServerCommandPB_Failed: return msg.Failed.ToGo(), nil case *ServerCommandPB_Act: return msg.Act.ToGo() default: panic("A case was missed in ServerCommandPB.ToGo!") } } func (x *ServerHelloPB) ToGo() (ServerHello, error) { state, err := x.State.ToGo() if err != nil { return ServerHello{}, err } return ServerHello{ Version: x.Version, State: &state, }, nil } func (s ServerHello) ToServerPB() *ServerCommandPB { return &ServerCommandPB{ Command: &ServerCommandPB_Hello{ Hello: &ServerHelloPB{ Version: s.Version, State: s.State.ToPB(), }, }, } } func (x *ServerRefreshPB) ToGo() (ServerRefresh, error) { state, err := x.State.ToGo() if err != nil { return ServerRefresh{}, err } return ServerRefresh{ State: &state, }, nil } func (s ServerRefresh) ToServerPB() *ServerCommandPB { return &ServerCommandPB{ Command: &ServerCommandPB_Refresh{ Refresh: &ServerRefreshPB{ State: s.State.ToPB(), }, }, } } func (x *ServerOKPB) ToGo() ServerOK { ids := make(IDSlice, len(x.Ids)) copy(ids, x.Ids) return ServerOK{ IDs: ids, } } func (s ServerOK) ToServerPB() *ServerCommandPB { ids := make([]uint32, len(s.IDs)) copy(ids, s.IDs) return &ServerCommandPB{ Command: &ServerCommandPB_Ok{ Ok: &ServerOKPB{ Ids: ids, }, }, } } func (x *ServerFailedPB) ToGo() ServerFailed { ids := make(IDSlice, len(x.Ids)) copy(ids, x.Ids) return ServerFailed{ IDs: ids, Error: x.Error, } } func (s ServerFailed) ToServerPB() *ServerCommandPB { ids := make([]uint32, len(s.IDs)) copy(ids, s.IDs) return &ServerCommandPB{ Command: &ServerCommandPB_Failed{ Failed: &ServerFailedPB{ Ids: ids, Error: s.Error, }, }, } } func (x *ServerActPB) ToGo() (ServerAct, error) { actions := make(action.ServerSlice, len(x.Actions)) for index, act := range x.Actions { convertedAct, err := act.ToGo() if err != nil { return ServerAct{}, err } actions[index] = convertedAct } return ServerAct{ Actions: actions, }, nil } func (s ServerAct) ToServerPB() *ServerCommandPB { actions := make([]*action.ServerActionPB, len(s.Actions)) for index, act := range s.Actions { actions[index] = act.ToServerPB() } return &ServerCommandPB{ Command: &ServerCommandPB_Act{ Act: &ServerActPB{ Actions: actions, }, }, } } func (SocketClosed) ToServerPB() *ServerCommandPB { return nil }