一、直接看源码:
这是序列化打包的源代码:
bool MessageLite::SerializePartialToArray(void* data, int size) const {
const size_t byte_size = ByteSizeLong();
if (byte_size > INT_MAX) { // 只要不大于 2GB,那么都可以序列化
GOOGLE_LOG(ERROR) << GetTypeName()
<< " exceeded maximum protobuf size of 2GB: " << byte_size;
return false;
}
if (size < static_cast<int64_t>(byte_size)) return false;
uint8_t* start = reinterpret_cast<uint8_t*>(data);
SerializeToArrayImpl(*this, start, byte_size);
return true;
}
二、总结:
一个协议可以传送的数据量非常大,大部分情况都没有问题。
极端情况:
1.当内存非常小的时候
2.当客户端内存非常小的时候
这时,协议数据就需要分批发送,不然可能会造成协议数据发送不完全,解包失败