package com.pwt.netty.common.charger.client;

import com.pwt.netty.common.charger.MessageData;
import com.pwt.netty.common.charger.ResponseData;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@EqualsAndHashCode(callSuper = true)
public class ClientResponseData extends ResponseData {

    /**
     * 1 肯定响应, 0 否定响应
     */
    private byte status;

    @Override
    public void encode(ByteBuf byteBuf) throws Exception {
        byteBuf.writeByte(status);
        byteBuf.writeByte(getEnd());
    }

    @Override
    public void decode(ByteBuf byteBuf) throws Exception {
        status = byteBuf.readByte();
        // skip end
        byteBuf.skipBytes(1);
    }

    @Override
    public int getProtocolLength() {
        return 2;
    }

    @Override
    public byte getEnd() {
        return 0x16;
    }
}
