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);
signature.asc
Description: This is a digitally signed message part.
------------------------------------------------------------------------------ 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
