37 lines
1.1 KiB
C++
37 lines
1.1 KiB
C++
#pragma once
|
|
|
|
// TS3 command wire format: "commandname key=value key=value|key=value".
|
|
// Ported from ts6-manager tslib/commands.ts.
|
|
|
|
#include <map>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace Echoion::Protocol
|
|
{
|
|
|
|
// Escape / unescape a single token per the TS3 rules
|
|
// (\\ \/ \s \p \f \n \r \t \v).
|
|
std::string tsEscape(const std::string& str);
|
|
std::string tsUnescape(const std::string& str);
|
|
|
|
// Ordered key/value params for a command. std::map keeps a stable order so
|
|
// serialization is deterministic (helpful for tests); the server does not
|
|
// care about ordering.
|
|
using CommandParams = std::map<std::string, std::string>;
|
|
|
|
struct ParsedCommand {
|
|
std::string name;
|
|
CommandParams params; // first group
|
|
std::vector<CommandParams> groups; // all '|'-separated groups
|
|
};
|
|
|
|
// Serialize "name k=v k=v". Empty values are emitted as "k=".
|
|
std::string buildCommand(const std::string& name,
|
|
const CommandParams& params);
|
|
|
|
// Parse a raw command / notify line into name + params (+ pipe groups).
|
|
ParsedCommand parseCommand(const std::string& raw);
|
|
|
|
} // namespace Echoion::Protocol
|