All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.feingto.iot.common.codec.MqttWebSocketCodec Maven / Gradle / Ivy

There is a newer version: 2.3.3.RELEASE
Show newest version
package com.feingto.iot.common.codec;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageCodec;
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;

import java.util.List;

/**
 * WebSocket Mqtt 消息编解码器
 *
 * @author longfei
 */
public class MqttWebSocketCodec extends MessageToMessageCodec {
    @Override
    protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List out) {
        if (msg == null) {
            return;
        }
        out.add(new BinaryWebSocketFrame(msg.retain()));
    }

    @Override
    protected void decode(ChannelHandlerContext ctx, BinaryWebSocketFrame msg, List out) {
        out.add(msg.retain().content());
    }
}