#include <modbus/ModbusFramer.h>

namespace modbus {

softbus::core::FrameResult ModbusFramer::extract(const uint8_t* data, std::size_t size)
{
    softbus::core::FrameResult result;
    if (size < 7 || data[1] != 0x03) {
        return result;
    }

    const std::size_t byteCount = data[2];
    const std::size_t frameSize = 3 + byteCount + 2;
    if (size < frameSize) {
        return result;
    }

    result.success = true;
    result.frameStartOffset = 0;
    result.consumedBytes = frameSize;
    result.frame.assign(data, data + frameSize);
    return result;
}

} // namespace modbus
