Closed Gowa2017 closed 2 years ago
you could just use pb.decode('google.FileDescriptorSet', <pb file binary data>)
to get a Lua table about pb file with structure of FileDescriptorSet
(in google's descriptor.proto schema file). in this table, the messages are in order of schema file.
thanks ..I will try it
lua: gen.lua:126: bad argument #1 to 'decode' (type 'google.FileDescriptorSet' does not exists)
I try to decode it, but failed.
You can load descriptor.pb file content (from Google) or simply require "protoc"
Gowa2017 @.***>于2021年10月12日 周二11:29写道:
lua: gen.lua:126: bad argument #1 to 'decode' (type 'google.FileDescriptorSet' does not exists)
I try to decode it, but failed.
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/starwing/lua-protobuf/issues/164#issuecomment-940623904, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA36MZZ6XI7RCNAAKE35S3UGOTTBANCNFSM5FVO6RPA .
-- regards, Xavier Wang.
Not so sure how to do it. ,my code is :
package.cpath = package.cpath .. ";../../luaclib/?.so"
local pb = require("pb")
local pbio = require("pb.io")
local protoFile = "proto.pb"
local data = assert(pbio.read(protoFile))
local ok, n = pb.load(data)
assert(ok, n)
pb.decode("google.FileDescriptorSet", protoFile)
Error the same.
you should call this function: https://github.com/starwing/lua-protobuf/blob/e49582f704821b1b6049b4e5c3870ec89025cf2c/protoc.lua#L1147
because this function will be called after you require "protoc"
, so just require the protoc.lua.
I realy do this:
package.cpath = package.cpath .. ";../../luaclib/?.so"
local protoc = require("protoc")
local pb = require("pb")
local pbio = require("pb.io")
local protoFile = "proto.pb"
local data = assert(pbio.read(protoFile))
local ok, n = pb.load(data)
assert(ok, n)
pb.decode("google.FileDescriptorSet", protoFile)
But :
lua: test.lua:12: bad argument #1 to 'decode' (type 'google.FileDescriptorSet' does not exists)
stack traceback:
[C]: in function 'pb.decode'
test.lua:12: in main chunk
[C]: in ?
Oh, I read the protoc code, the type may be is 'google.protobuf.FileDescriptorSet', this workd:
package.cpath = package.cpath .. ";../../luaclib/?.so"
package.path = package.path .. ";3rd/Penlight/lua/?.lua"
local protoc = require("protoc")
local pb = require("pb")
local pbio = require("pb.io")
local protoFile = "proto.pb"
local data = assert(pbio.read(protoFile))
local pretty = require("pl.pretty")
local t = pb.decode("google.protobuf.FileDescriptorSet", data)
pretty.dump(t)
sorry for my typo 😢
thanks. I closed this issue
As now the pb.types() 's return is no order.
I found the command :
get the output below:
Its order is same with the .proto file.