在调用protobuf的ParseFromString(str)方法时,默认情况下,如果str的长度>64MB,会返回失败。

 

这里给出了解释,主要是出于安全因素的考虑。

 

可以通过SetTotalBytesLimit方法去除这个限制:

// ::google::protobuf::Message req;

::google::protobuf::io::ArrayInputStream input(str.data(), str.size());
::google::protobuf::io::CodedInputStream decoder(&input);
decoder.SetTotalBytesLimit(1024*1024*1024, 64*1024*1024);
bool success = req.ParseFromCodedStream(&decoder) && decoder.ConsumedEntireMessage();

相关文章:

  • 2021-04-26
  • 2023-01-30
  • 2022-12-23
  • 2022-02-08
  • 2021-10-13
  • 2021-07-13
  • 2021-11-16
  • 2021-08-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2021-08-23
  • 2021-05-10
  • 2022-12-23
  • 2021-05-18
相关资源
相似解决方案