Port Lua client fix

This commit is contained in:
Ottatop 2024-02-23 18:10:28 -06:00
parent 556294d4ef
commit 67ee5021bd

View file

@ -136,9 +136,14 @@ function client.server_streaming_request(grpc_request_params, callback)
client.loop:wrap(function()
for response_body in stream:each_chunk() do
-- Skip the 1-byte compressed flag and the 4-byte message length
---@diagnostic disable-next-line: redefined-local
local response_body = response_body:sub(6)
local response_body = response_body
while response_body:len() > 0 do
local msg_len = string.unpack(">I4", response_body:sub(2, 5))
-- Skip the 1-byte compressed flag and the 4-byte message length
response_body = response_body:sub(6, 6 + msg_len - 1)
---@diagnostic disable-next-line: redefined-local
local success, obj = pcall(pb.decode, response_type, response_body)
@ -149,6 +154,9 @@ function client.server_streaming_request(grpc_request_params, callback)
local response = obj
callback(response)
response_body = response_body:sub(msg_len + 1)
end
end
local trailers = stream:get_headers()
@ -184,9 +192,14 @@ function client.bidirectional_streaming_request(grpc_request_params, callback)
client.loop:wrap(function()
for response_body in stream:each_chunk() do
-- Skip the 1-byte compressed flag and the 4-byte message length
---@diagnostic disable-next-line: redefined-local
local response_body = response_body:sub(6)
local response_body = response_body
while response_body:len() > 0 do
local msg_len = string.unpack(">I4", response_body:sub(2, 5))
-- Skip the 1-byte compressed flag and the 4-byte message length
response_body = response_body:sub(6, 6 + msg_len - 1)
---@diagnostic disable-next-line: redefined-local
local success, obj = pcall(pb.decode, response_type, response_body)
@ -197,6 +210,9 @@ function client.bidirectional_streaming_request(grpc_request_params, callback)
local response = obj
callback(response)
response_body = response_body:sub(msg_len + 1)
end
end
local trailers = stream:get_headers()