Thank you very much Tommi. This works perfectly.

The binay dictionary is genious and very convenient when using standard
containers.



On 04/03/15 18:49, Tommi Mäkitalo wrote:
> Hi,
>
> this was indeed a bug in the parser. I just checked in a fix. It failed 
> to parse arrays which have names.
>
> Btw. you optimization is not necessary. Some times ago I implemented a 
> dictionary in binary format. When serializing stuff into binary format 
> it writes those strings just once. The second time it needs that string 
> it writes just a references to the first occurrence.
>
> Tommi
>
> Am 03.03.2015 um 12:20 schrieb Michael Gius:
>> 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
>
> ------------------------------------------------------------------------------
> 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


------------------------------------------------------------------------------
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