-
Notifications
You must be signed in to change notification settings - Fork 395
Open
Labels
Description
local pb = require "pb"
local protoc = require "protoc"
assert(protoc:load [[
message Phone {
optional string name = 1;
optional int64 phonenumber = 2;
optional Person item = 3;
}
message Person {
optional string name = 1;
optional int32 age = 2;
optional string address = 3;
repeated Phone contacts = 4;
} ]])
local data = {
name = "ilse",
age = 18,
contacts = {
{ name = "alice", phonenumber = 12312341234 }
}
}
data.contacts[1].item = data
local bytes = pb.encode("Person", data)
执行这段代码会得到如下结果
lua: a.lua:26: stack overflow (message too many levels)
stack traceback:
[C]: in function 'encode'
a.lua:26: in main chunk
[C]: ?
虽然可以利用pcall来解决,但是是否应该在encode中对这种数据循环引用的情况做一些检查来避免栈满的情况呢?