44using namespace google::protobuf;
47 fileStream(filename.c_str(),
48 std::ios::out |
std::ios::binary |
std::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(
'.') != std::string::npos &&
59 filename.substr(filename.find_last_of(
'.') + 1) ==
"gz") {
92# if GOOGLE_PROTOBUF_VERSION < 3001000
93 auto msg_size = msg.ByteSize();
95 auto msg_size = msg.ByteSizeLong();
97 codedStream.WriteVarint32(msg_size);
100 msg.SerializeWithCachedSizes(&codedStream);
104 fileStream(filename.c_str(),
std::ios::in |
std::ios::binary),
105 fileName(filename), useGzip(false),
106 wrappedFileStream(NULL), gzipStream(NULL), zeroCopyStream(NULL)
109 panic(
"Could not open %s for reading\n", filename);
112 unsigned char bytes[2];
141 uint32_t magic_check;
143 if (!codedStream.ReadLittleEndian32(&magic_check) ||
145 panic(
"Input file %s is not a valid gem5 proto format.\n",
192 if (codedStream.ReadVarint32(&size)) {
193 io::CodedInputStream::Limit limit = codedStream.PushLimit(size);
194 if (msg.ParseFromCodedStream(&codedStream)) {
195 codedStream.PopLimit(limit);
200 panic(
"Unable to read message from coded stream %s\n",
std::ofstream fileStream
Underlying file output stream.
google::protobuf::io::ZeroCopyOutputStream * zeroCopyStream
Top-level zero-copy stream, either with compression or not.
google::protobuf::io::OstreamOutputStream * wrappedFileStream
Zero Copy stream wrapping the STL output stream.
~ProtoOutputStream()
Destruct the output stream, and also flush and close the underlying file streams and coded streams.
ProtoOutputStream(const std::string &filename)
Create an output stream for a given file name.
void write(const google::protobuf::Message &msg)
Write a message to the stream, preprending it with the message size.
google::protobuf::io::GzipOutputStream * gzipStream
Optional Gzip stream to wrap the Zero Copy stream.
static const uint32_t magicNumber
Use the ASCII characters gem5 as our magic number.
#define panic(...)
This implements a cprintf based panic() function.
Overload hash function for BasicBlockRange type.
Declaration of a wrapper for protobuf output streams and input streams.