C 語言協定緩衝區的分隔I/O 函數
問題:
問題:
問題:
問題:
<code class="cpp">bool writeDelimitedTo( const google::protobuf::MessageLite& message, google::protobuf::io::ZeroCopyOutputStream* rawOutput) { // Create a new coded stream for each message. google::protobuf::io::CodedOutputStream output(rawOutput); // Write the size. int size = message.ByteSize(); output.WriteVarint32(size); // Optimize for messages that fit in a single buffer. uint8_t* buffer = output.GetDirectBufferForNBytesAndAdvance(size); if (buffer != NULL) { message.SerializeWithCachedSizesToArray(buffer); return true; } // Slower path for messages that span multiple buffers. message.SerializeWithCachedSizes(&output); return !output.HadError(); } bool readDelimitedFrom( google::protobuf::io::ZeroCopyInputStream* rawInput, google::protobuf::MessageLite* message) { // Create a new coded stream for each message. google::protobuf::io::CodedInputStream input(rawInput); // Read the size. uint32_t size; if (!input.ReadVarint32(&size)) return false; // Limit the stream to the message 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; }</code>
問題:
以上是Java API for Protocol Buffers v2.1.0 中引入的「Delimited」 I/O 函數(parseDelimitedFrom、mergeDelimitedFrom 和 writeDelimitedTo)是否有 C 等效項?如果沒有,h的詳細內容。更多資訊請關注PHP中文網其他相關文章!