Closed leonyu879 closed 3 years ago
It seems that protobuf3 need the empty table, if you use protobuf2, the repeated table should not exists. But you can use pb.hook()
interrface to remove that table just after decodeed.
how pb.hook works with repeated
type (i have hundreds types defined in proto), actually i want treat empty repeated
/map
defferently(for json encode). and can u explain more clearly about it please?
It seems that protobuf3 need the empty tab
i have tried pb.hook("map")
but it doesn't works. if empty table is required for repeated in proto3, can pb.decode
remove empty map?
solved by removing all empty tables from decoded obj
Sorry for late reply, you could look this line in source: https://github.com/starwing/lua-protobuf/blob/3f2d706aca7b57c3ffc27daf85c03c7d21a21f7c/pb.c#L1320
just change it to if (...) return 0
w/o your own flags will remove the empty table.
the pb.hook()
interface acts on a message tyue, but "map" itself is not a message type, so pb.hook "map"
is not work :-(
currently I have no way to config pb
not produce the empty table other than modifying the source code, sorry for that...
decode
will drop field for refrerence type which value is empty in a message, that's good but when the type isrepeated
ormap
,decode
will generate a empty table which will let cjson encode it to{}
(or[]
when use empty_array_mt),that may cause type error in upstream service. candecode
drop field when the types above(repeated/map) is empty?