package com.njcn.gather.detection.util.socket;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;

/**
 * Generic socket message helper retained by the communication foundation.
 * Stage 4-B removes detection-specific text assembly helpers and keeps only
 * payload parsing and JSON framing methods used by the base transport layer.
 *
 * @author wr
 * @author hongawen
 * @date 2026/04/08
 */
public final class MsgUtil {

    private MsgUtil() {
    }

    public static SocketDataMsg socketDataMsg(String textMsg) {
        return JSON.parseObject(textMsg, SocketDataMsg.class);
    }

    public static String toJsonWithNewLine(Object obj) {
        return JSON.toJSONString(obj, SerializerFeature.PrettyFormat) + "\n";
    }

    public static String toJsonWithNewLinePlain(Object obj) {
        return JSON.toJSONString(obj) + "\n";
    }
}
