0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 23:14:13 +01:00

modules: Reduce various chunked json buffer mgmt boilerplates.

This commit is contained in:
Jason Volk 2018-09-04 22:48:23 -07:00
parent 660bfcc03f
commit 4f2e1a4acd
9 changed files with 15 additions and 105 deletions

View file

@ -83,26 +83,14 @@ get__context(client &client,
event_id
};
const unique_buffer<mutable_buffer> buf
{
96_KiB
};
resource::response::chunked response
{
client, http::OK
};
const auto flush{[&response]
(const const_buffer &buf)
{
response.write(buf);
return buf;
}};
json::stack out
{
buf, flush, size_t(flush_hiwat)
response.buf, response.flusher(), size_t(flush_hiwat)
};
json::stack::object ret

View file

@ -96,22 +96,15 @@ get__messages(client &client,
room, page.from, &default_fetch_opts
};
const unique_buffer<mutable_buffer> buf
{
96_KiB
};
resource::response::chunked response
{
client, http::OK
};
json::stack out{buf, [&response]
(const const_buffer &buf)
json::stack out
{
response.write(buf);
return buf;
}};
response.buf, response.flusher()
};
json::stack::object ret
{

View file

@ -95,26 +95,14 @@ get__backfill(client &client,
room_id, event_id
};
const unique_buffer<mutable_buffer> buf
{
96_KiB
};
resource::response::chunked response
{
client, http::OK
};
const auto flush{[&response]
(const const_buffer &buf)
{
response.write(buf);
return buf;
}};
json::stack out
{
buf, flush, size_t(backfill_flush_hiwat)
response.buf, response.flusher(), size_t(backfill_flush_hiwat)
};
json::stack::object top{out};

View file

@ -96,22 +96,15 @@ get__backfill_ids(client &client,
room
};
const unique_buffer<mutable_buffer> buf
{
4_KiB
};
resource::response::chunked response
{
client, http::OK
};
json::stack out{buf, [&response]
(const const_buffer &buf)
json::stack out
{
response.write(buf);
return buf;
}};
response.buf, response.flusher()
};
json::stack::object top{out};
json::stack::member pdus_m

View file

@ -49,11 +49,6 @@ handle_get(client &client,
event_id
};
const unique_buffer<mutable_buffer> buf
{
96_KiB
};
resource::response::chunked response
{
client, http::OK
@ -61,11 +56,7 @@ handle_get(client &client,
json::stack out
{
buf, [&response](const const_buffer &buf)
{
response.write(buf);
return buf;
}
response.buf, response.flusher()
};
json::stack::object top{out};

View file

@ -80,26 +80,14 @@ get__event_auth(client &client,
room
};
const unique_buffer<mutable_buffer> buf
{
96_KiB
};
resource::response::chunked response
{
client, http::OK
};
const auto flush{[&response]
(const const_buffer &buf)
{
response.write(buf);
return buf;
}};
json::stack out
{
buf, flush, size_t(event_auth_flush_hiwat)
response.buf, response.flusher(), size_t(event_auth_flush_hiwat)
};
json::stack::object top{out};

View file

@ -108,26 +108,14 @@ get__missing_events(client &client,
});
}};
const unique_buffer<mutable_buffer> buf
{
96_KiB
};
resource::response::chunked response
{
client, http::OK
};
const auto flush{[&response]
(const const_buffer &buf)
{
response.write(buf);
return buf;
}};
json::stack out
{
buf, flush, size_t(flush_hiwat)
response.buf, response.flusher(), size_t(flush_hiwat)
};
json::stack::object top{out};

View file

@ -62,26 +62,14 @@ get__state(client &client,
room
};
const unique_buffer<mutable_buffer> buf
{
96_KiB
};
resource::response::chunked response
{
client, http::OK
};
const auto flush{[&response]
(const const_buffer &buf)
{
response.write(buf);
return buf;
}};
json::stack out
{
buf, flush, size_t(state_flush_hiwat)
response.buf, response.flusher(), size_t(state_flush_hiwat)
};
json::stack::object top{out};

View file

@ -55,22 +55,15 @@ get__state_ids(client &client,
room
};
const unique_buffer<mutable_buffer> buf
{
8_KiB
};
resource::response::chunked response
{
client, http::OK
};
json::stack out{buf, [&response]
(const const_buffer &buf)
json::stack out
{
response.write(buf);
return buf;
}};
response.buf, response.flusher()
};
json::stack::object top{out};
json::stack::member pdus_m