kingluo commented on issue #8655:
URL: https://github.com/apache/apisix/issues/8655#issuecomment-1378460282

   @gaoxingliang
   It seems that there is bug for 
[lua-protobuf](https://github.com/starwing/lua-protobuf) (used by APISIX) to 
import file in proto file.
   When I copy all definitions except `package google.protobuf;` from 
`protobuf/src/google/protobuf/struct.proto`, everything is ok.
   
   `test_struct.proto`
   
   ```protobuf
   syntax = "proto3";
   package test;
   //import "protobuf/src/google/protobuf/struct.proto";
   //copied from struct.proto
   option cc_enable_arenas = true;
   option go_package = "google.golang.org/protobuf/types/known/structpb";
   option java_package = "com.google.protobuf";
   option java_outer_classname = "StructProto";
   option java_multiple_files = true;
   ...
   message RawRequest {
       //google.protobuf.Struct reqdata = 1;
       Struct reqdata = 1;
       string type = 2;
       string serviceurl = 3;
       string source = 4;
       int32 page = 5;
       int32 size = 6;
   }
   ```
   
   `test_struct.lua`
   
   ```lua
   local pb = require "pb"
   local protoc = require "protoc"
   local cjson = require"cjson"
   
   assert(protoc:loadfile("test_struct.proto"))
   local data = [[
   {
       "type":"7",
       "serviceurl" :"xxxx",
       "reqdata" :{
           "fields": {
               "name": {"number_value":3},
               "key": {"string_value":"yyyy"}
           }
       },
       "source":"3"
   }
   ]]
   local tbl = cjson.decode(data)
   print(cjson.encode(tbl))
   local data = pb.encode("test.RawRequest", tbl)
   local decoded = pb.decode("test.RawRequest", data)
   print(cjson.encode(decoded))
   ```
   
   ```bash
   $ luajit test_struct.lua
   
{"source":"3","reqdata":{"fields":{"name":{"number_value":3},"key":{"string_value":"yyyy"}}},"serviceurl":"xxxx","type":"7"}
   
{"reqdata":{"fields":{"name":{"number_value":3,"kind":"number_value"},"key":{"string_value":"yyyy","kind":"string_value"}}},"serviceurl":"xxxx","source":"3","page":0,"size":0,"type":"7"}
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to