parselink-old/include/parselink/proto/message.h
Kurt Sassenrath b2a6f25306 Start proto::parser, remove msgpack::reader
- proto::parser will likely contain helper functions for parsing
  messages from a buffer, for now it will explicitly define message
  parsers for each available message. It also leverages the new unpacker
  API, which has type safety in mind. These messages should not be
  unstructured, so it doesn't make sense to use the token API.
2024-01-12 19:36:56 -08:00

79 lines
2.4 KiB
C++

//-----------------------------------------------------------------------------
// ___ __ _ _
// / _ \__ _ _ __ ___ ___ / /(_)_ __ | | __
// / /_)/ _` | '__/ __|/ _ \/ / | | '_ \| |/ /
// / ___/ (_| | | \__ \ __/ /__| | | | | <
// \/ \__,_|_| |___/\___\____/_|_| |_|_|\_\ .
//
//-----------------------------------------------------------------------------
// Author: Kurt Sassenrath
// Module: Proto
//
// Message type definitions for the parselink protocol.
//
// Copyright (c) 2023 Kurt Sassenrath.
//
// License TBD.
//-----------------------------------------------------------------------------
#ifndef message_0c61530748b9f966
#define message_0c61530748b9f966
#include <cstdint>
#include <span>
#include <string_view>
namespace parselink {
namespace proto {
// Parselink messages are encoded with MessagePack and take the form of:
// | magic | size | content |
// - [magic] is the string "prs", in "fixstr" format.
// - [size] is the size of the message, not including this header.
// - [content] is [size] bytes of MessagePack data, including the
// specific type of message presented.
// This may be revised in the future. The header could remain as msgpack, or
// switch to something hand-crafted for saving bits.
struct base_message {};
template <typename T>
concept message_type = std::is_base_of_v<base_message, T>;
struct error_message : base_message {
std::uint32_t code; // An error code
std::string_view what; // A string
};
// C->S: Request to (re)connect.
struct connect_message : base_message {
std::uint32_t version; // The version of the client.
std::string_view user_id; // The user id.
std::span<std::byte> session_token; // An optional existing session token.
};
// S->C: Challenge to authenticate client as user_id
struct challenge_message : base_message {
std::uint32_t version;
std::span<std::byte> challenge;
};
// C->S: Calculated response to a challenge.
struct response_message : base_message {
std::span<std::byte> response;
};
// S->C: Session token.
struct session_established_message : base_message {
std::span<std::byte> session_token;
};
struct parser_data_message : base_message {
std::string_view opts;
std::span<std::byte> payload;
};
} // namespace proto
} // namespace parselink
#endif // message_0c61530748b9f966