19 #ifndef avro_Stream_hh__
20 #define avro_Stream_hh__
26 #include "boost/utility.hpp"
29 #include "Exception.hh"
55 virtual bool next(
const uint8_t **data,
size_t *len) = 0;
62 virtual void backup(
size_t len) = 0;
67 virtual void skip(
size_t len) = 0;
74 virtual size_t byteCount()
const = 0;
77 typedef std::unique_ptr<InputStream> InputStreamPtr;
100 virtual void seek(int64_t position) = 0;
103 typedef std::unique_ptr<SeekableInputStream> SeekableInputStreamPtr;
126 virtual bool next(uint8_t **data,
size_t *len) = 0;
132 virtual void backup(
size_t len) = 0;
139 virtual uint64_t byteCount()
const = 0;
145 virtual void flush() = 0;
148 typedef std::unique_ptr<OutputStream> OutputStreamPtr;
186 size_t bufferSize = 8 * 1024);
193 const char *filename,
size_t bufferSize = 8 * 1024);
194 AVRO_DECL SeekableInputStreamPtr fileSeekableInputStream(
195 const char *filename,
size_t bufferSize = 8 * 1024);
203 size_t bufferSize = 8 * 1024);
211 std::istream &in,
size_t bufferSize = 8 * 1024);
224 std::istream &is,
size_t bufferSize = 8 * 1024);
289 ::memcpy(b,
next_, q);
301 if (n >
static_cast<size_t>(
end_ -
next_)) {
419 ::memcpy(
next_, b, q);
466 const uint8_t *p =
nullptr;
469 while (in.
next(&p, &n)) {
bool hasMore()
Returns true if and only if the end of stream is not reached.
Definition: Stream.hh:339
void reset(OutputStream &os)
Replaces the current underlying stream with a new one.
Definition: Stream.hh:389
void writeBytes(const uint8_t *b, size_t n)
Writes the specified number of bytes starting at b.
Definition: Stream.hh:410
A no-copy output stream.
Definition: Stream.hh:108
bool fill()
Get as many byes from the underlying stream as possible in a single chunk.
Definition: Stream.hh:316
virtual void flush()=0
Flushes any data remaining in the buffer to the stream's underlying store, if any.
InputStream * in_
The underlying input stream.
Definition: Stream.hh:231
AVRO_DECL OutputStreamPtr fileOutputStream(const char *filename, size_t bufferSize=8 *1024)
Returns a new OutputStream whose contents would be stored in a file.
AVRO_DECL InputStreamPtr nonSeekableIstreamInputStream(std::istream &is, size_t bufferSize=8 *1024)
Returns a new InputStream whose contents come from the given std::istream.
AVRO_DECL InputStreamPtr memoryInputStream(const uint8_t *data, size_t len)
Returns a new InputStream, with the data from the given byte array.
AVRO_DECL OutputStreamPtr ostreamOutputStream(std::ostream &os, size_t bufferSize=8 *1024)
Returns a new OutputStream whose contents will be sent to the given std::ostream.
void flush()
backs up upto the currently written data and flushes the underlying stream.
Definition: Stream.hh:430
AVRO_DECL OutputStreamPtr memoryOutputStream(size_t chunkSize=4 *1024)
Returns a new OutputStream, which grows in memory chunks of specified size.
void skipBytes(size_t n)
Skips the given number of bytes.
Definition: Stream.hh:300
void reset(InputStream &is)
Replaces the current input stream with the given one after backing up the original one if required.
Definition: Stream.hh:257
uint8_t * end_
One past the last location one can write to.
Definition: Stream.hh:373
uint8_t * next_
The next location to write to.
Definition: Stream.hh:368
A convenience class for reading from an InputStream.
Definition: Stream.hh:227
A bunch of templates and specializations for encoding and decoding specific types.
Definition: AvroParse.hh:30
int64_t byteCount() const
Return the number of bytes written so far.
Definition: Stream.hh:442
void more()
Tries to get more data and if it cannot, throws an exception.
Definition: Stream.hh:330
AVRO_DECL InputStreamPtr fileInputStream(const char *filename, size_t bufferSize=8 *1024)
Returns a new InputStream whose contents come from the given file.
StreamWriter()
Constructs a writer with no underlying stream.
Definition: Stream.hh:378
AVRO_DECL std::shared_ptr< std::vector< uint8_t > > snapshot(const OutputStream &source)
Returns the contents written so far into the output stream, which should be a memory output stream.
void drain(bool unRead)
Returns unused bytes back to the underlying stream.
Definition: Stream.hh:347
const uint8_t * next_
The next location to read from.
Definition: Stream.hh:236
const uint8_t * end_
One past the last valid location.
Definition: Stream.hh:241
void more()
Gets more space to write to.
Definition: Stream.hh:449
AVRO_DECL InputStreamPtr istreamInputStream(std::istream &in, size_t bufferSize=8 *1024)
Returns a new InputStream whose contents come from the given std::istream.
void readBytes(uint8_t *b, size_t n)
Reads the given number of bytes from the underlying stream.
Definition: Stream.hh:280
virtual void backup(size_t len)=0
"Returns" back to the stream some of the buffer obtained from in the last call to next().
StreamReader(InputStream &in)
Constructs a reader with the given underlying stream.
Definition: Stream.hh:251
void copy(InputStream &in, OutputStream &out)
A convenience function to copy all the contents of an input stream into an output stream.
Definition: Stream.hh:465
virtual bool next(uint8_t **data, size_t *len)=0
Returns a buffer that can be written into.
A convenience class to write data into an OutputStream.
Definition: Stream.hh:359
OutputStream * out_
The underlying output stream for this writer.
Definition: Stream.hh:363
StreamReader()
Constructs an empty reader.
Definition: Stream.hh:246
virtual uint64_t byteCount() const =0
Number of bytes written so far into this stream.
void write(uint8_t c)
Writes a single byte.
Definition: Stream.hh:400
StreamWriter(OutputStream &out)
Constructs a new writer with the given underlying stream.
Definition: Stream.hh:383
Wrapper for std::runtime_error that provides convenience constructor for boost::format objects.
Definition: Exception.hh:31
uint8_t read()
Read just one byte from the underlying stream.
Definition: Stream.hh:269