Permalink
Browse files

JsonSerializer returns QByteArray

JSON supports UTF-16, however the serializer is 8-bit clean.  Instead of
returning a QString only to turn it back into a QByteArray, return a
QByteArray on serialization.
  • Loading branch information...
1 parent 9596c5d commit e18380378457c987d222c66a4389c4cee50db397 @mhoran mhoran committed Dec 30, 2012
Showing with 13 additions and 8 deletions.
  1. +4 −0 src/Command.cpp
  2. +1 −0 src/Command.h
  3. +1 −1 src/ConsoleMessages.cpp
  4. +1 −1 src/GetWindowHandles.cpp
  5. +3 −3 src/JsonSerializer.cpp
  6. +3 −3 src/JsonSerializer.h
View
@@ -15,3 +15,7 @@ void Command::emitFinished(bool success, QString message) {
emit finished(new Response(success, message, this));
}
+void Command::emitFinished(bool success, QByteArray message) {
+ emit finished(new Response(success, message, this));
+}
+
View
@@ -16,6 +16,7 @@ class Command : public QObject {
protected:
void emitFinished(bool success);
void emitFinished(bool success, QString message);
+ void emitFinished(bool success, QByteArray message);
signals:
void finished(Response *response);
View
@@ -8,7 +8,7 @@ ConsoleMessages::ConsoleMessages(WebPageManager *manager, QStringList &arguments
void ConsoleMessages::start() {
JsonSerializer serializer;
- QString json = serializer.serialize(page()->consoleMessages());
+ QByteArray json = serializer.serialize(page()->consoleMessages());
emitFinished(true, json);
}
View
@@ -15,7 +15,7 @@ void GetWindowHandles::start() {
handles << page->uuid();
JsonSerializer serializer;
- QString json = serializer.serialize(handles);
+ QByteArray json = serializer.serialize(handles);
emitFinished(true, json);
}
View
@@ -3,7 +3,7 @@
JsonSerializer::JsonSerializer(QObject *parent) : QObject(parent) {
}
-QString JsonSerializer::serialize(const QVariant &object) {
+QByteArray JsonSerializer::serialize(const QVariant &object) {
addVariant(object);
return m_buffer;
}
@@ -82,7 +82,7 @@ void JsonSerializer::addMap(const QVariantMap &map) {
m_buffer.append("}");
}
-QString JsonSerializer::sanitizeString(QString str) {
+QByteArray JsonSerializer::sanitizeString(QString str) {
str.replace("\\", "\\\\");
str.replace("\"", "\\\"");
str.replace("\b", "\\b");
@@ -91,7 +91,7 @@ QString JsonSerializer::sanitizeString(QString str) {
str.replace("\r", "\\r");
str.replace("\t", "\\t");
- QString result;
+ QByteArray result;
const ushort* unicode = str.utf16();
unsigned int i = 0;
View
@@ -6,15 +6,15 @@ class JsonSerializer : public QObject {
public:
JsonSerializer(QObject *parent = 0);
- QString serialize(const QVariant &object);
+ QByteArray serialize(const QVariant &object);
private:
void addVariant(const QVariant &object);
void addString(const QString &string);
void addArray(const QVariantList &list);
void addMap(const QVariantMap &map);
- QString sanitizeString(QString string);
+ QByteArray sanitizeString(QString string);
- QString m_buffer;
+ QByteArray m_buffer;
};

0 comments on commit e183803

Please sign in to comment.