Hi,

the cxxtools::SerializationInfo is meant to be a generic data structure, which do not depend on the format. Using the serialization operator you can convert C++ objects into a cxxtools::SerializationInfo. Json is just one format you can create from that.

Putting a raw type make the SerializationInfo depend on the format. You are not able to create xml from that any more. It would really break the idea of the serialization framework.

I would prefer not to support hat.

Note that you can convert you existing json parts into a SerializationInfo using the json deserializer. Then you can use that to build the complete structure and serialize it into json again. It is not really the fastest was but I guess it is a strange requirement also.


Tommi


Am 26.03.2014 14:01, schrieb Marek Lindner:
Hi,

On Monday 24 March 2014 18:24:16 Marek Lindner wrote:
I am in the process of extending the json serializer to accept arguments
which are json already and don't require further processing (my data
contains mixed elements - partly raw data requiring conversion as well as
json i'd like to output). As it so happens I have developed a patch which
does not work as expected (see below). Any idea what I am missing ?
I found the problem! Below you will find a revised version of my original
patch. Please let me know if you consider the patch for inclusion. I'd be
happy to help to make that happen.

Thanks,
Marek

--- a/include/cxxtools/bin/formatter.h  2013-12-26 09:33:48.000000000 +0000
+++ b/include/cxxtools/bin/formatter.h  2014-03-25 19:50:32.145288454 +0000
@@ -67,6 +67,8 @@
virtual void addNull(const std::string& name, const std::string& type); + virtual void addRaw(const cxxtools::String& value);
+
                  virtual void beginArray(const std::string& name, const 
std::string& type);
virtual void finishArray();
--- a/include/cxxtools/formatter.h      2013-12-26 09:33:48.000000000 +0000
+++ b/include/cxxtools/formatter.h      2014-03-25 19:50:32.145288454 +0000
@@ -73,6 +73,8 @@
virtual void addNull(const std::string& name, const std::string& type); + virtual void addRaw(const cxxtools::String& value);
+
          virtual void beginArray(const std::string& name, const std::string& 
type) = 0;
virtual void finishArray() = 0;
--- a/include/cxxtools/jsonformatter.h  2013-12-26 09:33:48.000000000 +0000
+++ b/include/cxxtools/jsonformatter.h  2014-03-25 19:50:32.145288454 +0000
@@ -78,6 +78,8 @@
virtual void addNull(const std::string& name, const std::string& type); + virtual void addRaw(const cxxtools::String& value);
+
              virtual void beginArray(const std::string& name, const 
std::string& type);
virtual void finishArray();
--- a/include/cxxtools/serializationinfo.h      2014-01-17 19:05:09.000000000 
+0000
+++ b/include/cxxtools/serializationinfo.h      2014-03-26 12:45:20.159185071 
+0000
@@ -53,7 +53,7 @@
public:
          enum Category {
-            Void = 0, Value = 1, Object = 2, Array = 6
+            Void = 0, Value = 1, Object = 2, Array = 6, Raw = 20
          };
class Iterator;
@@ -262,6 +262,7 @@
          void swap(SerializationInfo& si);
bool isNull() const { return _t == t_none && _category == Void; }
+        bool isRaw() const      { return _category == Raw; }
          bool isString() const   { return _t == t_string; }
          bool isString8() const  { return _t == t_string8; }
          bool isChar() const     { return _t == t_char; }
--- a/src/bin/formatter.cpp     2013-12-26 09:33:48.000000000 +0000
+++ b/src/bin/formatter.cpp     2014-03-25 19:50:32.149288438 +0000
@@ -581,6 +581,11 @@
      *_out << '\xff';
  }
+void Formatter::addRaw(const cxxtools::String& value)
+{
+    *_out << value;
+}
+
  void Formatter::beginArray(const std::string& name, const std::string& type)
  {
      log_trace("beginArray(\"" << name << "\", \"" << type << ')');
--- a/src/decomposer.cpp        2013-12-26 09:33:48.000000000 +0000
+++ b/src/decomposer.cpp        2014-03-25 19:50:32.149288438 +0000
@@ -37,6 +37,12 @@
      {
          formatter.addNull( si.name(), si.typeName() );
      }
+    else if (si.category() == SerializationInfo::Raw)
+    {
+        String value;
+        si.getValue(value);
+        formatter.addRaw( value );
+    }
      else if (si.category() == SerializationInfo::Value)
      {
          if (si.isInt())
--- a/src/formatter.cpp 2013-12-26 09:33:48.000000000 +0000
+++ b/src/formatter.cpp 2014-03-25 19:50:32.149288438 +0000
@@ -66,5 +66,10 @@
      addValueString(name, type, String());
  }
+void Formatter::addRaw(const cxxtools::String& value)
+{
+   addRaw(value);
+}
+
  }
--- a/src/jsonformatter.cpp 2014-01-17 19:05:09.000000000 +0000
+++ b/src/jsonformatter.cpp     2014-03-26 09:51:21.354709871 +0000
@@ -199,6 +199,18 @@
      finishValue();
  }
+void JsonFormatter::addRaw(const cxxtools::String& value)
+{
+    const std::string name;
+
+    beginValue(name);
+
+    for (cxxtools::String::const_iterator it = value.begin(); it != 
value.end(); ++it)
+       *_ts << *it;
+
+    finishValue();
+}
+
  void JsonFormatter::beginArray(const std::string& name, const std::string& 
type)
  {
      checkTs(_ts);


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech


_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general

------------------------------------------------------------------------------
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general

Reply via email to