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

com.github.javaclub.mq.common.netty.protocol.SubLoadReportProtocol Maven / Gradle / Ivy

The newest version!
package com.github.javaclub.mq.common.netty.protocol;

import io.netty.buffer.ByteBuf;


public class SubLoadReportProtocol extends AbstractProtocol {
    private static byte code = CodeProtocol.sub_load_report;
    private int subId;
    private int time;
    private long rt;

    @Override
    public void encode(ByteBuf out) {
        super.setCode(code);
        super.encode(out);
        out.writeInt(subId);
        out.writeInt(time);
        out.writeLong(rt);
    }

    @Override
    public int decode(ByteBuf in) {
        int readindex = super.decode(in);
        if (readindex != -1) {
            if(in.readableBytes() >= 4 + 4 +8)
            {
                subId = in.readInt();
                time = in.readInt();
                rt = in.readLong();
                return 0;
            }
            else{
                in.readerIndex(readindex); // 恢复readindex
                return -1;
            }
        }
        return -1;
    }

    public byte getCode() {
        return code;
    }

    public void setCode(byte code) {
        SubLoadReportProtocol.code = code;
    }

    public int getSubId() {
        return subId;
    }

    public void setSubId(int subId) {
        this.subId = subId;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }

    public long getRt() {
        return rt;
    }

    public void setRt(long rt) {
        this.rt = rt;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy