Comments (12)
没有字段的 message 是合法的么?
from pbc.
是的,protoc是可以生成空字段的。
from pbc.
我指的是协议上是不是合法的. 而不是 protoc 这个具体实现. 也可能是 protoc 不检查而已.
虽然我觉得不应该有空的 message (定义出来就是 bug), 不过还是把 parser 里检查空 message 的去掉了.
from pbc.
我觉得空的message有存在的必要,在一些小型的项目里面有的协议确实用不上字段,相当于是个开关指令,比如定义一个pause协议,就不需要什么参数。
from pbc.
定义一个空的 message 和不定义这个 message 对 protobuff 来说是一样的. 因为即使你定义了一个没有参数的 pause 协议, 发送这个协议和 protobuff 也没有关系. 就是说,识别你的协议是 pause 还是别的什么, 和 proto buffer 没有关系. 你定不定义 pause 也不是 protobuff 关心的事情.
from pbc.
如果空 message 作为另一个消息的子结构. 那么, 因为 protobuff 有 default 值的定义, 而一个 message 为空就是 default 状态. 按协议是可以不打包的. 具体是否打包可以由实现来决定. 在我的 pbc 的实现中, 如果一个 message 为空, 是永远不会打包的 (在最终的数据流中不存在). 所以定义一个空 message 就失去了意义.
from pbc.
我不太理解,但我想描述一下做为上层使用时的一个场景:
客户端和服务器用protobuff做为相互通讯的唯一通道,在这些message中使用者不心这里头的实现,他想要的效果只是序列化1个message_a,加上uri,加上长度,打包为二进制发送给对端。对端根据长度和uri反序列化出这个message_a而不>是message_b,这个message_a有可能有字段,也有可能没有字段,或者将来可能会加上字段.这种情况总不能让使用者针>对空message做一个特殊处理把?
from pbc.
我的意思是,即使你序列化了 message_a, 只加上长度是不够的, 你必须说清楚这是个 message_a. 可以发字符串也可以发 id, 这些都用 protobuff 之外的协议来约定. 通常你需要有一个自定义协议来描述这个东西. 这份东西里写清楚 message_a 不用 protobuffer 编码就可以了.
from pbc.
上面提到的uri指的就是你说的id吧。看来我们分歧就在与:你认为对空协议该做特殊处理,而我觉得不应该。
from pbc.
假设buf是空协议pause encode后的二进制数据,这个buf可能是空的(google的实现也是),但我觉得使用者不用关心怎么实现,也不用在乎buf是否是空,在乎的是当他用buf来decode协议时,还能decode出pause来,这个在google的实现里面是可以的,希望云风大大的这个pbc也能和google的做法相同.
from pbc.
不是一直都是支持的 ?
parser 那里只是做了个检查, 前几天已经把检查去掉了.
btw, 即使不是空协议, 打包的结果也可能是空的. (如果都是默认值)
from pbc.
噢,刚又试了一下,因为之前都是encode后写入文件,然后读出文件内容再decode的方式,这种在python下没问题,因为python下空文件读出来是""(空字符), 而lua读出来的是nil,所以decode出错了,改""就可以。
from pbc.
Related Issues (20)
- pbc_wmessage_integer
- mac os 上make命令不能执行 HOT 1
- 在 Mac 直接编译项目提供的 Demo,直接提示下面错误,大神能给看一下吗
- pbc_array_push_slice() bug?
- ubuntu+skynet+pbc环境,encode一个包含了int32类型的数据,会报错。但是改成了类型就不会了.
- skyent 加了一个protobuf 第一次运行报错了。 风哥看看这是啥原因啊 HOT 5
- protobuf 编译如何链接lua5.4,风哥是否能说的稍微详细一些。 HOT 3
- 最新版skynet里调用报错 HOT 3
- pbc是否支持protobuf3的any类型
- PBC library generate a BN256 curve
- enum 类型在 lua 层会被解析为 字符串呢?
- 是否支持grpc呢
- Error : rmessage decode context error HOT 2
- 是否能支持protobuf 3
- 编译binding/lua53时报错 HOT 3
- 在lua中修改的uint64字段字段,经过一次encode之后,又变回了原来的值,感觉没有修改成功,请云风大大看看怎么回事哈 HOT 1
- mingw环境下编译pbc的lua绑定库protobuf会出怪异现象,引用的skynet里lua5.4版本: HOT 5
- SEGV issue detected in pbc_wmessage_integer src/wmessage.c:137
- PBC有非Lazy的解析接口吗
- SEGV issue detected in pbc_wmessage_string src/wmessage.c:281:8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pbc.