// SPDX-License-Identifier: BSD-3-Clause

#include "device.h"

namespace voltronic {

void SharedIOBuffer::resetWith(const u8* inbuf,
                               size_t inbufSize,
                               u8* outbuf,
                               size_t outbufSize) {
    // set input
    inputBuffer = inbuf;
    inputBufferSize = inbufSize;

    outputBuffer = outbuf;
    outputBufferSize = outbufSize;

    // clean output
    errorType = ErrorType::None;
    errorMessage.erase();
    dataSize = 0;

    // mark as ready
    state = SharedIOBufferState::Ready;
}

void SharedIOBuffer::setResult(ErrorType type, std::string message) {
    errorType = type;
    errorMessage = std::move(message);
    state = SharedIOBufferState::Done;
}

void SharedIOBuffer::setResult(size_t _dataSize) {
    dataSize = _dataSize;
    state = SharedIOBufferState::Done;
}

}