proto3 移除了内建类型的非空判断方法

  • 即代码生成工具不会为 bool int 等类型生成has方法

有使用过proto2 或者其它rpc 框架的人都知道使用has 方法去判断消息里的值是否设置,

而在proto3 里只有自定义类型才能有这个方法了,

这个问题在github上引起激烈讨论, 以下是开发人员在github的解释

大致意思是从简易性和实践出发降低复杂度,停止支持为空的判断, 但是用户依旧有其它办法支持has,例如oneof和自定义类型

I brought up the syntax sugar proposal in #1606 (comment) to protobuf team meetings and after some discussions the decision is to not move forward with the proposal:

Rationale of removing field presence in proto3:
Field presence in proto2 has caused confusions and it complicates the semantics, e.g. one
has to distinguish between absence fields vs fields set to their default values; users usually
check presence before accessing the fields which is unnecessary. We believe in most cases,
field presence info is not needed.
Removing field presence makes Proto3 significantly easier to implement with open struct
representations, as in languages like Android Java (go/nano-proto), or Go. The easier
implementation in turn makes it better accessible to external implementer communities.
If such presence info is explicitly needed, there are several workarounds, e.g. wrappers, explicit
has_field boolean. Oneof can also be used if backward wire compatibility with proto2 optional
field is desired.
Introducing a new keyword or reusing an existing keyword to support field presence in proto3
will complicate protobuf semantics. We believe it will lead to confusion and misuse, which
defeats the purpose of removing field presence in proto3.

We may reconsider the proposal in the future when there are more data showing field presence are used more often than we expect in proto3, but at the moment we recommend users to design their proto3 protos without relying on field presence.

proto3 不支持内建类型的非空判断即 hasXXX的更多相关文章

  1. dart之旅(二)- 内建类型

    目录 number 类型 字符串 布尔类型 像大多数语言一样,dart 也提供了 number,string,boolean 等类型,包括以下几种: numbers strings booleans ...

  2. python高级编程之(类级):子类内建类型

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #类级 #在2.2中,提出了类型(type0与类(class)统一( ...

  3. 零基础学python-4.2 其它内建类型

    这一章节我们来聊聊其它内建类型 1.类型type 在python2.2的时候,type是通过字符串实现的,再后来才把类型和类统一 我们再次使用上一章节的图片来说明一些问题 我们通过对照上面的图片.在p ...

  4. C/C++ 指针的非空判断

    一定要分得清楚C和C++的“空指针常量”不是一样的.C标准不保证NULL等于0,所以做指针非空判断时,应该用if(p != NULL):因为“上下文转换到bool值”的统一性,C++就应该用if(p) ...

  5. JAVAWEB servlet验证登录时进行完全的非空判断防止空值登录

    如果不进行完全的非空判断,那么对 "" 这种类型的空值就会导致直接登录 所以需要用下面的字符串处理方法对其进行判断 这样就可以防止空值登录了 容易出现的混淆错误: 这里的空值登录容 ...

  6. java基础之----非空判断

    大家好,第一次写博客,一直想写博客,用于自我总结,也用于帮助新同学成长. 平常我们开发的时候,用到很多非空判断,但是很多同学用到的地方不是很准确,这里,我把自己平时遇到的坑跟大家说说.我废话不多,只想 ...

  7. List和String的非空判断

    1.如果想判断list是否为空,可以这么判断: if(null == list || list.size() ==0 ){ //为空的情况 }else{ //不为空的情况 } 2.list.isEmp ...

  8. throw关键字和Objects非空判断_requireNonNull方法

    作用: 可以使用throw关键字在指定的方法中抛出指定的异常 使用格式: throw new xxxException("异常产生的原因") 注意: 1.throw关键字必须写在方 ...

  9. String的非空判断、Integer的非空判断、list的大小判断,对象的非空判断

    1.String的非空判断. StringUtils.isNotEmpty(String str); 2.Integer的非空判断. null != Integer ; 3.list的大小判断. li ...

随机推荐

  1. NO10 查看Linux操作系统-版本-内核-Linux分区

    ·看Linux系统: [root@localhost ~]# uname -m  (看操作系统)x86_64[root@localhost ~]# uname -a   (看操作系统)Linux lo ...

  2. Rabbitmq之高级特性——实现消费端限流&NACK重回队列

    如果是高并发下,rabbitmq服务器上收到成千上万条消息,那么当打开消费端时,这些消息必定喷涌而来,导致消费端消费不过来甚至挂掉都有可能. 在非自动确认的模式下,可以采用限流模式,rabbitmq ...

  3. 配置多个数据源datasource

    https://www.jianshu.com/p/34730e595a8c @Primary.@Qualifire.@Autowired.@Resource https://blog.csdn.ne ...

  4. Oracle 子程序、过程、函数

    一.子程序 子程序是一个数据库对象,存在于数据库中,里面存放的是PL/SQL代码,可以完成一定的共能,能被程序和客户端工具直接调用.子程序类似于java中的方法,可以接接收参数,按照是否有返回值,子程 ...

  5. JPA#Interfaces总结

    _开局一张图,内容全靠编 震惊:某小白熟练使用了JpaRepository和JpaSpecificationExecutor,就在简历上写下了,精通SpringData Jpa. 震惊,如果想熟练的使 ...

  6. oracle基础知识小结

    一.查看oracle用户.角色信息1.查看所有用户 select * from all_users; select * from user_users; 2.查看用户或角色系统权限 select * ...

  7. 一条 SQL 在 Apache Spark 之旅

    转载自过往记忆大数据 https://www.iteblog.com/archives/2561.html Spark SQL 是 Spark 众多组件中技术最复杂的组件之一,它同时支持 SQL 查询 ...

  8. 一万五千字的Dissertation你真的会写了吗?

    在英国留学的同学们想要顺利毕业,就必须要过Dissertation这一关.而一篇Dissertation字数可能多大一万五千字,其写作难度之大让很多留学生疯狂吐槽.那么这么多字的Dissertatio ...

  9. 实验吧-杂项-啦啦啦(数据包http导出、图片拼接)

    比较综合的一道题. 1.数据包数据提取 首先下载数据包,一般数据包都是抓取的一些数据,需要对数据进行分析. 用wireshark打开数据包,筛选出http协议的数据,发现有两个是上传的数据: 我们就看 ...

  10. Cheat Engine 入门操作

    Cheat Engine(简称CE,中文名-作弊引擎),用于查找.修改内存数据,是游戏逆向的基础工具. 本文仅介绍基础操作. 1.打开进程 运行游戏程序,并将CE附加到进程 2.寻找数据地址,并修改数 ...