Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proto3怎么区分默认值和缺省值呢? #239

Open
dwjcola opened this issue Apr 3, 2023 · 1 comment
Open

proto3怎么区分默认值和缺省值呢? #239

dwjcola opened this issue Apr 3, 2023 · 1 comment
Labels

Comments

@dwjcola
Copy link

dwjcola commented Apr 3, 2023

在设置pb.option("no_default_values")的情况下,无论是没赋值还是赋的默认值,decode出来都是nil,请问怎么区分呢?
另,试了
local parser = protoc.new();
parser.proto3_optional = true
之后在proto3中加入 optional 依然报错

@starwing
Copy link
Owner

starwing commented Apr 3, 2023

你试试最新的master的版本,我这边是OK的:

local pb = require "pb"
local slice = require "pb.slice"
local buffer = require "pb.buffer"
local protoc = require "protoc"
local serpent = require "serpent"

local parser = protoc.new()
parser.proto3_optional = true
parser:load [[
syntax = "proto3";
message Test {
   optional uint32 foo = 1;
}
]]

print(serpent.block(pb.decode("Test", pb.encode("Test", {}))))
print(serpent.block(pb.decode("Test", pb.encode("Test", {foo = 0}))))

输出:

{} --[[table: 00000195450FBEF0]]
{
  foo = 0,
  optional_foo = "foo"
} --[[table: 00000195450FC830]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants