Skip to content
Discussion options

You must be logged in to vote

You can pass a readable and writable bytearray to a C module quite easily, in fact the following example function in a C module will accept a bytearray, memoryview or array (or any r/w python object which supports the "buffer protocol") (I'm not sure if that actually will help with your application):

STATIC mp_obj_t my_function(mp_obj_t buf_obj) {
    // Get a pointer to the data of the supplied buffer (eg. bytearray)
    mp_buffer_info_t buf;
    mp_get_buffer_raise(buf_obj, &buf, MP_BUFFER_RW);

    // buf.len is length of the supplied data buffer.
    // buf.buf is a void * ptr to the contiguous data underlying the bytearray or array
    // Process the bytearray underlying data....

    

Replies: 1 comment 15 replies

Comment options

You must be logged in to vote
15 replies
@iBigDane
Comment options

@nspsck
Comment options

@iBigDane
Comment options

@nspsck
Comment options

@iBigDane
Comment options

Answer selected by nspsck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
ESP32
Labels
None yet
3 participants