starwing / lua-protobuf

A Lua module to work with Google protobuf
MIT License
1.73k stars 387 forks source link

decode map error #201

Closed stillcold closed 2 years ago

stillcold commented 2 years ago

Hi starwing,

I think decoding map has a bug:

local pb = require "pb"
local protoc = require "protoc"

assert(protoc:load [[
    message Member {
        repeated int32 id = 1;
    }

    message Team {
        map <int32, Member> team_member = 1;
    }

]])

-- lua table data
local team_data = {team_member = {}}
team_data.team_member[0] = {1,2}

local tbl = pb.decode("Team", pb.encode("Team", team_data))
print(tbl.team_member[0][1]) --> 1 expected, got  nil
starwing commented 2 years ago

maybe it should be team_data.team_member[0] = { id = {1, 2} }?

stillcold commented 2 years ago

That's right. I am a fool. Please forgive me, man.