/* * Copyright (c) 2010-2018 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include #include #include #include using namespace Swift; std::shared_ptr ByteArrayReadBytestream::read(size_t size) { size_t readSize = size; if (position + readSize > data.size()) { readSize = data.size() - position; } try { std::shared_ptr result = std::make_shared( data.begin() + boost::numeric_cast(position), data.begin() + boost::numeric_cast(position) + boost::numeric_cast(readSize)); onRead(*result); position += readSize; return result; } catch (const boost::numeric::bad_numeric_cast&) { // If we cannot cast to long long, we probably ran out of memory long ago assert(false); return {}; } } void ByteArrayReadBytestream::addData(const std::vector& moreData) { append(data, moreData); onDataAvailable(); }