Boost logo

Boost :

Subject: Re: [boost] Any interest in bitstream class?
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2013-06-28 11:07:15


> -----Original Message-----
> From: Boost [mailto:boost-bounces_at_[hidden]] On Behalf Of Paul Long
> Sent: Friday, June 28, 2013 2:44 AM
> To: boost_at_[hidden]
> Subject: [boost] Any interest in bitstream class?
>
> Same semantics as, e.g., stringstream, but it operates on binary data. I already have the
analogues to
> istringstream/stringbuf (you can take a look at ibitstream/bitbuf at
https://github.com/dplong/bstream)
> There are some interesting features, but I won't go into them here. If there is interest, I would
> implement obitstream and bitstream and possibly support Boost::dynamic_bitset.
>
> The rationale is _succinct_ expression of predictive parsing of binary data.
>
> I've used ibitstream in production code for decoding RTP headers and frames of various video
encodings.
> Below is a simple function that decodes an RTP header using ibitstream; I also have a GitHub repo
that
> contains more complex code for high-level parsing of H.264 frames at
> https://github.com/dplong/rtspudph264
>
> struct RtpHeader {
> bool padding, marker;
> bitset<7> payloadType;
> WORD sequenceNumber;
> DWORD timestamp, ssrcIdentifier;
> vector<DWORD> csrcIdentifier;
> struct {
> bool present;
> WORD identifier;
> vector<BYTE> contents;
> } extension;
> };
>
> bool ParseRtpHeader(const BYTE *buffer, RtpHeader &rtp) {
> ibitstream bin(buffer);
> static const bitset<2> version(0x2);
> bitset<4> csrcCount;
> WORD extensionLength;
>
> bin >> version >> rtp.padding >> rtp.extension.present
> >> csrcCount >> rtp.marker >> rtp.payloadType
> >> rtp.sequenceNumber >> rtp.timestamp >> rtp.ssrcIdentifier
> >> setrepeat(csrcCount.to_ulong()) >> rtp.csrcIdentifier;
>
> if (rtp.extension.present) {
> bin >> rtp.extension.identifier >> extensionLength
> >> setrepeat(extensionLength * sizeof(DWORD))
> >> rtp.extension.contents;
> }
>
> return bin.good();
> }

Looks very useful - for some.

To get into Boost (in fact to get much further) it needs some tests (using Boost.test of course) and
some fully worked and commented examples, and of course some docs. However I'm delighted to see the
you already have lots of Doxygen comments in the code. These can be used with text and tutorial
stuff in easy-to-use mark-up language Quickbook to provide an indexed reference section that will
meet people's needs. (Contact me privately if you are thinking of embarking on this - I can build a
prototype version that will get you going quickly).

Paul

---
Paul A. Bristow,
Prizet Farmhouse, Kendal LA8 8AB  UK
+44 1539 561830  07714330204
pbristow_at_[hidden]

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk