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

请问下java的.proto文件存在import引用其它文件如何加载 #263

Open
sue602 opened this issue Mar 25, 2024 · 1 comment
Open
Labels

Comments

@sue602
Copy link

sue602 commented Mar 25, 2024

有文件1,文件名为 a.proto 内容如下

syntax = "proto2";
option java_package = "bf.message.game"; 
option java_outer_classname = "AntiqueMessage"; 

package bf.messages.game.EngineMessage;

message MsgGetReq_55012{
    optional CommonMsgMessage.MsgResources res= 1;
    optional int64 time=2; 
}
message MsgGetResp_55012{
    
}

有文件2,文件名为 b.proto 内容如下

syntax = "proto2";
option java_package = "bf.message.game"; 
option java_outer_classname = "CommonMsgMessage"; 

package bf.messages.game.CommonMsgMessage;

message MsgResources {
    optional int32 id = 1; 
    optional string num = 2; 
}

加载:

local pb = require "pb"
local protoc = require "protoc"
local pbdir = "./"
local protofiles = {a.proto,b.proto}
protoc:addpath(pbdir)

for _, proto_filename in ipairs(protofiles) do
     local proto = protoc.new()
     proto:addpath(pbdir)
     proto:loadfile(proto_filename)
end

local dd = {res= {id=1,num=3}, time= 3}
local bytes = pb.encode("MsgGetReq_55012", dd)  -- 这样加载失败
-- local bytes = pb.encode("AntiqueMessage.MsgGetReq_55012", dd)  -- 这样也是失败的

请问下要如何才能正确加载这种有import引用呢, 感谢

@starwing
Copy link
Owner

starwing commented Mar 25, 2024 via email

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