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

import cn.hutool.core.util.CharsetUtil;
import io.netty.buffer.ByteBuf;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

@Getter
@Setter
@ToString
@Accessors(chain = true)
public class TerminalTxtMessage {
    private byte type;
    /**
     * 文本信息
     */
    private String txt;

    public TerminalTxtMessage(ByteBuf body) {
        this.type = body.readByte();
        this.txt = body.toString(body.readerIndex(), body.readableBytes(),
                this.type == 0x00 ?
                        CharsetUtil.CHARSET_GBK :
                        CharsetUtil.CHARSET_UTF_8);
    }
}
