package meerkat.bulletinboard.sqlserver.mappers;

import com.google.protobuf.InvalidProtocolBufferException;
import meerkat.protobuf.BulletinBoardApi.BeginBatchMessage;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by Arbel Deutsch Peled on 20-Dec-15.
 */
public class BeginBatchMessageMapper implements RowMapper<BeginBatchMessage> {

    @Override
    public BeginBatchMessage mapRow(ResultSet rs, int rowNum) throws SQLException {
        try {
            return BeginBatchMessage.newBuilder().mergeFrom(rs.getBytes(1)).build();
        } catch (InvalidProtocolBufferException e) {
            return null;
        }
    }

}
