大佬教程收集整理的这篇文章主要介绍了Java中协议缓冲区分隔的I / O功能是否有C ++等效项?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在这里参加聚会有点晚,但是下面的实现包括其他答案中缺少的一些优化,并且在输入64MB后不会失败(尽管它仍然对每个单独的消息强制执行64MB的限制,只是对整个消息流没有限制))。@H_197_3@
(我是C ++和Java protobuf库的作者,但我不再在Google上工作。很抱歉,此代码从未将其添加到官方lib中。如果有的话,它的样子。)@H_197_3@
@H_772_7@bool writedelimitedTo( const Google::protobuf::messagelite& message, Google::protobuf::io::ZerocopyOutputStream* rawOutput) { // We create a new coded stream for each message. Don't worry, this is fast. Google::protobuf::io::CodedOutputStream output(rawOutput); // Write the size. const int size = message.byteSize(); output.WriteVarint32(sizE); uint8_t* buffer = output.GetDirectBufferForNBytesAndAdvance(sizE); if (buffer != NulL) { // Optimization: The message fits in one buffer, so use the faster // direct-to-array serialization path. message.serializeWithCachedSizesToArray(buffer); } else { // Slightly-slower path when the message is multiple buffers. message.serializeWithCachedSizes(&output); if (output.HadError()) return false; } return true; } bool readdelimitedFrom( Google::protobuf::io::ZerocopyinputStream* rawinput, Google::protobuf::messagelite* messagE) { // We create a new coded stream for each message. Don't worry, this is fast, // and it makes sure the 64MB @R_202_10586@l size limit is imposed per-message rather // than on the whole stream. (See the CodedinputStream interface for more // info on this limit.) Google::protobuf::io::CodedinputStream input(rawinput); // Read the size. uint32_t size; if (!input.ReadVarint32(&sizE)) return false; // Tell the stream not to read beyond that size. Google::protobuf::io::CodedinputStream::limit limit = input.Pushlimit(sizE); // Parse the message. if (!message->MergeFromCodedStream(&input)) return false; if (!input.ConsumedEntiremessage()) return false; // Release the limit. input.Poplimit(limit); return true; }
以上是大佬教程为你收集整理的Java中协议缓冲区分隔的I / O功能是否有C ++等效项?全部内容,希望文章能够帮你解决Java中协议缓冲区分隔的I / O功能是否有C ++等效项?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。