starwing / lua-protobuf

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

nested message with default values regression #256

Open kobykahane opened 10 months ago

kobykahane commented 10 months ago

With the latest lua-protobuf master, the assertion on the last line of this program is hit:

pb = require 'pb'
protoc = require 'protoc'

assert(protoc:load[[
syntax = "proto3";

package repro;

message Inner {
    string value = 1;
}

message Outer {
    Inner inner = 1;
}
]])

outer = {inner={value=""}}

assert(outer)
assert(outer.inner)

m = assert(pb.decode('repro.Outer', assert(pb.encode('repro.Outer', outer))))

assert(m.inner, 'inner')

As follows:

lua5.4: repro.lua:25: inner
stack traceback:
        [C]: in function 'assert'
        repro.lua:25: in main chunk
        [C]: in ?

This does not happen with older versions of lua-protobuf. After a git bisect, I've narrowed the change in behavior down to commit 7de8652a02a19a421698e2cbf8c2460108552bf1. From the commit description, this change does not appear to be intentional.

starwing commented 10 months ago

This commit fix a encode bug, if you need default message, use option "decode_default_message"