Add dictionary methods to docs

This commit is contained in:
Jason Paryani
2013-09-03 01:24:16 -07:00
parent 38cef54ddc
commit eec8cbe05c

View File

@@ -199,6 +199,24 @@ The only tricky one is unions, where you need to call `.which()` to determine th
print('self employed') print('self employed')
print() print()
Dictionaries
--------------
Converting to a dictionary
~~~~~~~~~~~~~~~~~~~~~~~~~~
There is a convenience method for converting Cap'n Proto messages to a dictionary. This works for both Builder and Reader type messages::
alice.to_dict()
Reading froma dictionary
~~~~~~~~~~~~~~~~~~~~~~~~~~
There is a convenience method for reading for reading a dict in and building a Builder message out of it. This the inverse of `Converting to a dictionary`_::
my_dict = {'name' : 'alice'}
alice = addressbook.Person.from_dict(my_dict)
Full Example Full Example
------------------ ------------------