Fixed up the docs a bit with sugesstions from Kenton

This commit is contained in:
Jason Paryani
2013-08-20 00:58:34 -07:00
parent 4373ecc50b
commit 934a204ea5
3 changed files with 12 additions and 12 deletions

View File

@@ -3,11 +3,11 @@
Welcome to capnp's documentation! Welcome to capnp's documentation!
================================= =================================
This is a python wrapping of the C++ implementation of the `Capnproto <http://kentonv.github.io/capnproto/>`_ library. Here is a description, quoted from its docs: This is a python wrapping of the C++ implementation of the `Cap'n Proto <http://kentonv.github.io/capnproto/>`_ library. Here is a short description, quoted from its docs:
Capn Proto is an insanely fast data interchange format and capability-based RPC system. Think JSON, except binary. Or think Protocol Buffers, except faster. In fact, in benchmarks, Capn Proto is INFINITY TIMES faster than Protocol Buffers. Capn Proto is an insanely fast data interchange format and capability-based RPC system. Think JSON, except binary. Or think Protocol Buffers, except faster. In fact, in benchmarks, Capn Proto is INFINITY TIMES faster than Protocol Buffers.
The INFINITY TIMES faster part isn't so true for python, but in some simplistic benchmarks (available in the `benchmark directory of the repo <https://github.com/jparyani/capnpc-python-cpp/tree/master/benchmark>`_), capnp is 4x faster than the pure python Protocol Buffer library, and 2x faster than the C++ implementation. The INFINITY TIMES faster part isn't so true for python, but in some simplistic benchmarks (available in the `benchmark directory of the repo <https://github.com/jparyani/capnpc-python-cpp/tree/master/benchmark>`_), capnp has proven to be decently faster than Protocol Buffers. Also, the python capnp library can load Cap'n Proto schema files directly, without the need for a seperate compile step like with Protocol Buffers or Thrift.
Contents: Contents:

View File

@@ -3,10 +3,10 @@
Installation Installation
=================== ===================
C++ Capnproto Library C++ Cap'n Proto Library
--------------------- ---------------------
You need to install the C++ Capnproto library first. It requires a C++ compiler with C++11 support, such as GCC 4.7+ or Clang 3.2+. Follow installation docs at `http://kentonv.github.io/capnproto/install.html <http://kentonv.github.io/capnproto/install.html>`_ with an added `sudo ldconfig` after you're done installing, or if you're feeling lazy, you can run the commands below:: You need to install the C++ Cap'n Proto library first. It requires a C++ compiler with C++11 support, such as GCC 4.7+ or Clang 3.2+. Follow installation docs at `http://kentonv.github.io/capnproto/install.html <http://kentonv.github.io/capnproto/install.html>`_ with an added `sudo ldconfig` after you're done installing, or if you're feeling lazy, you can run the commands below::
wget https://github.com/kentonv/capnproto/archive/master.zip wget https://github.com/kentonv/capnproto/archive/master.zip
unzip master.zip unzip master.zip

View File

@@ -5,20 +5,20 @@ Quickstart
This assumes you already have the capnp library installed. If you don't, please follow the instructions at :ref:`Installation <install>` first. This assumes you already have the capnp library installed. If you don't, please follow the instructions at :ref:`Installation <install>` first.
In general, this library is a very light wrapping of the `Capnproto C++ library <http://kentonv.github.io/capnproto/cxx.html>`_. You can refer to its docs for more advanced concepts, or just to get a basic idea of how the python library is structured. In general, this library is a very light wrapping of the `Cap'n Proto C++ library <http://kentonv.github.io/capnproto/cxx.html>`_. You can refer to its docs for more advanced concepts, or just to get a basic idea of how the python library is structured.
Load a Capnproto Schema Load a Cap'n Proto Schema
------------------------ ------------------------
First you need to import the library:: First you need to import the library::
import capnp import capnp
Then you can load the Capnproto schema with:: Then you can load the Cap'n Proto schema with::
capnp.load('addressbook.capnp') capnp.load('addressbook.capnp')
For future reference, here is the capnproto schema. Also available in the github repository under examples/addressbook.capnp:: For future reference, here is the Cap'n Proto schema. Also available in the github repository under examples/addressbook.capnp::
# addressbook.capnp # addressbook.capnp
0x934efea7f017fff0; 0x934efea7f017fff0;
@@ -63,14 +63,14 @@ First you need to allocate a MessageBuilder for your message to go in. There is
message = capnp.MallocMessageBuilder() message = capnp.MallocMessageBuilder()
Initialize a New Capnproto Object Initialize a New Cap'n Proto Object
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Now that you have a message buffer, you need to allocate an actual object that is from your schema. In this case, we will allocate an `AddressBook`:: Now that you have a message buffer, you need to allocate an actual object that is from your schema. In this case, we will allocate an `AddressBook`::
addressBook = message.initRoot(addressbook.AddressBook) addressBook = message.initRoot(addressbook.AddressBook)
Notice that we used `addressbook` from the previous section: `Load a Capnproto Schema`_. Notice that we used `addressbook` from the previous section: `Load a Cap'n Proto Schema`_.
List List
~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -86,7 +86,7 @@ For now, let's grab the first element out of this list and assign it to a variab
Primitive Types Primitive Types
~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
For all primitive types, from the Capnproto docs: For all primitive types, from the Cap'n Proto docs:
- Boolean: Bool - Boolean: Bool
- Integers: Int8, Int16, Int32, Int64 - Integers: Int8, Int16, Int32, Int64
@@ -154,7 +154,7 @@ Much like before, you will have to de-serialize the message from a file descript
f = open('example.bin') f = open('example.bin')
message = capnp.PackedFdMessageReader(f.fileno()) message = capnp.PackedFdMessageReader(f.fileno())
Initialize a New Capnproto Object Initialize a New Cap'n Proto Object
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Just like when building, you have to actually specify which message you want to read out of buffer:: Just like when building, you have to actually specify which message you want to read out of buffer::