diff options
author | Mark Spruiell <mes@zeroc.com> | 2016-03-09 16:00:39 -0800 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2016-03-09 16:00:39 -0800 |
commit | 15063818726cf3d474d77d9d5586b36a10a3d453 (patch) | |
tree | 35912f8e447722fdbc5f46a8a1500361a9327642 /cpp/src/IceDB | |
parent | fixing leak in Outgoing (diff) | |
download | ice-15063818726cf3d474d77d9d5586b36a10a3d453.tar.bz2 ice-15063818726cf3d474d77d9d5586b36a10a3d453.tar.xz ice-15063818726cf3d474d77d9d5586b36a10a3d453.zip |
ICE-6852 - allow OutputStream to marshal to user-supplied buffer
Diffstat (limited to 'cpp/src/IceDB')
-rw-r--r-- | cpp/src/IceDB/IceDB.h | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/cpp/src/IceDB/IceDB.h b/cpp/src/IceDB/IceDB.h index af9bd2206c0..d905f2bab22 100644 --- a/cpp/src/IceDB/IceDB.h +++ b/cpp/src/IceDB/IceDB.h @@ -515,19 +515,13 @@ struct Codec<T, IceContext, Ice::OutputStream> static bool write(const T& t, MDB_val& val, const IceContext& ctx) { - Ice::OutputStream stream(ctx.communicator, ctx.encoding); + const size_t limit = val.mv_size; + std::pair<Ice::Byte*, Ice::Byte*> p(reinterpret_cast<Ice::Byte*>(val.mv_data), + reinterpret_cast<Ice::Byte*>(val.mv_data) + limit); + Ice::OutputStream stream(ctx.communicator, ctx.encoding, p); stream.write(t); - if(stream.b.size() > val.mv_size) - { - val.mv_size = stream.b.size(); - return false; - } - else - { - val.mv_size = stream.b.size(); - memcpy(val.mv_data, &stream.b[0], stream.b.size()); - return true; - } + val.mv_size = stream.b.size(); + return stream.b.size() > limit ? false : true; } }; |