diff options
author | José Fonseca <jfonseca@vmware.com> | 2014-09-25 15:19:09 +0100 |
---|---|---|
committer | José Fonseca <jfonseca@vmware.com> | 2014-09-26 21:00:33 +0100 |
commit | d5cda7c23f274c5be0ff0e47f711fd2be53de268 (patch) | |
tree | 98edb363e246b7f3ca675bc5730b26eb1a0ef52b /cli | |
parent | 20a1521efdac44c8219f00c2414de031891fb464 (diff) |
trace: Serialize wide-strings properly.
Wide strings are only used by DirectX APIs, mostly for descriptions, but
it's still useful to be able to read them.
I'm split on whether to bump the trace format version or not.
OpenGL traces are unaffected.
Diffstat (limited to 'cli')
-rw-r--r-- | cli/cli_pickle.cpp | 4 | ||||
-rw-r--r-- | cli/cli_sed.cpp | 3 | ||||
-rw-r--r-- | cli/pickle.hpp | 28 |
3 files changed, 35 insertions, 0 deletions
diff --git a/cli/cli_pickle.cpp b/cli/cli_pickle.cpp index e7f51ff9..286716be 100644 --- a/cli/cli_pickle.cpp +++ b/cli/cli_pickle.cpp @@ -83,6 +83,10 @@ public: writer.writeString(node->value); } + void visit(WString *node) { + writer.writeWString(node->value); + } + void visit(Enum *node) { if (symbolic) { const EnumValue *it = node->lookup(); diff --git a/cli/cli_sed.cpp b/cli/cli_sed.cpp index afec1257..ccb38b0a 100644 --- a/cli/cli_sed.cpp +++ b/cli/cli_sed.cpp @@ -106,6 +106,9 @@ public: void visit(String *node) { } + void visit(WString *node) { + } + void visit(Enum *node) { const EnumValue *it = node->lookup(); if (it) { diff --git a/cli/pickle.hpp b/cli/pickle.hpp index 35973ef5..753cd6f1 100644 --- a/cli/pickle.hpp +++ b/cli/pickle.hpp @@ -211,6 +211,34 @@ public: writeString(s.c_str(), s.size()); } + inline void writeWString(const wchar_t *s, size_t length) { + if (!s) { + writeNone(); + return; + } + + /* FIXME: emit UTF-8 */ + os.put(BINUNICODE); + putInt32(length); + for (size_t i = 0; i < length; ++i) { + wchar_t wc = s[i]; + char c = wc >= 0 && wc < 0x80 ? (char)wc : '?'; + os.put(c); + } + + os.put(BINPUT); + os.put(1); + } + + inline void writeWString(const wchar_t *s) { + if (!s) { + writeNone(); + return; + } + + writeWString(s, wcslen(s)); + } + inline void writeNone(void) { os.put(NONE); } |