starwing / lua-protobuf

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

unfinished bytes #60

Closed Swagova closed 6 years ago

Swagova commented 6 years ago

Hi, We are trying to decode google rtb requester post data. But it is giving "unfinished bytes" error. Our .proto file : https://developers.google.com/ad-exchange/rtb/downloads/realtime-bidding-proto.txt Here is the code we are using

local bid_request = assert(pb.decode("BidRequest", ngx.req.get_body_data()))

Can you help me with this.

starwing commented 6 years ago

post data? it's a text-based data format? maybe you should base64 data before send it via post?

Swagova commented 6 years ago

Google sends a bid request as a serialized protocol buffer attached as the binary payload of an HTTP POST request. While we are decoding that bid request we are getting above error.

starwing commented 6 years ago

So maybe you should use Content-Length to receive all bytes of the binary payload? you can try it out, or use payload binary make a minimalized failure test for me.

rdraju commented 6 years ago

I can confirm this. I have attached a simple example that trying to load the .proto file and decode data in PB format. The data exists in a separate file and can be successfully decoded using other libraries.

pb_test.zip

starwing commented 6 years ago

I just find out the reason. because your proto file 771 line set billing_id as not packed, but in proton.Lua any value in packed will treated as "true" :-( my bad.

just pushed a new version you could try it out, any feedbacks are welcome :-)

rdraju commented 6 years ago

That did the trick. Thanks for the quick resolution and the package itself.