package com.lanyuanxiaoyao.service.executor.task.functions.pulsar;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.Serializable;
import org.apache.flink.core.io.SimpleVersionedSerializer;

/**
 * @author lanyuanxiaoyao
 * @date 2024-01-18
 */
public class ReadPulsarVersionedSplitSerializer implements SimpleVersionedSerializer<ReadPulsarSplit>, Serializable {
    private final ObjectMapper mapper = new ObjectMapper();

    @Override
    public int getVersion() {
        return 0;
    }

    @Override
    public byte[] serialize(ReadPulsarSplit obj) throws IOException {
        return mapper.writeValueAsBytes(obj);
    }

    @Override
    public ReadPulsarSplit deserialize(int version, byte[] serialized) throws IOException {
        return mapper.readValue(serialized, ReadPulsarSplit.class);
    }
}
