From e80e002a6cc1a270e2a05d571896e8010994807d Mon Sep 17 00:00:00 2001 From: Jason Paryani Date: Tue, 3 Sep 2013 22:10:37 -0700 Subject: [PATCH] Fix some docs --- README.md | 4 ++-- docs/install.rst | 2 +- docs/quickstart.rst | 35 +++++++++++++++++++++++++++++------ 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 56c0cfe..0dc8f4f 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ pip install -U setuptools ## 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: @@ -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. -[![Build Status](https://travis-ci.org/jparyani/pycapnp.png?branch=master)](https://travis-ci.org/jparyani/pycapnp) +[![Build Status](https://travis-ci.org/jparyani/pycapnp.png?branch=develop)](https://travis-ci.org/jparyani/pycapnp) diff --git a/docs/install.rst b/docs/install.rst index b3ed7f9..d48aa01 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -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 -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 --------------------- diff --git a/docs/quickstart.rst b/docs/quickstart.rst index af5900e..e424382 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -199,24 +199,47 @@ The only tricky one is unions, where you need to call `.which()` to determine th print('self employed') 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:: 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`_:: +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:: my_dict = {'name' : 'alice'} 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 ------------------