Boost logo

Boost Users :

From: Graham Reitz (graham.cpp_at_[hidden])
Date: 2008-05-29 17:28:18


I am having a little trouble getting this to work. Here's an example
I am working on:

#include <boost/integer/endian.hpp>

struct data
{
    boost::integer::little8_t first;
    boost::integer::little8_t second;
    boost::integer::little16_t third;
};

int main(int argc, char *argv[])
{
    std::vector<unsigned char> binary_buffer;

    binary_buffer.push_back(0x03);
    binary_buffer.push_back(0x06);
    binary_buffer.push_back(0x00);
    binary_buffer.push_back(0x09);

    data_record dr;

    std::copy(binary_buffer.begin(), binary_buffer.end(), /* need an
iterator to &dr? */);

    return 0;
}

Am I doing this correctly?

thanks,
graham

On Thu, May 29, 2008 at 1:37 PM, Scott McMurray <me22.ca+boost_at_[hidden]> wrote:
> On Thu, May 29, 2008 at 2:19 PM, Graham Reitz <graham.cpp_at_[hidden]> wrote:
>>
>> ...would like to convert to this in a C++'ish style using a boost
>> facility if it exists: (or consider directing me somewhere else if it
>> doesn't)
>>
>
> There isn't at the moment.
>
> However, Beman Dawes has recently updated his proposed Boost.Endian
> library (http://tinyurl.com/4bswsh), and there is a discussion about
> it over on the dev list
> (http://lists.boost.org/Archives/boost/2008/05/137820.php and
> followups).
>
> It would allow you to say (something like)
>
> struct // or class
> {
> boost::endian::uint_t<16, boost::endian::big_endian> first;
> boost::endian::uint_t<32, boost::endian::big_endian> second;
> } data;
>
> Which you could then std::copy your data into (through char*s), and
> use the implicit conversions to get native integral types out.
>
> HTH,
> ~ Scott
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net