Fix some docs
This commit is contained in:
@@ -24,7 +24,7 @@ pip install -U setuptools
|
|||||||
|
|
||||||
## Building and installation
|
## Building and installation
|
||||||
|
|
||||||
Install with `pip install pycapnp`. You can set the CC environment variable to control the compiler version, ie `CC=gcc-4.8 pip install pycapnp`.
|
Install with `pip install pycapnp`. You can set the CC environment variable to control which compiler is used, ie `CC=gcc-4.8 pip install pycapnp`.
|
||||||
|
|
||||||
Or you can clone the repo like so:
|
Or you can clone the repo like so:
|
||||||
|
|
||||||
@@ -116,5 +116,5 @@ If you get an error on installation like:
|
|||||||
|
|
||||||
Then you have too old a version of setuptools. Run `pip install -U setuptools` then try again.
|
Then you have too old a version of setuptools. Run `pip install -U setuptools` then try again.
|
||||||
|
|
||||||
[](https://travis-ci.org/jparyani/pycapnp)
|
[](https://travis-ci.org/jparyani/pycapnp)
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ On some systems you will have to install Python's headers before doing any of th
|
|||||||
|
|
||||||
sudo apt-get install python-dev
|
sudo apt-get install python-dev
|
||||||
|
|
||||||
You can control the compiler version with the environment variable CC, ie. `CC=gcc-4.8 pip install pycapnp`. You only need to run the setuptools line if you have a setuptools older than v0.8.0, and the cython line if you have a version older than v0.19.1.
|
You can control what compiler is used with the environment variable CC, ie. `CC=gcc-4.8 pip install pycapnp`. You only need to run the setuptools line if you have a setuptools older than v0.8.0, and the cython line if you have a version older than v0.19.1.
|
||||||
|
|
||||||
From Source
|
From Source
|
||||||
---------------------
|
---------------------
|
||||||
|
|||||||
@@ -199,24 +199,47 @@ The only tricky one is unions, where you need to call `.which()` to determine th
|
|||||||
print('self employed')
|
print('self employed')
|
||||||
print()
|
print()
|
||||||
|
|
||||||
Dictionaries
|
Serializing/Deserializing
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
Converting to a dictionary
|
Files
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
As shown in the examples above, there is file serialization with `write()`::
|
||||||
|
|
||||||
|
addresses = addressbook.AddressBook.new_message()
|
||||||
|
...
|
||||||
|
f = open('example.bin', 'w')
|
||||||
|
addresses.write(f)
|
||||||
|
|
||||||
|
And similarly for reading::
|
||||||
|
|
||||||
|
f = open('example.bin')
|
||||||
|
addresses = addressbook.AddressBook.read(f)
|
||||||
|
|
||||||
|
Dictionaries
|
||||||
|
~~~~~~~~~~~~~~
|
||||||
|
|
||||||
There is a convenience method for converting Cap'n Proto messages to a dictionary. This works for both Builder and Reader type messages::
|
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()
|
alice.to_dict()
|
||||||
|
|
||||||
Reading froma dictionary
|
There is also a convenience method for reading for reading a dict in and building a Builder message out of it. This the inverse of the above::
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
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'}
|
my_dict = {'name' : 'alice'}
|
||||||
alice = addressbook.Person.from_dict(my_dict)
|
alice = addressbook.Person.from_dict(my_dict)
|
||||||
|
|
||||||
|
Byte Strings/Buffers
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
There is serialization to a byte string available::
|
||||||
|
|
||||||
|
encoded_message = alice.to_bytes()
|
||||||
|
|
||||||
|
And a corresponding from_bytes function::
|
||||||
|
|
||||||
|
alice addressbook.Person.from_bytes(encoded_message)
|
||||||
|
|
||||||
Full Example
|
Full Example
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user