Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Don't support nested message. #10

Closed
yihuang opened this issue Dec 23, 2012 · 3 comments
Closed

Don't support nested message. #10

yihuang opened this issue Dec 23, 2012 · 3 comments

Comments

@yihuang
Copy link

yihuang commented Dec 23, 2012

The decode api only decode one layer.

For example, a message like this:

message Detail {
  ...
}
message List {
  repeated Detail details;
}

I want to decode a list, i have to manually decode details with a loop:

local list = protobuf.decode('List', buffer)
for _, buf in list.details or {} do
    local detail = protobuf.decode(unpack(buf))
end

Is there an api to decode it recursively, or is it possible to implement this using a lua function.

@SimonRen
Copy link

seems that, there is a metatable for table 'list', when you access any field of table 'list', it will decode sub-fields of 'list' automatic for you.

On Dec 23, 2012, at 8:28 PM, yihuang wrote:

The decode api only decode one layer.

For example, a message like this:

message Detail {
...
}
message List {
repeated Detail details;
}
I want to decode a list, i have to manually decode details with a loop:

local list = protobuf.decode('List', buffer)
for _, buf in list.details or {} do
local detail = protobuf.decode(unpack(buf))
end

Reply to this email directly or view it on GitHub.

@cloudwu
Copy link
Owner

cloudwu commented Dec 23, 2012

SimonRen is right.
And did you use lua 5.1 ? lua 5.1's pairs can not invoke the meta method '__pairs' .

@cloudwu cloudwu closed this as completed Dec 24, 2012
@yihuang
Copy link
Author

yihuang commented Dec 24, 2012

It tuns out my table dump function don't trigger any metatable magic methods, whan i index it normally, it works,

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants