Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Unified Diff: native_client_sdk/src/doc/devguide/coding/message-system.rst

Issue 23688008: [NaCl Docs] Add some messaging system docs for how to use pp::VarDictionaries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: native_client_sdk/src/doc/devguide/coding/message-system.rst
diff --git a/native_client_sdk/src/doc/devguide/coding/message-system.rst b/native_client_sdk/src/doc/devguide/coding/message-system.rst
index f77b9bd4d704864b2bc5ecbf45f2a7dff5dacecd..8a96c8f3a047b817cfb30171cb0746ada129ce32 100644
--- a/native_client_sdk/src/doc/devguide/coding/message-system.rst
+++ b/native_client_sdk/src/doc/devguide/coding/message-system.rst
@@ -358,3 +358,45 @@ end of the Native Client module's ``HandleMessage()`` function:
.. naclcode::
PostMessage(var_reply);
+
+
+Sending and receiving other ``pp::Var`` types
+---------------------------------------------
+
+Besides strings, ``pp::Var`` can represent other types of JavaScript
+objects. For example, messages can be JavaScript dictionaries.
binji 2013/09/24 21:56:26 JavaScript doesn't really have dictionaries, just
jvoung (off chromium) 2013/09/24 22:35:53 Done.
+These richer types can make it easier to implement an application's
+messaging protocol.
+
+To send a dictionary from the NaCl module to JavaScript simply
+create a ``pp::VarDictionary`` and then call ``PostMessage`` with
+the dictionary.
+
+.. naclcode::
+
+ pp::VarDictionary dictionary;
+ dictionary.Set(pp::Var("command"), pp::Var(next_command));
+ dictionary.Set(pp::Var("param_int"), pp::Var(123));
+ pp::VarArray an_array;
+ an_array.Set(0, pp::Var("string0"));
+ an_array.Set(1, pp::Var("string1"))
+ dictionary.Set(pp::Var("param_array"), an_array);
+ PostMessage(dictionary);
binji 2013/09/24 21:56:26 Is it worth mentioning what this will look like in
jvoung (off chromium) 2013/09/24 22:35:53 Seems worth doing -- Done.
+
+
+To receive a dictionary-typed message in the NaCl module, test that
+the message is truly a dictionary type, then convert the message
+with the ``pp::VarDictionary`` class.
+
+.. naclcode::
+
+ virtual void HandleMessage(const pp::Var& var) {
+ if (var.is_dictionary()) {
+ pp::VarDictionary dictionary(var);
+ // Use the dictionary
+ pp::VarArray keys = dictionary.GetKeys();
+ // ...
+ } else {
+ // ...
+ }
+ }
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698