prophy:快速序列化协议

proph的Python项目详细描述


Pypi Package VersionSupported Python VersionsDocumentation StatusCoverage StatusTravis-CI Build Status

prophy是一个静态类型的、二进制的、无标记的、未打包的序列化协议。

您可以定义消息架构:

struct MyMsg
{
    u16 x<>;
};

为所选语言生成编解码器:

prophyc --python_out . --cpp_full_out . --cpp_out . test.prophy

并在python中序列化数据:

>>> import test
>>> msg = test.MyMsg()
>>> msg.x[:] = [1, 2, 3]
>>> msg.encode('<')
'\x03\x00\x00\x00\x01\x00\x02\x00\x03\x00\x00\x00'
>>> print msg
x: 1
x: 2
x: 3
C++中的P>:

#include <iostream>
#include <iterator>
#include "test.ppf.hpp"

int main()
{
    prophy::generated::MyMsg msg{{1, 2, 3}};
    std::vector<uint8_t> data = msg.encode();
    std::copy(data.begin(), data.end(), std::ostream_iterator<unsigned>(std::cout, " "));
    std::cout << '\n' << msg.print();
    return 0;
}
3 0 0 0 1 0 2 0 3 0 0 0
x: 1
x: 2
x: 3

再次在C++中(半手翻滚,依赖于编译器,但最快的选项):

#include <iostream>
#include <iterator>
#include <cstdlib>
#include "test.pp.hpp"

int main()
{
    MyMsg* msg = static_cast<MyMsg*>(std::malloc(12));
    msg->num_of_x = 3;
    msg->x[0] = 1;
    msg->x[1] = 2;
    msg->x[2] = 3;
    std::copy((uint8_t*)msg, ((uint8_t*)msg) + 12, std::ostream_iterator<unsigned>(std::cout, " "));
    std::cout << '\n';
    return 0;
}
3 0 0 0 1 0 2 0 3 0 0 0

文档:http://prophy.readthedocs.org

问题:https://github.com/aurzenligl/prophy/issues

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
swing Java按钮/网格布局   java列出Google日历中的所有事件   java无效:单击API publisher test按钮后连接到后端时出错   带有内部赋值的java While循环导致checkstyle错误   java为什么trimToSize/ensureCapacity方法提供“公共”级访问?   文件输出流的java问题   ListIterator和并发修改异常的java问题   java如何使用两个URL映射   无法识别使用“./../”构造的字符串java相对路径,为什么?   首次写入remotelyclosedsocket不会触发异常,对吗?JAVA   java OneDrive REST API为文件上载提供了400个无效谓词   Java泛型、集合接口和对象类的问题   OpenSSL Java安全提供程序   jmeter java运行jmx禁用操作