You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by fo...@apache.org on 2018/10/28 09:50:06 UTC
[avro] branch master updated: AVRO-2249 Fix for C++ build failures
(#360)
This is an automated email from the ASF dual-hosted git repository.
fokko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new c9a62f3 AVRO-2249 Fix for C++ build failures (#360)
c9a62f3 is described below
commit c9a62f3c2530f5c957edca4b5096f74c78b408a3
Author: Thiruvalluvan M G <th...@apache.org>
AuthorDate: Sun Oct 28 15:20:00 2018 +0530
AVRO-2249 Fix for C++ build failures (#360)
---
lang/c++/api/DataFile.hh | 3 ++-
lang/c++/impl/DataFile.cc | 36 +++++++++++++++++++-----------------
lang/c++/impl/NodeImpl.cc | 7 ++++---
3 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/lang/c++/api/DataFile.hh b/lang/c++/api/DataFile.hh
index d95f09b..30cae5a 100644
--- a/lang/c++/api/DataFile.hh
+++ b/lang/c++/api/DataFile.hh
@@ -183,7 +183,7 @@ public:
*/
class AVRO_DECL DataFileReaderBase : boost::noncopyable {
const std::string filename_;
- const std::auto_ptr<SeekableInputStream> stream_;
+ const std::auto_ptr<InputStream> stream_;
const DecoderPtr decoder_;
int64_t objectCount_;
bool eof_;
@@ -207,6 +207,7 @@ class AVRO_DECL DataFileReaderBase : boost::noncopyable {
void readHeader();
bool readDataBlock();
+ void doSeek(int64_t position);
public:
/**
* Returns the current decoder for this reader.
diff --git a/lang/c++/impl/DataFile.cc b/lang/c++/impl/DataFile.cc
index fdfd5b9..56ec619 100644
--- a/lang/c++/impl/DataFile.cc
+++ b/lang/c++/impl/DataFile.cc
@@ -90,12 +90,12 @@ DataFileWriterBase::DataFileWriterBase(const char* filename, const ValidSchema&
DataFileWriterBase::DataFileWriterBase(std::auto_ptr<OutputStream> outputStream,
const ValidSchema& schema, size_t syncInterval, Codec codec) :
- filename_(nullptr),
+ filename_(NULL),
schema_(schema),
encoderPtr_(binaryEncoder()),
syncInterval_(syncInterval),
codec_(codec),
- stream_(std::move(outputStream)),
+ stream_(outputStream),
buffer_(memoryOutputStream()),
sync_(makeSync()),
objectCount_(0)
@@ -281,7 +281,7 @@ DataFileReaderBase::DataFileReaderBase(const char* filename) :
}
DataFileReaderBase::DataFileReaderBase(std::auto_ptr<InputStream> inputStream) :
- filename_(nullptr), stream_(inputStream),
+ filename_(NULL), stream_(inputStream),
decoder_(binaryDecoder()), objectCount_(0), eof_(false)
{
readHeader();
@@ -527,25 +527,27 @@ void DataFileReaderBase::readHeader()
blockStart_ = stream_->byteCount();
}
-void DataFileReaderBase::seek(int64_t position) {
- if (!eof_) {
- dataDecoder_->init(*dataStream_);
- drain(*dataStream_);
+void DataFileReaderBase::doSeek(int64_t position) {
+ if (SeekableInputStream *ss = dynamic_cast<SeekableInputStream *>(stream_.get())) {
+ if (!eof_) {
+ dataDecoder_->init(*dataStream_);
+ drain(*dataStream_);
+ }
+ decoder_->init(*stream_);
+ ss->seek(position);
+ eof_ = false;
+ } else {
+ throw Exception("seek not supported on non-SeekableInputStream");
}
- decoder_->init(*stream_);
- stream_->seek(position);
- eof_ = false;
+}
+
+void DataFileReaderBase::seek(int64_t position) {
+ doSeek(position);
readDataBlock();
}
void DataFileReaderBase::sync(int64_t position) {
- if (!eof_) {
- dataDecoder_->init(*dataStream_);
- drain(*dataStream_);
- }
- decoder_->init(*stream_);
- stream_->seek(position);
- eof_ = false;
+ doSeek(position);
DataFileSync sync_buffer;
const uint8_t *p = 0;
size_t n = 0;
diff --git a/lang/c++/impl/NodeImpl.cc b/lang/c++/impl/NodeImpl.cc
index 435d2ef..1969406 100644
--- a/lang/c++/impl/NodeImpl.cc
+++ b/lang/c++/impl/NodeImpl.cc
@@ -28,7 +28,8 @@ namespace {
std::string escape(const std::string &unescaped) {
std::string s;
s.reserve(unescaped.length());
- for (auto c : unescaped) {
+ for (std::string::const_iterator it = unescaped.begin(); it != unescaped.end(); ++it) {
+ char c = *it;
switch (c) {
case '\\':
case '"':
@@ -289,10 +290,10 @@ void NodePrimitive::printDefaultToJson(const GenericDatum &g, std::ostream &os,
os << g.value<int64_t>();
break;
case AVRO_FLOAT:
- os << std::to_string(g.value<float>());
+ os << g.value<float>();
break;
case AVRO_DOUBLE:
- os << std::to_string(g.value<double>());
+ os << g.value<double>();
break;
case AVRO_STRING:
os << "\"" << escape(g.value<std::string>()) << "\"";