smplbuf_u8<32> b;auto&& bs =b.get_stream_helper(); // helper object// Data String Generationuint8_t FOURCHARS[]={'A','B','C','D'};bs << FOURCHARS;bs <<';';bs <<uint32_t(0x30313233); // "0123"bs <<format(";%d",99);Serial << b << crlf; // Output to Serial via smplbuf_u8<32> class//Result: ABCD;0123;99
Helper object type names are resolved by auto&& because they are long. The interfaces defined in mwx::stream, such as << operator, can be used for this object.
The generated helper object bs starts reading/writing from the beginning of the main array b when it is created. If it is at the end of the array, data is added by append(). Each time a read/write operation is performed, the position is moved to the next one.
Helper functions can use the >> operator for reading.
//..Continuation of the above example// ABCD;0123;99 <- stored in b//Variable for storing read datauint8_tFOURCHARS_READ[4];uint32_t u32val_read;uint8_tc_read[2];// Read out by operator>>bs.rewind(); //Rewind the position to the beginning.bs >> FOURCHARS_READ; //4 charsbs >> mwx::null_stream(1); //1 char skippingbs >> u32val_read; //32bit databs >> mwx::null_stream(1); //1 char skippingbs >> c_read; //2 chars// ResultSerial << crlf <<"4chars="<< FOURCHARS_READ;Serial << crlf <<format("32bit val=0x%08x", u32val_read);Serial << crlf <<"2chars="<< c_read;// 4chars=ABCD// 32bit val=0x30313233// 2chars=99