parselink-old/include/parselink/proto/session.h
2023-10-19 23:56:22 -07:00

72 lines
1.9 KiB
C++

//-----------------------------------------------------------------------------
// ___ __ _ _
// / _ \__ _ _ __ ___ ___ / /(_)_ __ | | __
// / /_)/ _` | '__/ __|/ _ \/ / | | '_ \| |/ /
// / ___/ (_| | | \__ \ __/ /__| | | | | <
// \/ \__,_|_| |___/\___\____/_|_| |_|_|\_\ .
//
//-----------------------------------------------------------------------------
// Author: Kurt Sassenrath
// Module: Proto
//
// Session management for the "user" protocol.
//
// Copyright (c) 2023 Kurt Sassenrath.
//
// License TBD.
//-----------------------------------------------------------------------------
#ifndef session_07eae057feface79
#define session_07eae057feface79
#include <tl/expected.hpp>
#include "parselink/msgpack/token.h"
#include <cstdint>
#include <span>
#include <string>
namespace parselink {
namespace proto {
enum class error {
system_error,
incomplete,
unsupported,
bad_data,
too_large,
};
// Structure containing header information parsed from a buffer.
struct header_info {
std::uint32_t message_size; // Size of the message, minus the header.
std::uint32_t bytes_read; // How many bytes of the buffer were used.
};
class session {
public:
session() = default;
// Parse the protocol header out of a buffer. This is a member function
// as we may choose to omit data once a session is established.
tl::expected<header_info, error> parse_header(
std::span<std::byte const> buffer) noexcept;
tl::expected<std::monostate, error> handle_connect(
std::span<msgpack::token> tokens) noexcept;
// The maximum size of a single message. Should probably depend on whether
// the session is established or not.
constexpr static std::uint32_t max_message_size = 128 * 1024;
std::string user_id;
private:
};
} // namespace proto
} // namespace parselink
#endif // session_0c61530748b9f966