gem5  v21.2.0.0
protoio.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 
44 #ifndef __PROTO_PROTOIO_HH__
45 #define __PROTO_PROTOIO_HH__
46 
47 #include <google/protobuf/io/coded_stream.h>
48 #include <google/protobuf/io/gzip_stream.h>
49 #include <google/protobuf/io/zero_copy_stream_impl.h>
50 #include <google/protobuf/message.h>
51 
52 #include <fstream>
53 
59 {
60 
61  protected:
62 
64  static const uint32_t magicNumber = 0x356d6567;
65 
70 
71  private:
72 
77  ProtoStream(const ProtoStream&);
80 };
81 
91 {
92 
93  public:
94 
101  ProtoOutputStream(const std::string& filename);
102 
108 
115  void write(const google::protobuf::Message& msg);
116 
117  private:
118 
120  std::ofstream fileStream;
121 
123  google::protobuf::io::OstreamOutputStream* wrappedFileStream;
124 
126  google::protobuf::io::GzipOutputStream* gzipStream;
127 
129  google::protobuf::io::ZeroCopyOutputStream* zeroCopyStream;
130 
131 };
132 
141 {
142 
143  public:
144 
151  ProtoInputStream(const std::string& filename);
152 
158 
165  bool read(google::protobuf::Message& msg);
166 
170  void reset();
171 
172  private:
173 
177  void createStreams();
178 
182  void destroyStreams();
183 
185  std::ifstream fileStream;
186 
188  const std::string fileName;
189 
191  bool useGzip;
192 
194  google::protobuf::io::IstreamInputStream* wrappedFileStream;
195 
197  google::protobuf::io::GzipInputStream* gzipStream;
198 
200  google::protobuf::io::ZeroCopyInputStream* zeroCopyStream;
201 
202 };
203 
204 #endif //__PROTO_PROTOIO_HH
ProtoOutputStream::write
void write(const google::protobuf::Message &msg)
Write a message to the stream, preprending it with the message size.
Definition: protoio.cc:82
ProtoOutputStream::zeroCopyStream
google::protobuf::io::ZeroCopyOutputStream * zeroCopyStream
Top-level zero-copy stream, either with compression or not.
Definition: protoio.hh:129
ProtoInputStream::useGzip
bool useGzip
Boolean flag to remember whether we use gzip or not.
Definition: protoio.hh:191
ProtoInputStream::read
bool read(google::protobuf::Message &msg)
Read a message from the stream.
Definition: protoio.cc:180
ProtoInputStream::wrappedFileStream
google::protobuf::io::IstreamInputStream * wrappedFileStream
Zero Copy stream wrapping the STL input stream.
Definition: protoio.hh:194
ProtoStream
A ProtoStream provides the shared functionality of the input and output streams.
Definition: protoio.hh:58
ProtoInputStream::~ProtoInputStream
~ProtoInputStream()
Destruct the input stream, and also close the underlying file streams and coded streams.
Definition: protoio.cc:162
ProtoInputStream::gzipStream
google::protobuf::io::GzipInputStream * gzipStream
Optional Gzip stream to wrap the Zero Copy stream.
Definition: protoio.hh:197
ProtoOutputStream::wrappedFileStream
google::protobuf::io::OstreamOutputStream * wrappedFileStream
Zero Copy stream wrapping the STL output stream.
Definition: protoio.hh:123
ProtoOutputStream::ProtoOutputStream
ProtoOutputStream(const std::string &filename)
Create an output stream for a given file name.
Definition: protoio.cc:44
ProtoInputStream::zeroCopyStream
google::protobuf::io::ZeroCopyInputStream * zeroCopyStream
Top-level zero-copy stream, either with compression or not.
Definition: protoio.hh:200
ProtoInputStream::fileName
const std::string fileName
Hold on to the file name for debug messages.
Definition: protoio.hh:188
ProtoInputStream::fileStream
std::ifstream fileStream
Underlying file input stream.
Definition: protoio.hh:185
ProtoStream::operator=
ProtoStream & operator=(const ProtoStream &)
ProtoStream::magicNumber
static const uint32_t magicNumber
Use the ASCII characters gem5 as our magic number.
Definition: protoio.hh:64
ProtoOutputStream::fileStream
std::ofstream fileStream
Underlying file output stream.
Definition: protoio.hh:120
ProtoStream::ProtoStream
ProtoStream()
Create a ProtoStream.
Definition: protoio.hh:69
ProtoOutputStream::gzipStream
google::protobuf::io::GzipOutputStream * gzipStream
Optional Gzip stream to wrap the Zero Copy stream.
Definition: protoio.hh:126
ProtoInputStream::createStreams
void createStreams()
Create the internal streams that are wrapping the input file.
Definition: protoio.cc:122
ProtoInputStream::destroyStreams
void destroyStreams()
Destroy the internal streams that are wrapping the input file.
Definition: protoio.cc:148
ProtoOutputStream::~ProtoOutputStream
~ProtoOutputStream()
Destruct the output stream, and also flush and close the underlying file streams and coded streams.
Definition: protoio.cc:72
ProtoInputStream::reset
void reset()
Reset the input stream and seek to the beginning of the file.
Definition: protoio.cc:170
ProtoOutputStream
A ProtoOutputStream wraps a coded stream, potentially with compression, based on looking at the file ...
Definition: protoio.hh:90
ProtoInputStream
A ProtoInputStream wraps a coded stream, potentially with decompression, based on looking at the file...
Definition: protoio.hh:140
ProtoInputStream::ProtoInputStream
ProtoInputStream(const std::string &filename)
Create an input stream for a given file name.
Definition: protoio.cc:101

Generated on Tue Dec 21 2021 11:34:34 for gem5 by doxygen 1.8.17