machinetalk的python模块protobuf
machinetalk-protobuf的Python项目详细描述
MachineTalk协议
machinekit消息的protobuf声明
此repo作为git子树集成到github.com/machinekit/machinekit中。
更改/添加到消息定义:
- 根据此回购协议发送PR
- 在machinekit repo中添加一个新遥控器,请参阅此处
- 像这样更新machinekit repo中的子树
git remote add machinetalk-protobuf git://github.com/machinekit/machinetalk-protobuf.git
git fetch machinetalk-protobuf
git subtree merge --prefix=src/machinetalk/proto machinetalk-protobuf/master --squash
现在针对machinekit repo创建一个pr。
Python
通过PYPI安装
要在项目中使用machinetalk protobuf python模块,请使用:
pip install machinetalk-protobuf
从源安装
或者,可以直接从源代码安装python模块。
make python setup.py build sudo python setup.py install
使用量
见examples。
javascript(npm/nodejs)
安装
要在基于npm的项目中使用machinetalk protobuf定义,请使用:
npm install --save machinetalk-protobuf
使用量
见examples。如果要尝试这些示例,请确保首先在此存储库中运行npm install
。
编码
varmachinetalkProtobuf=require('machinetalk-protobuf');varmessageContainer={type:machinetalkProtobuf.message.ContainerType.MT_PING};varencodedMessageContainer=machinetalkProtobuf.message.Container.encode(messageContainer);
这将导致以0x08 0xd2 0x01
开头的缓冲区。
解码
varmachinetalkProtobuf=require('machinetalk-protobuf');varencodedBuffer=newBuffer([0x08,0xd2,0x01]);vardecodedMessageContainer=machinetalkProtobuf.message.Container.decode(encodedBuffer);
这会产生一个类似于Encoding中定义的消息容器。
javascript(浏览器)
cdn使用
<scriptsrc="//cdn.rawgit.com/machinekit/machinetalk-protobuf/VERSION/dist/machinetalk-protobuf.js"></script>
用VERSION
替换为a valid tag或仅用master
进行测试
最新的主版本。
编码
varmessageContainer={type:machinetalk.protobuf.message.ContainerType.MT_PING};varencodedMessageContainer=machinetalk.protobuf.message.Container.encode(messageContainer);
这将导致以0x08 0xd2 0x01
开头的缓冲区。
解码
varencodedBuffer=newArrayBuffer([0x08,0xd2,0x01]);vardecodedMessageContainer=machinetalk.protobuf.message.Container.decode(encodedBuffer);
这会产生一个类似于Encoding中定义的消息容器。