Update README.md
This commit is contained in:
21
README.md
21
README.md
@@ -25,13 +25,11 @@ You also need a working version of the latest [Cython](http://cython.org/) insta
|
|||||||
At the moment, there is no documenation, but the library is almost a 1:1 clone of the [Capnproto C++ Library](http://kentonv.github.io/capnproto/cxx.html)
|
At the moment, there is no documenation, but the library is almost a 1:1 clone of the [Capnproto C++ Library](http://kentonv.github.io/capnproto/cxx.html)
|
||||||
|
|
||||||
The examples has one example that shows off the capabilities quite nicely. Here it is, reproduced:
|
The examples has one example that shows off the capabilities quite nicely. Here it is, reproduced:
|
||||||
|
```python
|
||||||
|
import capnp
|
||||||
|
addressbook = capnp.load('addressbook.capnp')
|
||||||
|
|
||||||
import os
|
def writeAddressBook(fd):
|
||||||
import capnp
|
|
||||||
this_dir = os.path.dirname(__file__)
|
|
||||||
addressbook = capnp.load(os.path.join(this_dir, 'addressbook.capnp'))
|
|
||||||
|
|
||||||
def writeAddressBook(fd):
|
|
||||||
message = capnp.MallocMessageBuilder()
|
message = capnp.MallocMessageBuilder()
|
||||||
addressBook = message.initRoot(addressbook.AddressBook)
|
addressBook = message.initRoot(addressbook.AddressBook)
|
||||||
people = addressBook.initPeople(2)
|
people = addressBook.initPeople(2)
|
||||||
@@ -58,10 +56,10 @@ The examples has one example that shows off the capabilities quite nicely. Here
|
|||||||
|
|
||||||
capnp.writePackedMessageToFd(fd, message)
|
capnp.writePackedMessageToFd(fd, message)
|
||||||
|
|
||||||
f = open('example', 'w')
|
f = open('example', 'w')
|
||||||
writeAddressBook(f.fileno())
|
writeAddressBook(f.fileno())
|
||||||
|
|
||||||
def printAddressBook(fd):
|
def printAddressBook(fd):
|
||||||
message = capnp.PackedFdMessageReader(f.fileno())
|
message = capnp.PackedFdMessageReader(f.fileno())
|
||||||
addressBook = message.getRoot(addressbook.AddressBook)
|
addressBook = message.getRoot(addressbook.AddressBook)
|
||||||
|
|
||||||
@@ -83,5 +81,6 @@ The examples has one example that shows off the capabilities quite nicely. Here
|
|||||||
print 'unemployed'
|
print 'unemployed'
|
||||||
print
|
print
|
||||||
|
|
||||||
f = open('example', 'r')
|
f = open('example', 'r')
|
||||||
printAddressBook(f.fileno())
|
printAddressBook(f.fileno())
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user