package com.mortals.xhx.queue;

import com.alibaba.fastjson.JSON;
import com.mortals.xhx.common.model.DefaultTbQueueMsgHeaders;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.json.JSONObject;

import java.util.UUID;

/**
 * 默认消息
 *
 * @author: zxfei
 * @date: 2021/11/22 10:59
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DefaultTbQueueMsg implements TbQueueMsg {
    /**
     * key 唯一标识
     */
    private  String key;
    /**
     * 数据载体
     */
    private  byte[] data;
    /**
     * 消息头信息
     */
    private  TbQueueMsgHeaders headers;

    public DefaultTbQueueMsg(TbQueueMsg msg) {
        this.key = msg.getKey();
        this.data = msg.getData();
        TbQueueMsgHeaders headers = new DefaultTbQueueMsgHeaders();
        msg.getHeaders().getData().forEach(headers::put);
        this.headers = headers;
    }


    public static void main(String[] args) {
//        DefaultTbQueueMsg defaultTbQueueMsg = new DefaultTbQueueMsg(UUID.randomUUID(),"string".getBytes(),null);
//
//        String ret = JSON.toJSONString(defaultTbQueueMsg);
//        System.out.println("pro:"+ret);
//
//        DefaultTbQueueMsg qu = JSON.parseObject(ret, DefaultTbQueueMsg.class);
//
//        System.out.println("after:"+qu.toString());

    }

}
