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

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 ServerResponseData extends ResponseData {

    private byte status = 1;

    @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 1;
    }

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