You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
hexmap/server/ws/client.pbconv.go

99 lines
1.9 KiB

package ws
import (
"git.reya.zone/reya/hexmap/server/action"
"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() (action.IDed, error) {
act, err := x.Action.ToGo()
if err != nil {
return action.IDed{}, nil
}
return action.IDed{
ID: x.Id,
Action: act,
}, nil
}
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 nil, 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] = &ClientActPB_IDed{
Id: ided.ID,
Action: ided.Action.ToClientPB(),
}
}
return &ClientCommandPB{
Command: &ClientCommandPB_Act{
Act: &ClientActPB{
Actions: actions,
},
},
}
}
func (*ClientMalformed) ToClientPB() *ClientCommandPB {
return nil
}
func (*SocketClosed) ToClientPB() *ClientCommandPB {
return nil
}