WIP slight changes to token_reader
This commit is contained in:
parent
21b388f0d0
commit
915773f3a8
@ -15,6 +15,14 @@ cc_library(
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "proto",
|
||||
hdrs = glob(["proto/**/*.h"]),
|
||||
includes = ["."],
|
||||
deps = ["//include:path"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "utility",
|
||||
hdrs = glob(["utility/**/*.h"]),
|
||||
|
||||
@ -60,6 +60,21 @@ constexpr inline decltype(auto) make_token(auto bytes) {
|
||||
|
||||
// Define in token/type.h instead? Avoid instantiations in the core API.
|
||||
constexpr inline format::traits const& traits_lookup(std::byte id) {
|
||||
// Check for fix formats first.
|
||||
if ((id & ~format::negative_fixint::mask)
|
||||
== format::negative_fixint::marker) {
|
||||
return format::get_traits<format::negative_fixint>();
|
||||
} else if ((id & ~format::positive_fixint::mask)
|
||||
== format::positive_fixint::marker) {
|
||||
return format::get_traits<format::positive_fixint>();
|
||||
} else if ((id & ~format::fixstr::mask) == format::fixstr::marker) {
|
||||
return format::get_traits<format::fixstr>();
|
||||
} else if ((id & ~format::fixmap::mask) == format::fixmap::marker) {
|
||||
return format::get_traits<format::fixmap>();
|
||||
} else if ((id & ~format::fixarray::mask) == format::fixarray::marker) {
|
||||
return format::get_traits<format::fixarray>();
|
||||
}
|
||||
|
||||
switch (id) {
|
||||
case format::uint8::marker:
|
||||
return format::get_traits<format::uint8>();
|
||||
@ -113,23 +128,6 @@ constexpr inline format::traits const& traits_lookup(std::byte id) {
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO(ksassenrath): Handle fixtype formats.
|
||||
if ((id & ~format::negative_fixint::mask) == format::negative_fixint::marker) {
|
||||
return format::get_traits<format::negative_fixint>();
|
||||
}
|
||||
if ((id & ~format::positive_fixint::mask) == format::positive_fixint::marker) {
|
||||
return format::get_traits<format::positive_fixint>();
|
||||
}
|
||||
if ((id & ~format::fixstr::mask) == format::fixstr::marker) {
|
||||
return format::get_traits<format::fixstr>();
|
||||
}
|
||||
if ((id & ~format::fixmap::mask) == format::fixmap::marker) {
|
||||
return format::get_traits<format::fixmap>();
|
||||
}
|
||||
if ((id & ~format::fixarray::mask) == format::fixarray::marker) {
|
||||
return format::get_traits<format::fixarray>();
|
||||
}
|
||||
|
||||
return format::no_traits;
|
||||
}
|
||||
|
||||
@ -139,15 +137,19 @@ class token_reader {
|
||||
public:
|
||||
|
||||
constexpr token_reader(std::span<std::byte const> src) noexcept :
|
||||
data_(src), curr_{src.begin()}, end_(src.end()) {}
|
||||
data_(src), curr_{} {}
|
||||
|
||||
constexpr auto current() const noexcept {
|
||||
return std::next(data_.begin(), curr_);
|
||||
}
|
||||
|
||||
constexpr auto remaining(auto itr) noexcept {
|
||||
using dist_type = decltype(std::distance(itr, end_));
|
||||
return std::max(dist_type(0), std::distance(itr, end_));
|
||||
using dist_type = decltype(std::distance(itr, data_.end()));
|
||||
return std::max(dist_type(0), std::distance(itr, data_.end()));
|
||||
}
|
||||
|
||||
constexpr auto remaining() noexcept {
|
||||
return remaining(curr_);
|
||||
return remaining(current());
|
||||
}
|
||||
|
||||
// Read the next token. If the reader currently points to the end of the
|
||||
@ -156,12 +158,12 @@ public:
|
||||
// potentially hinting that further buffering is required.
|
||||
constexpr tl::expected<token, error> read_one() noexcept {
|
||||
token tok;
|
||||
if (curr_ >= end_) {
|
||||
if (remaining() == 0) {
|
||||
return tl::make_unexpected(error::end_of_message);
|
||||
}
|
||||
|
||||
// curr_ will be updated after everything succeeds.
|
||||
auto curr = curr_;
|
||||
auto curr = current();
|
||||
std::size_t var_size = 0;
|
||||
auto id = *curr++;
|
||||
auto const& traits = detail::traits_lookup(id);
|
||||
@ -240,7 +242,7 @@ public:
|
||||
return tl::make_unexpected(error::not_implemented);
|
||||
}
|
||||
|
||||
curr_ = curr;
|
||||
curr_ = std::distance(data_.begin(), curr);
|
||||
return {tok};
|
||||
}
|
||||
|
||||
@ -278,10 +280,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::span<std::byte const> data_;
|
||||
decltype(data_)::iterator curr_;
|
||||
decltype(data_)::iterator end_;
|
||||
decltype(data_)::iterator::difference_type curr_;
|
||||
};
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
@ -15,8 +15,9 @@ cc_binary(
|
||||
deps = [
|
||||
"headers",
|
||||
"//include/parselink:msgpack",
|
||||
"//source/logging",
|
||||
"//include/parselink:proto",
|
||||
"//include/parselink:utility",
|
||||
"//source/logging",
|
||||
"@boost//:beast",
|
||||
],
|
||||
)
|
||||
|
||||
@ -21,6 +21,8 @@
|
||||
#include "parselink/logging.h"
|
||||
#include "parselink/server.h"
|
||||
|
||||
#include "parselink/proto/message.h"
|
||||
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/signal_set.hpp>
|
||||
#include <boost/asio/redirect_error.hpp>
|
||||
@ -151,7 +153,7 @@ monolithic_server::monolithic_server(std::string_view address,
|
||||
, user_port_{user_port}
|
||||
, websocket_port_{websocket_port} {
|
||||
logger.debug("Creating monolithic_server(address = {}, user_port = {}, "
|
||||
"websocket_port = {})", address, user_port_, websocket_port_);
|
||||
"websocket_port = {}, sizeof(message) = {})", address, user_port_, websocket_port_, sizeof(proto::message));
|
||||
}
|
||||
|
||||
awaitable<void> monolithic_server::user_listen() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user