Boost logo

Boost :

Subject: Re: [boost] [boost::endian] Request for comments/interest
From: Tomas Puverle (Tomas.Puverle_at_[hidden])
Date: 2010-05-30 11:27:24


Terry,

> template<endian_t, int w1, int w2=0, int w3=0, int w4=0, int w5=0>
> struct bitfield {
> char placeholder[(w1 + w2 + w3 + w4 + w5 + 7)/8];
> }; // bitfield

By the way, you could always plug into the facility for swapping user defined
types for the above.

> struct UserMessage {
> endian<little, time_point<system_clock, duration<int64_t, nano> > >
> timestamp;

I was under the impression that Beman's library doesn't support any types
beside integers? This definitely looks like a user defined type to me.

> struct Position {
> endian<little, quantity<si::length, int32_t> > x;
> endian<little, quantity<si::length, int32_t> > y;
> endian<little, quantity<si::length, int32_t> > z;
> } position;

Again, UDTs?

> struct Packet {
> internet::IpHeader ipHeader;
> internet::UdpHeader udpHeader;
> UserMessage userMessage;
> }; // Packet
> #pragma pack(pop)
>
> int main() {
> Packet packet;
> packet.ipHeader.source_address = 0x12345678;
> packet.udpHeader.destination_port = 1234;
> packet.userMessage.timestamp = system_clock::now();
> packet.userMessage.position.y = 17 * si::meter;
> } // main

I definitely see the elegance of this code and as I said before, I am not
opposed to implementing the typed interface. Having said that, I do have
several concerns with how this gets actually read from/sent to a device and
additionally, as mentioned in another post, I think this "neat" code may be a
little opaque for someone not familiar with it.

Tom


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