idl: allow fragmented bytes_view in serialisation

This patch adds new way of serialising bytes and sstring objects in the
IDL. Using write_fragmented_<field-name>() the caller can pass a range
of fragments that would be serialised without linearising the buffer.
This commit is contained in:
Paweł Dziepak
2018-03-22 17:18:58 +00:00
parent c41b9fc7ec
commit 5845d52632
2 changed files with 18 additions and 1 deletions

View File

@@ -418,12 +418,14 @@ def add_param_writer_basic_type(name, base_state, typ, var_type = "", var_index
set_command = ("_state.f.end(_out);" if not root_node else "state.f.end(_out);") if var_type is not "" else ""
return_command = "{ _out, std::move(_state._parent) }" if var_type is not "" and not root_node else "{ _out, std::move(_state) }"
allow_fragmented = False
if typ in ['bytes', 'sstring']:
typ += '_view'
allow_fragmented = True
else:
typ = 'const ' + typ + '&'
return Template(reindent(4, """
writer = Template(reindent(4, """
after_${base_state}__$name<Output> write_$name$var_type($typ t) && {
$create_variant_state
$set_varient_index
@@ -431,6 +433,20 @@ def add_param_writer_basic_type(name, base_state, typ, var_type = "", var_index
$set_command
return $return_command;
}""")).substitute(locals())
if allow_fragmented:
writer += Template(reindent(4, """
template<typename FragmentedBuffer>
GCC6_CONCEPT(requires FragmentRange<FragmentedBuffer>)
after_${base_state}__$name<Output> write_fragmented_$name$var_type(FragmentedBuffer&& fragments) && {
$set_varient_index
using boost::range::for_each;
for_each(fragments, [&] ($typ t) {
serialize(_out, t);
});
$set_command
return $return_command;
}""")).substitute(locals())
return writer
def add_param_writer_object(name, base_state, typ, var_type = "", var_index = None, root_node = False):
var_type1 = "_" + var_type if var_type != "" else ""

View File

@@ -32,6 +32,7 @@
#include "boost/variant/variant.hpp"
#include "bytes_ostream.hh"
#include "utils/input_stream.hh"
#include "utils/fragment_range.hh"
namespace ser {
using size_type = uint32_t;