[OpenWrt-Devel] [RFC] libubox/binary.h design proposal
Javier Domingo Cansino
javierdo1 at gmail.com
Sun Oct 4 16:47:11 EDT 2015
Hello,
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.
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.
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.
Cheers!
/*
* Syntax for the function is as follows.
* %[n][a][lb][01r]{i,y,w,d,q,s}
*
* All the characters that don't follow this will be treated as raw chars
* to be written as they are.
*
* Data type
* * i - bit
* * y - byte
* * w - 2 byte word
* * d - 4 byte word
* * q - 8 byte word
* * s - string without termination (use strlen()+1 in quantity to null)
*
* Data value
* * 0 - fill the specified space with zeros
* * 1 - fill the specified space with ones
* * r - fill the specified space with random data
*
* String data type is not valid in this case
*
* Endianess. No conversion by default
* * l - little endian
* * b - big endian
*
* Alignment. No alignment by default
* * a - align this to it's datatype
* bits are aligned to byte
*
* Quantity. One by default
* * n - number of same datatype (placed together)
* this denotes length of string, padded with 0
*
* Some examples:
* * %4lw - 4 little endian 2 byte word
* * %2i - 2 bits 'ab' from value b'000000ab'
* * %2bi - 2 bits 'ab' from value b'000000ba'
* * %2li - 2 bits 'ab' from value b'ab000000'
*
*/
[1] Github branch: https://github.com/txomon/libubox
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20151004/6fdd51c6/attachment.htm>
-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list