On Mon, May 08, 2000 at 09:18:40AM +0200, andreas.sikkema@xxxxxxxxxxx wrote:
> <knip>
>
> Some protocols have values that span a couple of bytes, but do not use both
> endbytes completely (f.i. 6 byte values with bytes 0 and 1 in byte 1 and bits
> 2..5 in byte 2)
>
> I don't know how common this is, but I have just finished a couple of protocols that use this VERY
> much. In my situation it would result in much cleaner code to retrieve bits, instead of bytes. Other
> protocols could just multiply all values by 8, or just use another version of the function....
I'm amenable to something like this.
What arguments would you like to pass to the tvbuff accessor? That is, how
would you specify the bits that you want?
Lets say you have these four bytes:
00 01 02 03
1) How would you specify "bits 0-2 in byte 1"?
2) How would you specify "bits 6-10 in bytes 1-2"
(that is, bits 6-7 in byte 2, and bits 0-2 in byte 1, if you
consider the 16 bits in bytes 1 and 2 to be a single unit (like an
endian-independent uint16), and to count bits from the right)
Perhaps:
guint32
tvb_get_bits(tvbuff_t *tvb, gint offset, gint length, gint bit_start, gint num_bits);
where 'offset' and 'length' specify the bytes to look at, and
'bit_start" and 'num_bits' would be the bits. So, the answers to the questions above
would be:
1) tvb_get_bits(tvb, 1, 1, 0, 2)
2) tvb_get_bits(tvb, 1, 2, 6, 10)
--gilbert