blob: 5f1db8b8722980673ea3c67531a0fd5823657a27 [file] [log] [blame] [raw]
package com.grahamedgecombe.smpd.net.codec;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import com.grahamedgecombe.smpd.msg.ChatMessage;
import com.grahamedgecombe.smpd.util.ChannelBufferUtils;
public final class ChatMessageCodec extends MessageCodec<ChatMessage> {
public ChatMessageCodec() {
super(ChatMessage.class, 0x03);
}
@Override
public ChatMessage decode(ChannelBuffer buffer) {
String message = ChannelBufferUtils.readString(buffer);
return new ChatMessage(message);
}
@Override
public ChannelBuffer encode(ChatMessage message) {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
ChannelBufferUtils.writeString(buffer, message.getMessage());
return buffer;
}
}