广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Protocol Buffer的使用(p
  • 683
分享到

Protocol Buffer的使用(p

ProtocolBuffer 2023-01-31 05:01:22 683人浏览 泡泡鱼

Python 官方文档:入门教程 => 点击学习

摘要

1.需要安装Protocol Buffer 直接:apt-get install protobuf-compiler 安装完毕后,进入解压目录的python目录,执行Python setup.py install;安装python的pro

1.需要安装Protocol Buffer

直接:apt-get install protobuf-compiler

安装完毕后,进入解压目录的python目录,执行Python setup.py install;安装python的protobuf库即可。


2.可以查询到它的大致用法

pijing@ubuntu:~/protobuffer$ protoc -h
Usage: protoc [OPTioN] PROTO_FILES
Parse PROTO_FILES and generate output based on the options given:
  -IPATH, --proto_path=PATH   Specify the directory in which to search for
                              imports.  May be specified multiple times;
                              directories will be searched in order.  If not
                              given, the current working directory is used.
  --version                   Show version info and exit.
  -h, --help                  Show this text and exit.
  --encode=MESSAGE_TYPE       Read a text-fORMat message of the given type
                              from standard input and write it in binary
                              to standard output.  The message type must
                              be defined in PROTO_FILES or their imports.
  --decode=MESSAGE_TYPE       Read a binary message of the given type from
                              standard input and write it in text format
                              to standard output.  The message type must
                              be defined in PROTO_FILES or their imports.
  --decode_raw                Read an arbitrary protocol message from
                              standard input and write the raw tag/value
                              pairs in text format to standard output.  No
                              PROTO_FILES should be given when using this
                              flag.
  -oFILE,                     Writes a FileDescriptorSet (a protocol buffer,
    --descriptor_set_out=FILE defined in descriptor.proto) containing all of
                              the input files to FILE.
  --include_imports           When using --descriptor_set_out, also include
                              all dependencies of the input files in the
                              set, so that the set is self-contained.
  --include_source_info       When using --descriptor_set_out, do not strip
                              SourceCodeInfo from the FileDescriptorProto.
                              This results in vastly larger descriptors that
                              include information about the original
                              location of each decl in the source file as
                              well as surrounding comments.
  --error_format=FORMAT       Set the format in which to print errors.
                              FORMAT may be 'GCc' (the default) or 'msvs'
                              (Microsoft Visual Studio format).
  --plugin=EXECUTABLE         Specifies a plugin executable to use.
                              Normally, protoc searches the PATH for
                              plugins, but you may specify additional
                              executables not in the path using this flag.
                              Additionally, EXECUTABLE may be of the form
                              NAME=PATH, in which case the given plugin name
                              is mapped to the given executable even if
                              the executable's own name differs.
  --cpp_out=OUT_DIR           Generate c++ header and source.
  --java_out=OUT_DIR          Generate Java source file.
  --python_out=OUT_DIR        Generate Python source file.


3.简单使用一下

首先定义proto文件,my.proto
  {
  optional int32 id=1;
  optional string testname=2;
  }

然后,执行命令:

protoc --python_out=./ ./my.proto

得到my_pb2.py文件

最后,在当前目录下新建一个test.py文件夹,写入测试的脚本,包括序列化和反序列化代码:


--结束END--

本文标题: Protocol Buffer的使用(p

本文链接: https://www.lsjlt.com/news/188740.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Protocol Buffer的使用(p
    1.需要安装Protocol Buffer 直接:apt-get install protobuf-compiler 安装完毕后,进入解压目录的python目录,执行python setup.py install;安装python的pro...
    99+
    2023-01-31
    Protocol Buffer
  • C++中Protocol Buffer怎么安装和使用
    要在C++中使用Protocol Buffer,您需要进行以下步骤来安装和使用它: 下载和安装 Protocol Buffer ...
    99+
    2023-10-23
    C++
  • Golang安装和使用protocol-buffer流程介绍
    目录前言安装protoc编译工具编写proto文件生成指定语言的proto文件调用proto制作插件前言 protocol buffer是Google发布的一种独立的数据交换格式,类...
    99+
    2022-11-11
  • 在Python中使用protocol b
    本教程提供了一个Python程序员使用protocol buffers的基本的入门教程。通过创建一个简单的示例应用程序,它向您展示了如何 *在一个.proto文件中定义Message的格式。 *使用protocol buffer c...
    99+
    2023-01-31
    Python protocol
  • location中assign与protocol如何使用
    本篇内容主要讲解“location中assign与protocol如何使用”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“location中assign与prot...
    99+
    2022-10-19
  • Spring P标签的使用详解
    目录Spring P标签的使用本例设计对象Topic、Speech和Speakerspring配置p标签问题今天学习spring遇到这样的一个问题解决方法如下Spring P标签的使...
    99+
    2022-11-12
  • 再述:python中redis的使用(P
    redis提供两个类Redis和StrictRedis用于实现Redis的命令,StrictRedis用于实现大部分官方的命令,并使用官方的语法和命令,Redis是StrictRedis的子类,用于向后兼容旧版本的redis-py。redi...
    99+
    2023-01-31
    再述 python redis
  • 关于python使用hadoop(使用p
    最近想学习一下hadoop,但是本人对java不是很熟悉,所以决定用python来进行尝试,以下是整个环境部署及测试: 软件环境:VMware10.0,VMware10,ubuntu15.10桌面版(ubuntukylin-15.10-d...
    99+
    2023-01-31
    python hadoop
  • C++使用boost.python编写P
    很久没有写文章了,今天整理了一些东西,在这里分享一下。 最近一直在想用C++封装一些在工作中常用的Python扩展模块,因为之前没有用C++写过类似的东西,因此一直在网上找一些文章,但是我发现好多文章都描述的不是很清晰,对于老鸟来说应该会很...
    99+
    2023-01-31
    boost python
  • Python 3 进阶 —— 使用 P
    PyMySQL 是一个纯 Python 实现的 MySQL 客户端操作库,支持事务、存储过程、批量执行等。 PyMySQL 遵循 Python 数据库 API v2.0 规范,并包含了 pure-Python MySQL 客户端库。 安装...
    99+
    2023-01-31
    进阶 Python
  • Node.js的Buffer模块怎么使用
    这篇文章主要介绍“Node.js的Buffer模块怎么使用”,在日常操作中,相信很多人在Node.js的Buffer模块怎么使用问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”...
    99+
    2022-10-19
  • Node中的Buffer类怎么使用
    这篇文章主要介绍了Node中的Buffer类怎么使用的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Node中的Buffer类怎么使用文章都会有所收获,下面我们一起来看看吧。在TypedArray出来之前,Jav...
    99+
    2023-07-04
  • Android下使用lamemp3库将P
    之前已经介绍过iOS下使用lamemp3将PCM压缩为mp3格式,今天介绍一下Android的使用。至于lamemp3库的下载就不再介绍了,大家可以直接把iOS的那个库拷过来,或者使用我附件中的库也可以。下面我介绍一下整个使用步骤,我将按照...
    99+
    2023-01-31
    Android
  • python学习-windows下使用p
       有时候需要处理很多报表,将一个目录下的所有excel格式报表合并,手工操作费事费力如果能使用python,将多个.xlsx同时能够合并多个excel表的话,多么方便。1、windows上python配置windows上安装的是pyth...
    99+
    2023-01-31
    python windows
  • redis protocol通信协议及使用详解
    目录简介Redis的高级用法Redis中的piplineRedis中的Pub/SubRESP protocolSimple StringsBulk StringsRESP IntegersRESP ArraysRESP ...
    99+
    2022-07-15
    redis protocol通信协议 redis protocol
  • redis protocol通信协议及使用详解
    目录简介redis的高级用法Redis中的piplineRedis中的Pub/SubRESP protocolSimple StringsBulk StringsRESP Integ...
    99+
    2022-11-13
  • Nodejs中的buffer模块怎么使用
    这篇文章主要介绍“Nodejs中的buffer模块怎么使用”,在日常操作中,相信很多人在Nodejs中的buffer模块怎么使用问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”...
    99+
    2022-10-19
  • 浅谈C++ 缓冲区(buffer)的使用
    缓冲区 缓冲区 (buffer) 是内存空间的一部分. 在内存中会为每一个数据流开辟一个内存缓冲区. 缓冲区是用来存放流中的数据, 缓冲区中的数据就是流. 在 C++ 中, 输入输出...
    99+
    2022-11-12
  • Docker教程:使用docker配置p
    http://blog.csdn.net/pipisorry/article/details/50808034 Docker的安装和配置 [Docker教程:docker的安装] [Docker教程:dokcer的配置]  皮皮blog ...
    99+
    2023-01-31
    教程 Docker docker
  • nginx中配置使用proxy protocol协议的全过程
    目录简介proxy protocol在nginx中应用在nginx中配置使用proxy protocol在nginx中启用proxy protocol使用Real‑IP module...
    99+
    2022-11-13
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作