com.github.edgar615.util.event.MessageCodec Maven / Gradle / Ivy
package com.github.edgar615.util.event;
import java.util.HashMap;
import java.util.Map;
/**
* Created by Edgar on 2017/3/22.
*
* @author Edgar Date 2017/3/22
*/
public class MessageCodec implements EventActionCodec {
@Override
public EventAction decode(Map map) {
String resource = (String) map.get("resource");
Map content = (Map) map.get("content");
return Message.create(resource, content);
}
@Override
public Map encode(EventAction action) {
Message message = (Message) action;
Map map = new HashMap<>();
map.put("resource", message.resource());
map.put("content", message.content());
return map;
}
@Override
public String name() {
return Message.TYPE;
}
}