shift-left-buffer1

nazarijtipusak080/buffer1/shift-left-buffer1

Shifts the contents of the buffer by a byte to the left.
shift-left-buffer1
@/shift-left-buffer1
Shifts the contents of the buffer by a byte to the left.
buffer1@/buffer1
lennumber
triggerpulse
shift-left-buffer1
buffer1
len
trigger
done
ERR
ERRpulse
donepulse
To use the node in your project you should have the nazarijtipusak080/buffer1 library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

struct State {
    // не використовується
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    if (!isInputDirty<input_trigger>(ctx)) return;

    // Отримуємо об'єкт буфера
    auto _object = getValue<input_buffer1>(ctx); // буфер
    uint16_t len = static_cast<uint16_t>(getValue<input_len>(ctx));

    // Перевірка, чи існує буфер і чи є правильна довжина
    if (!_object->buffer || len > _object->len) {
        emitValue<output_ERR>(ctx, 1);  // видаємо помилку
        return;
    }

    // Зсув байтів вліво
    for (uint16_t i = 1; i < len; i++) {
        reinterpret_cast<uint8_t*>(_object->buffer)[i - 1] = reinterpret_cast<uint8_t*>(_object->buffer)[i];
    }
    
    // Очищуємо останній байт
    reinterpret_cast<uint8_t*>(_object->buffer)[len - 1] = 0;

    // Виводимо успіх
    emitValue<output_done>(ctx, 1);
}