I’ve now seen several libraries that want to read/write buffers (I2C, Neopixel, for example): the buffers are
In my libraries, I could provide a
[custom-type](https://xod.io/docs/guide/custom-types/), but then it would be specific to a particular library. I’ve avoided implementing patches for this reason.
I think it is common enough, and important enough, to warrant adding to core. XOD
static allocation/initialization I think, so it would use the heap (alloc/new).
The obvious buffer should just be of type
byte . I have not considered other buffer types!
buffer(number-of-bytes) -> buffer-objectof type xod/core/byte-buffer
- Should the
buffer-objectcarry it’s allocated-size with it?
- Is there a “smart” buffer type in std-c+±lib or boost or somewhere popular?
- Should the
- The implicit
- The specializers for it:
- The specializer
equalwhich tests the
buffer-objectsfor addresses for equality
set-byte(buffer, int i, byte value)sets
read-byte(buffer, int i) -> byte valuegets a byte at
Typical patches that use this type would take 2 inputs: the
buffer-object and a
byte-count for some action (read-i2c-bytes) may be different from the allocated size, of course. In the spirit of being more robust than C, we should perhaps include the allocated-size in the
buffer-object and check against the requested read/write size!