package com.njzscloud.common.localizer.jt808.message;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
public class ServerGeneralReplyMessage implements ServerMessageBody {
    /**
     * 消息ID
     */
    private int messageId;
    /**
     * 流水号
     */
    private int flowId;
    /**
     * 结果码，0 成功，其他失败
     */
    private int result;


    @Override
    public byte[] toBytes() {
        ByteBuf body = Unpooled.buffer();
        try {
            body.writeShort(flowId);
            body.writeShort(messageId);
            body.writeByte(result);
            return ByteBufUtil.getBytes(body);
        } finally {
            body.release();
        }
    }
}
