Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
msgpack_impl.hpp
Go to the documentation of this file.
1#pragma once
2// Meant to be the main header included by *.cpp files* that use msgpack.
3// Note: heavy header due to serialization logic, don't include if msgpack.hpp will do
4
5#include <cstring>
6
8
16
25 uint8_t* scratch_buf = nullptr,
26 size_t scratch_size = 0)
27{
28 // Create a buffer to store the encoded data
29 msgpack::sbuffer buffer;
30 msgpack::pack(buffer, obj);
31
32 // If scratch buffer provided and result fits, use it
33 if (scratch_buf != nullptr && buffer.size() <= scratch_size) {
34 memcpy(scratch_buf, buffer.data(), buffer.size());
35 return { scratch_buf, buffer.size() };
36 }
37
38 // Otherwise allocate new buffer
39 uint8_t* output = static_cast<uint8_t*>(aligned_alloc(64, buffer.size()));
40 memcpy(output, buffer.data(), buffer.size());
41 return { output, buffer.size() };
42}
std::unique_ptr< uint8_t[]> buffer
Definition engine.cpp:60
std::pair< uint8_t *, size_t > msgpack_encode_buffer(auto &&obj, uint8_t *scratch_buf=nullptr, size_t scratch_size=0)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13