Baoyuantop commented on code in PR #12391:
URL: https://github.com/apache/apisix/pull/12391#discussion_r2206501304
##########
apisix/plugins/grpc-transcode/response.lua:
##########
@@ -132,6 +170,9 @@ return function(ctx, proto, service, method, pb_option,
show_status_in_body, sta
return err_msg
end
+ local array_names = fetch_proto_array_names ( proto )
Review Comment:
```suggestion
local array_names = fetch_proto_array_names( proto )
```
##########
apisix/plugins/grpc-transcode/response.lua:
##########
@@ -132,6 +170,9 @@ return function(ctx, proto, service, method, pb_option,
show_status_in_body, sta
return err_msg
end
+ local array_names = fetch_proto_array_names ( proto )
+ set_default_array(decoded,array_names)
Review Comment:
```suggestion
set_default_array(decoded, array_names)
```
##########
apisix/plugins/grpc-transcode/response.lua:
##########
@@ -16,13 +16,51 @@
--
local util = require("apisix.plugins.grpc-transcode.util")
local grpc_proto = require("apisix.plugins.grpc-transcode.proto")
-local core = require("apisix.core")
-local pb = require("pb")
-local ngx = ngx
-local string = string
+local core = require("apisix.core")
+local pb = require("pb")
+local ngx = ngx
+local string = string
local ngx_decode_base64 = ngx.decode_base64
-local ipairs = ipairs
-local pcall = pcall
+local ipairs = ipairs
+local pcall = pcall
+local type = type
+local pairs = pairs
+local setmetatable = setmetatable
+
+pb.option "decode_default_array"
+local repeated_label = 3
+
+local function fetch_proto_array_names(proto_obj)
+ local names = {}
+ if type(proto_obj) == "table" then
+ for k,v in pairs(proto_obj) do
+ if type(v) == "table" then
+ local sub_names = fetch_proto_array_names(v)
+ for sub_name,_ in pairs (sub_names ) do
+ names[sub_name]=1
+ end
+ end
+ end
+ if proto_obj["label"] == repeated_label then
+ names[proto_obj["name"]]=1
+ end
+ end
+ return names
+end
+
+local function set_default_array(tab,array_names )
Review Comment:
```suggestion
local function set_default_array(tab, array_names)
```
##########
apisix/plugins/grpc-transcode/response.lua:
##########
@@ -16,13 +16,51 @@
--
local util = require("apisix.plugins.grpc-transcode.util")
local grpc_proto = require("apisix.plugins.grpc-transcode.proto")
-local core = require("apisix.core")
-local pb = require("pb")
-local ngx = ngx
-local string = string
+local core = require("apisix.core")
+local pb = require("pb")
+local ngx = ngx
+local string = string
local ngx_decode_base64 = ngx.decode_base64
-local ipairs = ipairs
-local pcall = pcall
+local ipairs = ipairs
+local pcall = pcall
+local type = type
+local pairs = pairs
+local setmetatable = setmetatable
+
+pb.option "decode_default_array"
+local repeated_label = 3
+
+local function fetch_proto_array_names(proto_obj)
+ local names = {}
+ if type(proto_obj) == "table" then
+ for k,v in pairs(proto_obj) do
+ if type(v) == "table" then
+ local sub_names = fetch_proto_array_names(v)
+ for sub_name,_ in pairs (sub_names ) do
+ names[sub_name]=1
+ end
+ end
+ end
+ if proto_obj["label"] == repeated_label then
+ names[proto_obj["name"]]=1
+ end
+ end
+ return names
+end
+
+local function set_default_array(tab,array_names )
+ if type(tab) ~= "table" then
+ return false
+ end
+ for k, v in pairs(tab) do
Review Comment:
```suggestion
for k, v in pairs(tab) do
```
##########
apisix/plugins/grpc-transcode/response.lua:
##########
@@ -6,7 +6,7 @@
-- (the "License"); you may not use this file except in compliance with
-- the License. You may obtain a copy of the License at
--
--- http://www.apache.org/licenses/LICENSE-2.0
+-- http://www.apache.org/licenses/LICENSE-2.0
Review Comment:
Please revert these additional changes.
--
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]