Parsing a Boost:Tuple into a char* (with endianess)

124 Views Asked by At

I have many classes with varying implementations of their private member boost::tuple<> structures ie. <std::string, int> or <short, short, float>. I now need to parse that tuple into a private const char* message (since I want to send it via tcp), but not without changing the endianess on those data types that need their endianess changed.

This i what I have so far:

struct parseTuple{
    template<typename T>
    void operator()(T& t) const{
        std::cout << ntohl(t) << "\n";
    }
};

void Base::createMessageFromTuple(){
    boost::fusion::for_each(this->structure, parseTuple());
}

There are a few things I think I need to know before I can proceed:

  1. How to keep track of the tuple members so i can allocate space for the message according to their datatypes (static member, maybe?)

  2. How to differentiate in the template between the datatypes that fit the ntohl requirements and those that need different treatment i.e. std::string

  3. Is this even the correct approach?
0

There are 0 best solutions below