Home >Backend Development >C++ >C Protocol Buffer Delimited I/O: Are There Java-Equivalent Functions?
In an attempt to read and write multiple Protocol Buffers messages from files using both C and Java, it has been observed that Java provides a set of "Delimited" I/O functions for this purpose. However, it remains uncertain if C offers similar functionality.
The Java API functions are:
As of version 3.3.0, Google has addressed this issue by introducing the following C equivalents in google/protobuf/util/delimited_message_util.h:
bool writeDelimitedTo( const google::protobuf::MessageLite& message, google::protobuf::io::ZeroCopyOutputStream* rawOutput) { // Code to write delimited messages } bool readDelimitedFrom( google::protobuf::io::ZeroCopyInputStream* rawInput, google::protobuf::MessageLite* message) { // Code to read delimited messages }
For those seeking to parse the size-prefixed messages in C without using the official library, the wire format is as follows:
The provided C implementations include optimizations that were missing from other responses. These optimizations ensure that the functions:
The above is the detailed content of C Protocol Buffer Delimited I/O: Are There Java-Equivalent Functions?. For more information, please follow other related articles on the PHP Chinese website!