Skip to content

Commit c123a4a

Browse files
committed
add Python examples and install README
1 parent dc8c822 commit c123a4a

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ git subtree merge --prefix=src/machinetalk/proto machinetalk-protobuf/master --s
1919

2020
Now create a PR against the machinekit repo.
2121

22+
## Python
23+
24+
### Installation
25+
26+
To use the Machinetalk protobuf Python modules in your projects, use:
27+
28+
```sh
29+
cd python
30+
python setup.py build
31+
sudo python setup.py
32+
```
33+
34+
### Usage
35+
See [examples](python/examples).
36+
2237
## JavaScript (NPM/NodeJS)
2338

2439
### Installation
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from machinetalk.protobuf.message_pb2 import Container
2+
from machinetalk.protobuf.types_pb2 import *
3+
4+
encodedBuffer = ''.join(chr(x) for x in [0x08, 0xd2, 0x01])
5+
6+
# create the message container, reuse is more efficient
7+
rx = Container()
8+
9+
# parse the encoded message
10+
rx.ParseFromString(encodedBuffer)
11+
12+
# print the decoded message
13+
print(rx)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from machinetalk.protobuf.message_pb2 import Container
2+
from machinetalk.protobuf.types_pb2 import *
3+
4+
# create the message container, reuse is more efficient
5+
tx = Container()
6+
7+
# define the message
8+
tx.Clear()
9+
tx.type = MT_PING
10+
11+
# encode the message
12+
encodedBuffer = tx.SerializeToString()
13+
14+
# print the buffer
15+
print(encodedBuffer)

0 commit comments

Comments
 (0)