Skip to content

Instantly share code, notes, and snippets.

@yongboy
Created May 20, 2014 14:28
Show Gist options
  • Save yongboy/0bb76623f2a45d82bbf3 to your computer and use it in GitHub Desktop.
Save yongboy/0bb76623f2a45d82bbf3 to your computer and use it in GitHub Desktop.
package io.mqtt.handler.coder;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import java.util.List;
import org.meqantt.message.Message;
@Sharable
public class MqttMessageNewEncoder extends MessageToMessageEncoder<Object> {
@Override
protected void encode(ChannelHandlerContext ctx, Object msg,
List<Object> out) throws Exception {
if (!(msg instanceof Message)) {
return;
}
byte[] data = ((Message) msg).toBytes();
out.add(Unpooled.wrappedBuffer(data));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment