/.metadata/.plugins/org.eclipse.core.resources/.history/69/10459600d7a2001e1d98c762f0e1eac2

https://bitbucket.org/fixpoint/connexion · #! · 53 lines · 44 code · 9 blank · 0 comment · 0 complexity · edffbbb99d1537dfeb9e2de2921775ad MD5 · raw file

  1. package info.reflectionsofmind.connexion.platform.control.cts.message;
  2. import info.reflectionsofmind.connexion.platform.control.cts.IClientToServerMessage;
  3. import info.reflectionsofmind.connexion.platform.control.cts.IClientToServerMessageDispatchTarget;
  4. import info.reflectionsofmind.connexion.platform.game.IAction;
  5. import info.reflectionsofmind.connexion.transport.ITransport.INode;
  6. import info.reflectionsofmind.connexion.util.convert.ClassBasedJsonCoder;
  7. import info.reflectionsofmind.connexion.util.convert.DecodingException;
  8. import info.reflectionsofmind.connexion.util.convert.EncodingException;
  9. import info.reflectionsofmind.connexion.util.convert.ICoder;
  10. import org.json.JSONObject;
  11. public class MsgActionRequest implements IClientToServerMessage
  12. {
  13. private final IAction action;
  14. public MsgActionRequest(final IAction action)
  15. {
  16. this.action = action;
  17. }
  18. public void dispatch(final IClientToServerMessageDispatchTarget target, final INode sender)
  19. {
  20. target.onClientAction(this, sender);
  21. }
  22. public IAction getAction()
  23. {
  24. return this.action;
  25. }
  26. public static final class Coder extends ClassBasedJsonCoder<MsgActionRequest>
  27. {
  28. @Override
  29. protected Class<? extends MsgActionRequest> getEncodableClass()
  30. {
  31. return MsgActionRequest.class;
  32. }
  33. @Override
  34. protected MsgActionRequest decodeJson(final JSONObject json) throws DecodingException
  35. {
  36. return new MsgActionRequest(this.actionCoder.decode(json.getJSONObject("action").toString()));
  37. }
  38. @Override
  39. protected JSONObject encodeJson(final MsgActionRequest object) throws EncodingException
  40. {
  41. return new JSONObject().put("action", this.actionCoder.encode(object.getAction()));
  42. }
  43. }
  44. }