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

com.godmao.mqbroker.handler.BindMessageEncoderHandler Maven / Gradle / Ivy

There is a newer version: 0.2.7.RELEASE
Show newest version
package com.godmao.mqbroker.handler;

import com.godmao.mqbroker.message.BindMessage;
import com.godmao.netty.handler.AbstractEncoderHandler;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelHandler;

@ChannelHandler.Sharable
public class BindMessageEncoderHandler extends AbstractEncoderHandler {

    public static final BindMessageEncoderHandler INSTANCE = new BindMessageEncoderHandler();

    @Override
    public ByteBuf encode(BindMessage msg) {
        final byte cmd = msg.getCmd();
        final String name = msg.getName();
        final String address = msg.getAddress();
        final byte[] name_bytes = name.getBytes();
        final byte[] address_bytes = address.getBytes();

        ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer(5 + address_bytes.length + name_bytes.length);
        byteBuf.writeByte(cmd);//1
        byteBuf.writeInt(name_bytes.length);//4
        byteBuf.writeBytes(name_bytes);
        byteBuf.writeBytes(address_bytes);
        return byteBuf;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy