Skip to content

Commit

Permalink
Add the bytearray
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Aug 14, 2021
1 parent dbfb52e commit a3fdbce
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions include/cpp_bytearray.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#include <stdint.h>

struct bytearray {
uint8_t *data;
int myLength;

bytearray() {
data = NULL;
}

void alloc(int elements) {
myLength = elements;
data = new uint8_t[myLength];
}

void free() {
delete[] data;
data = NULL;
}

int byteLength() {
return myLength;
}

float get(int index) {
return data[index];
}

float set(int index, float value) {
return data[index] = value;
}

bytearray slice(int begin, int end) {
bytearray arr;
arr.data = &data[begin];
arr.myLength = end - begin;
return arr;
}
};

0 comments on commit a3fdbce

Please sign in to comment.