Sorry, just a small addendum:

The interest being to not save the names for each field, the
serialization operator for the second, non functioning version must of
course be as below. The error remains unaffected by this change.

Thanks,
Michael

void operator<<= (cxxtools::SerializationInfo& si, const Object& object)
{
  si.setTypeName("Object");
  si.addMember() <<= object.stringValue();
  si.addMember() <<= object.intValue();
  si.setCategory(cxxtools::SerializationInfo::Array);
}

On 03/03/15 12:20, Michael Gius wrote:
> Hi List,
>
> Below is a small test program derived from the cxxtools demo
> serialization.cpp which serializes in binary to a file and reads the
> information back in. This works perfectly fine and outputs "HelloWorld".
> If however I change the serialization operators definition to use
> unnamed array members (source at the end) as pointed out by Tommy in
> http://sourceforge.net/p/tntnet/mailman/message/32265732/ an error is
> produced:
>
> "unknown serialization type code <7f>"
>
> In cxxtools/bin/serializer.h this code is actually defined as
> TypePlainOther but does not seem to be processed in the parser.
>
> I am unsure if this is a bug, or if it is simply my deserialization
> operator, that is badly defined.
>
> Thanks for your input,
> Michael
>
>
>
> Working program (compile with: g++ <filename> -lcxxtools -lcxxtools-bin)
>
> #include <iostream>
> #include <fstream>
> #include <cxxtools/bin/bin.h>
>
> class Object
> {
>     friend void operator>>= (const cxxtools::SerializationInfo& si,
> Object& object);
>
>     std::string _stringValue;
>     int _intValue;
>
>   public:
>     Object()
>       : _intValue(0)
>       { }
>
>     Object(const std::string& stringValue, int intValue)
>       : _stringValue(stringValue),
>         _intValue(intValue)
>       { }
>
>     const std::string& stringValue() const
>     { return _stringValue; }
>
>     int intValue() const
>     { return _intValue; }
> };
>
> void operator<<= (cxxtools::SerializationInfo& si, const Object& object)
> {
>   si.setTypeName("Object");
>   si.addMember("stringValue") <<= object.stringValue();
>   si.addMember("intValue") <<= object.intValue();
> }
>
> void operator>>= (const cxxtools::SerializationInfo& si, Object& object)
> {
>   si.getMember("stringValue") >>= object._stringValue;
>   si.getMember("intValue") >>= object._intValue;
> }
>
> int main(int argc, char* argv[])
> {
>   try
>   {
>     std::vector<Object> objects;
>
>     objects.push_back(Object("Hello", 42));
>     objects.push_back(Object("World", -17));
>
>     std::ofstream outfile("file.bin");
>
>     outfile << cxxtools::bin::Bin(objects);
>     outfile.close();
>
>     objects.clear();
>
>     std::ifstream infile("file.bin");
>     cxxtools::bin::Deserializer deserializer(infile);
>     deserializer.deserialize(objects);
>    
>     std::cout << objects[0].stringValue() << objects[1].stringValue() <<
> std::endl;
>    
>   }
>   catch (const std::exception& e)
>   {
>     std::cerr << e.what() << std::endl;
>   }
> }
>
>
>
> ========================================
>
> changed program:
>
> #include <iostream>
> #include <fstream>
> #include <cxxtools/bin/bin.h>
>
> class Object
> {
>     friend void operator>>= (const cxxtools::SerializationInfo& si,
> Object& object);
>
>     std::string _stringValue;
>     int _intValue;
>
>   public:
>     Object()
>       : _intValue(0)
>       { }
>
>     Object(const std::string& stringValue, int intValue)
>       : _stringValue(stringValue),
>         _intValue(intValue)
>       { }
>
>     const std::string& stringValue() const
>     { return _stringValue; }
>
>     int intValue() const
>     { return _intValue; }
> };
>
> void operator<<= (cxxtools::SerializationInfo& si, const Object& object)
> {
>   si.setTypeName("Object");
>   si.addMember("stringValue") <<= object.stringValue();
>   si.addMember("intValue") <<= object.intValue();
>   si.setCategory(cxxtools::SerializationInfo::Array);
> }
>
> void operator>>= (const cxxtools::SerializationInfo& si, Object& object)
> {
>   si.getMember(0) >>= object._stringValue;
>   si.getMember(1) >>= object._intValue;
> }
>
> int main(int argc, char* argv[])
> {
>   try
>   {
>     std::vector<Object> objects;
>
>     objects.push_back(Object("Hello", 42));
>     objects.push_back(Object("World", -17));
>
>     std::ofstream outfile("file.bin");
>
>     outfile << cxxtools::bin::Bin(objects);
>     outfile.close();
>
>     objects.clear();
>
>     std::ifstream infile("file.bin");
>     cxxtools::bin::Deserializer deserializer(infile);
>     deserializer.deserialize(objects);
>    
>     std::cout << objects[0].stringValue() << objects[1].stringValue() <<
> std::endl;
>    
>   }
>   catch (const std::exception& e)
>   {
>     std::cerr << e.what() << std::endl;
>   }
> }
>


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general

Reply via email to