mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd:Ⓜ️:v1: Simplify the buffer partition pattern.
This commit is contained in:
parent
0d42bf62f5
commit
74b7dddb9a
1 changed files with 24 additions and 89 deletions
113
ircd/m/v1.cc
113
ircd/m/v1.cc
|
@ -48,19 +48,14 @@ ircd::m::v1::groups::publicised::publicised(const id::node &node,
|
|||
});
|
||||
|
||||
// (front of buf was advanced by stringify)
|
||||
opts.out.head = opts.request(buf);
|
||||
opts.out.content = json::get<"content"_>(opts.request);
|
||||
opts.out.head = opts.request(buf);
|
||||
|
||||
if(!size(opts.in))
|
||||
{
|
||||
const auto in_max
|
||||
{
|
||||
std::max(ssize_t(size(buf) - size(opts.out.head)), ssize_t(0))
|
||||
};
|
||||
|
||||
assert(in_max >= ssize_t(size(buf) / 2));
|
||||
opts.in.head = { data(buf) + size(opts.out.head), size_t(in_max) };
|
||||
opts.in.content = opts.in.head;
|
||||
consume(buf, size(opts.out.head));
|
||||
opts.in.head = buf;
|
||||
opts.in.content = opts.in.head; // server::request will auto partition
|
||||
}
|
||||
|
||||
return server::request
|
||||
|
@ -128,14 +123,8 @@ ircd::m::v1::send::send(const string_view &txnid,
|
|||
|
||||
if(!size(opts.in))
|
||||
{
|
||||
const auto in_max
|
||||
{
|
||||
std::max(ssize_t(size(buf) - size(opts.out.head)), ssize_t(0))
|
||||
};
|
||||
|
||||
assert(in_max >= ssize_t(size(buf) / 2));
|
||||
opts.in.head = { data(buf) + size(opts.out.head), size_t(in_max) };
|
||||
opts.in.content = opts.in.head;
|
||||
opts.in.head = buf + size(opts.out.head);
|
||||
opts.in.content = opts.in.head; // server::request will auto partition
|
||||
}
|
||||
|
||||
return server::request
|
||||
|
@ -207,14 +196,8 @@ ircd::m::v1::backfill::backfill(const room::id &room_id,
|
|||
|
||||
if(!size(opts.in))
|
||||
{
|
||||
const auto in_max
|
||||
{
|
||||
std::max(ssize_t(size(buf) - size(opts.out.head)), ssize_t(0))
|
||||
};
|
||||
|
||||
assert(in_max >= ssize_t(size(buf) / 2));
|
||||
opts.in.head = { data(buf) + size(opts.out.head), size_t(in_max) };
|
||||
opts.in.content = mutable_buffer{};
|
||||
opts.in.head = buf + size(opts.out.head);
|
||||
opts.in.content = opts.in.head; // server::request will auto partition
|
||||
}
|
||||
|
||||
return server::request
|
||||
|
@ -286,14 +269,8 @@ ircd::m::v1::state::state(const room::id &room_id,
|
|||
|
||||
if(!size(opts.in))
|
||||
{
|
||||
const auto in_max
|
||||
{
|
||||
std::max(ssize_t(size(buf) - size(opts.out.head)), ssize_t(0))
|
||||
};
|
||||
|
||||
assert(in_max >= ssize_t(size(buf) / 2));
|
||||
opts.in.head = { data(buf) + size(opts.out.head), size_t(in_max) };
|
||||
opts.in.content = mutable_buffer{};
|
||||
opts.in.head = buf + size(opts.out.head);
|
||||
opts.in.content = opts.in.head; // server::request will auto partition
|
||||
}
|
||||
|
||||
return server::request
|
||||
|
@ -353,14 +330,8 @@ ircd::m::v1::event::event(const m::event::id &event_id,
|
|||
|
||||
if(!size(opts.in))
|
||||
{
|
||||
const auto in_max
|
||||
{
|
||||
std::max(ssize_t(size(buf) - size(opts.out.head)), ssize_t(0))
|
||||
};
|
||||
|
||||
assert(in_max >= ssize_t(size(buf) / 2));
|
||||
opts.in.head = { data(buf) + size(opts.out.head), size_t(in_max) };
|
||||
opts.in.content = opts.in.head;
|
||||
opts.in.head = buf + size(opts.out.head);
|
||||
opts.in.content = opts.in.head; // server::request will auto partition
|
||||
}
|
||||
|
||||
return server::request
|
||||
|
@ -413,14 +384,8 @@ ircd::m::v1::invite::invite(const room::id &room_id,
|
|||
|
||||
if(!size(opts.in))
|
||||
{
|
||||
const auto in_max
|
||||
{
|
||||
std::max(ssize_t(size(buf) - size(opts.out.head)), ssize_t(0))
|
||||
};
|
||||
|
||||
assert(in_max >= ssize_t(size(buf) / 2));
|
||||
opts.in.head = { data(buf) + size(opts.out.head), size_t(in_max) };
|
||||
opts.in.content = mutable_buffer{};
|
||||
opts.in.head = buf + size(opts.out.head);
|
||||
opts.in.content = opts.in.head; // server::request will auto partition
|
||||
}
|
||||
|
||||
return server::request
|
||||
|
@ -473,14 +438,8 @@ ircd::m::v1::send_join::send_join(const room::id &room_id,
|
|||
|
||||
if(!size(opts.in))
|
||||
{
|
||||
const auto in_max
|
||||
{
|
||||
std::max(ssize_t(size(buf) - size(opts.out.head)), ssize_t(0))
|
||||
};
|
||||
|
||||
assert(in_max >= ssize_t(size(buf) / 2));
|
||||
opts.in.head = { data(buf) + size(opts.out.head), size_t(in_max) };
|
||||
opts.in.content = mutable_buffer{};
|
||||
opts.in.head = buf + size(opts.out.head);
|
||||
opts.in.content = opts.in.head; // server::request will auto partition
|
||||
}
|
||||
|
||||
return server::request
|
||||
|
@ -543,14 +502,8 @@ ircd::m::v1::make_join::make_join(const room::id &room_id,
|
|||
|
||||
if(!size(opts.in))
|
||||
{
|
||||
const auto in_max
|
||||
{
|
||||
std::max(ssize_t(size(buf) - size(opts.out.head)), ssize_t(0))
|
||||
};
|
||||
|
||||
assert(in_max >= ssize_t(size(buf) / 2));
|
||||
opts.in.head = { data(buf) + size(opts.out.head), size_t(in_max) };
|
||||
opts.in.content = opts.in.head;
|
||||
opts.in.head = buf + size(opts.out.head);
|
||||
opts.in.content = opts.in.head; // server::request will auto partition
|
||||
}
|
||||
|
||||
return server::request
|
||||
|
@ -600,14 +553,8 @@ ircd::m::v1::user::devices::devices(const id::user &user_id,
|
|||
|
||||
if(!size(opts.in))
|
||||
{
|
||||
const auto in_max
|
||||
{
|
||||
std::max(ssize_t(size(buf) - size(opts.out.head)), ssize_t(0))
|
||||
};
|
||||
|
||||
assert(in_max >= ssize_t(size(buf) / 2));
|
||||
opts.in.head = { data(buf) + size(opts.out.head), size_t(in_max) };
|
||||
opts.in.content = opts.in.head;
|
||||
opts.in.head = buf + size(opts.out.head);
|
||||
opts.in.content = opts.in.head; // server::request will auto partition
|
||||
}
|
||||
|
||||
return server::request
|
||||
|
@ -814,14 +761,8 @@ ircd::m::v1::query::query(const string_view &type,
|
|||
|
||||
if(!size(opts.in))
|
||||
{
|
||||
const auto in_max
|
||||
{
|
||||
std::max(ssize_t(size(buf) - size(opts.out.head)), ssize_t(0))
|
||||
};
|
||||
|
||||
assert(in_max >= ssize_t(size(buf) / 2));
|
||||
opts.in.head = { data(buf) + size(opts.out.head), size_t(in_max) };
|
||||
opts.in.content = opts.in.head;
|
||||
opts.in.head = buf + size(opts.out.head);
|
||||
opts.in.content = opts.in.head; // server::request will auto partition
|
||||
}
|
||||
|
||||
return server::request
|
||||
|
@ -857,14 +798,8 @@ ircd::m::v1::version::version(const mutable_buffer &buf,
|
|||
|
||||
if(!size(opts.in))
|
||||
{
|
||||
const auto in_max
|
||||
{
|
||||
std::max(ssize_t(size(buf) - size(opts.out.head)), ssize_t(0))
|
||||
};
|
||||
|
||||
assert(in_max >= ssize_t(size(buf) / 2));
|
||||
opts.in.head = { data(buf) + size(opts.out.head), size_t(in_max) };
|
||||
opts.in.content = opts.in.head;
|
||||
opts.in.head = buf + size(opts.out.head);
|
||||
opts.in.content = opts.in.head; // server::request will auto partition
|
||||
}
|
||||
|
||||
return server::request
|
||||
|
|
Loading…
Reference in a new issue