How to change the buffer limit in Google's protobuf?

前端 未结 3 545
梦谈多话
梦谈多话 2020-12-09 20:34

I\'m getting this warning and an error afterwards when I try to parse a large message. I know than 64MB which is the default limit. I am using message.ParseFromIstream now.

3条回答
  •  悲哀的现实
    2020-12-09 20:59

    Just reading the documentation of the function that the error already told you about, would've answered that question:

    Hint: If you are reading this because your program is printing a warning about dangerously large protocol messages, you may be confused about what to do next. The best option is to change your design such that excessively large messages are not necessary. For example, try to design file formats to consist of many small messages rather than a single large one. If this is infeasible, you will need to increase the limit. Chances are, though, that your code never constructs a CodedInputStream on which the limit can be set. You probably parse messages by calling things like Message::ParseFromString(). In this case, you will need to change your code to instead construct some sort of ZeroCopyInputStream (e.g. an ArrayInputStream), construct a CodedInputStream around that, then call Message::ParseFromCodedStream() instead. Then you can adjust the limit. Yes, it's more work, but you're doing something unusual.

    Source

    Also it's probably a really good idea to follow the first part of the advice and redesign the application.

提交回复
热议问题