aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/src
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/epee/src')
-rw-r--r--contrib/epee/src/CMakeLists.txt2
-rw-r--r--contrib/epee/src/byte_stream.cpp11
-rw-r--r--contrib/epee/src/portable_storage.cpp29
3 files changed, 37 insertions, 5 deletions
diff --git a/contrib/epee/src/CMakeLists.txt b/contrib/epee/src/CMakeLists.txt
index 8adf69162..5e101a86a 100644
--- a/contrib/epee/src/CMakeLists.txt
+++ b/contrib/epee/src/CMakeLists.txt
@@ -29,7 +29,7 @@
add_library(epee STATIC byte_slice.cpp byte_stream.cpp hex.cpp abstract_http_client.cpp http_auth.cpp mlog.cpp net_helper.cpp net_utils_base.cpp string_tools.cpp
wipeable_string.cpp levin_base.cpp memwipe.c connection_basic.cpp network_throttle.cpp network_throttle-detail.cpp mlocker.cpp buffer.cpp net_ssl.cpp
- int-util.cpp)
+ int-util.cpp portable_storage.cpp)
if (USE_READLINE AND (GNU_READLINE_FOUND OR (DEPENDS AND NOT MINGW)))
add_library(epee_readline STATIC readline_buffer.cpp)
diff --git a/contrib/epee/src/byte_stream.cpp b/contrib/epee/src/byte_stream.cpp
index e87d9f0bc..73bba92f2 100644
--- a/contrib/epee/src/byte_stream.cpp
+++ b/contrib/epee/src/byte_stream.cpp
@@ -34,6 +34,11 @@
#include <iostream>
+namespace
+{
+ constexpr const std::size_t minimum_increase = 4096;
+}
+
namespace epee
{
void byte_stream::overflow(const std::size_t requested)
@@ -46,7 +51,7 @@ namespace epee
const std::size_t len = size();
const std::size_t cap = capacity();
- const std::size_t increase = std::max(need, increase_size());
+ const std::size_t increase = std::max(std::max(need, cap), minimum_increase);
next_write_ = nullptr;
end_ = nullptr;
@@ -62,8 +67,7 @@ namespace epee
byte_stream::byte_stream(byte_stream&& rhs) noexcept
: buffer_(std::move(rhs.buffer_)),
next_write_(rhs.next_write_),
- end_(rhs.end_),
- increase_size_(rhs.increase_size_)
+ end_(rhs.end_)
{
rhs.next_write_ = nullptr;
rhs.end_ = nullptr;
@@ -76,7 +80,6 @@ namespace epee
buffer_ = std::move(rhs.buffer_);
next_write_ = rhs.next_write_;
end_ = rhs.end_;
- increase_size_ = rhs.increase_size_;
rhs.next_write_ = nullptr;
rhs.end_ = nullptr;
}
diff --git a/contrib/epee/src/portable_storage.cpp b/contrib/epee/src/portable_storage.cpp
new file mode 100644
index 000000000..4534deff3
--- /dev/null
+++ b/contrib/epee/src/portable_storage.cpp
@@ -0,0 +1,29 @@
+
+#include "byte_slice.h"
+#include "byte_stream.h"
+#include "misc_log_ex.h"
+#include "span.h"
+#include "storages/portable_storage.h"
+#include "storages/portable_storage_to_bin.h"
+
+namespace epee
+{
+namespace serialization
+{
+ bool portable_storage::store_to_binary(byte_slice& target, const std::size_t initial_buffer_size)
+ {
+ TRY_ENTRY();
+ byte_stream ss;
+ ss.reserve(initial_buffer_size);
+ storage_block_header sbh{};
+ sbh.m_signature_a = SWAP32LE(PORTABLE_STORAGE_SIGNATUREA);
+ sbh.m_signature_b = SWAP32LE(PORTABLE_STORAGE_SIGNATUREB);
+ sbh.m_ver = PORTABLE_STORAGE_FORMAT_VER;
+ ss.write(epee::as_byte_span(sbh));
+ pack_entry_to_buff(ss, m_root);
+ target = epee::byte_slice{std::move(ss)};
+ return true;
+ CATCH_ENTRY("portable_storage::store_to_binary", false)
+ }
+}
+}