45 using namespace google::protobuf;
48 fileStream(filename.c_str(), ios::out | ios::binary | ios::trunc),
49 wrappedFileStream(NULL), gzipStream(NULL), zeroCopyStream(NULL)
52 panic(
"Could not open %s for writing\n", filename);
58 if (filename.find_last_of(
'.') != string::npos &&
59 filename.substr(filename.find_last_of(
'.') + 1) ==
"gz") {
92 codedStream.WriteVarint32(msg.ByteSize());
95 msg.SerializeWithCachedSizes(&codedStream);
99 fileStream(filename.c_str(), ios::in | ios::binary), fileName(filename),
101 wrappedFileStream(NULL), gzipStream(NULL), zeroCopyStream(NULL)
104 panic(
"Could not open %s for reading\n", filename);
107 unsigned char bytes[2];
136 uint32_t magic_check;
138 if (!codedStream.ReadLittleEndian32(&magic_check) ||
140 panic(
"Input file %s is not a valid gem5 proto format.\n",
187 if (codedStream.ReadVarint32(&size)) {
188 io::CodedInputStream::Limit limit = codedStream.PushLimit(size);
189 if (msg.ParseFromCodedStream(&codedStream)) {
190 codedStream.PopLimit(limit);
195 panic(
"Unable to read message from coded stream %s\n",
void write(const google::protobuf::Message &msg)
Write a message to the stream, preprending it with the message size.
google::protobuf::io::OstreamOutputStream * wrappedFileStream
Zero Copy stream wrapping the STL output stream.
ProtoOutputStream(const std::string &filename)
Create an output stream for a given file name.
std::ofstream fileStream
Underlying file output stream.
static const uint32_t magicNumber
Use the ASCII characters gem5 as our magic number.
google::protobuf::io::GzipOutputStream * gzipStream
Optional Gzip stream to wrap the Zero Copy stream.
~ProtoOutputStream()
Destruct the output stream, and also flush and close the underlying file streams and coded streams...
google::protobuf::io::ZeroCopyOutputStream * zeroCopyStream
Top-level zero-copy stream, either with compression or not.
Declaration of a wrapper for protobuf output streams and input streams.