0

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?
dos
  • 135
  • 1
  • 6
  • Generally speaking, "parse" means reading a data structure from a string,... sort of...it's a part of deserialization. Writing to a string generally doesn't involve parsing and is usually simply termed "serialization". – Edward Strange Apr 23 '13 at 15:37
  • consider using boost::serialization – andre Apr 23 '13 at 15:47
  • thank you. I'm sorry for the wording problem - I do now see that I meant serialization. Even though I can not find anything usable in boost::serialization to get a boost::tuple into a stream of characters. Would you mind pointing me into the right direction, please? Because so far I still find it easier to iterate trough the tuple and append the strings. – dos Apr 29 '13 at 11:17

0 Answers0