<div dir="ltr">Hello,<div><br></div><div>I asked Friday on IRC how to write blobs, I was suggested using blob_raw_put from libubox/blob.h, but as I have to implement a binary protocol that uses different endianess, non aligned data etc., I think the best solution is creating a set of helper functions to write/read blobs.</div><div><br class="Apple-interchange-newline">As this is quite generic library, there might already exist some work done that I am missing (please link!). I would love to have feedback from this design before typing code.<br></div><div><br></div><div>I have started my work on github[1], which is basically a header file with the following comment and some prototype ideas. The syntax I have thought is described there, but it basically follows a printf syntax, allowing raw chars to be written.</div><div><br></div><div>Cheers!</div><div><br></div><div><div>/*</div><div> * Syntax for the function is as follows.</div><div> *   %[n][a][lb][01r]{i,y,w,d,q,s}</div><div> *   </div><div> *   All the characters that don't follow this will be treated as raw chars</div><div> *   to be written as they are.</div><div> *</div><div> * Data type</div><div> *   * i - bit</div><div> *   * y - byte</div><div> *   * w - 2 byte word</div><div> *   * d - 4 byte word</div><div> *   * q - 8 byte word</div><div> *   * s - string without termination (use strlen()+1 in quantity to null)</div><div> *</div><div> * Data value</div><div> *   * 0 - fill the specified space with zeros</div><div> *   * 1 - fill the specified space with ones</div><div> *   * r - fill the specified space with random data</div><div> *</div><div> *   String data type is not valid in this case</div><div> *</div><div> * Endianess. No conversion by default</div><div> *   * l - little endian</div><div> *   * b - big endian</div><div> *</div><div> * Alignment. No alignment by default</div><div> *   * a - align this to it's datatype</div><div> *         bits are aligned to byte</div><div> *</div><div> * Quantity. One by default</div><div> *   * n - number of same datatype (placed together)</div><div> *         this denotes length of string, padded with 0</div><div> *</div><div> * Some examples:</div><div> *   * %4lw - 4 little endian 2 byte word</div><div> *   * %2i  - 2 bits 'ab' from value b'000000ab'</div><div> *   * %2bi - 2 bits 'ab' from value b'000000ba'</div><div> *   * %2li - 2 bits 'ab' from value b'ab000000'</div><div> *</div><div> */</div></div><div><br></div><div><div><br></div></div><div>[1] Github branch: <a href="https://github.com/txomon/libubox">https://github.com/txomon/libubox</a></div></div>