package websocket import ( "git.reya.zone/reya/hexmap/server/state" ) func (x *ClientCommandPB) ToGo() (ClientCommand, error) { switch msg := x.Command.(type) { case nil: return nil, state.ErrOneofNotSet case *ClientCommandPB_Hello: return msg.Hello.ToGo(), nil case *ClientCommandPB_Refresh: return msg.Refresh.ToGo(), nil case *ClientCommandPB_Act: return msg.Act.ToGo() default: panic("A case was missed in ClientCommandPB.ToGo!") } } func (x *ClientHelloPB) ToGo() ClientHello { return ClientHello{ Version: x.Version, } } func (c ClientHello) ToClientPB() *ClientCommandPB { return &ClientCommandPB{ Command: &ClientCommandPB_Hello{ Hello: &ClientHelloPB{ Version: c.Version, }, }, } } func (*ClientRefreshPB) ToGo() ClientRefresh { return ClientRefresh{} } func (c ClientRefresh) ToClientPB() *ClientCommandPB { return &ClientCommandPB{ Command: &ClientCommandPB_Refresh{ Refresh: &ClientRefreshPB{}, }, } } func (x *ClientActPB_IDed) ToGo() (IDed, error) { action, err := x.Action.ToGo() if err != nil { return IDed{}, nil } return IDed{ ID: x.Id, Action: action, }, nil } func (i IDed) ToPB() *ClientActPB_IDed { return &ClientActPB_IDed{ Id: i.ID, Action: i.Action.ToClientPB(), } } func (x *ClientActPB) ToGo() (ClientAct, error) { actions := make(IDPairs, len(x.Actions)) for index, ided := range x.Actions { action, err := ided.ToGo() if err != nil { return ClientAct{}, err } actions[index] = action } return ClientAct{ Actions: actions, }, nil } func (c ClientAct) ToClientPB() *ClientCommandPB { actions := make([]*ClientActPB_IDed, len(c.Actions)) for index, ided := range c.Actions { actions[index] = ided.ToPB() } return &ClientCommandPB{ Command: &ClientCommandPB_Act{ Act: &ClientActPB{ Actions: actions, }, }, } } func (ClientMalformed) ToClientPB() *ClientCommandPB { return nil } func (SocketClosed) ToClientPB() *ClientCommandPB { return nil }