2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-09-08 10:51:28 +03:00
|
|
|
#pragma once
|
|
|
|
|
2022-12-04 21:02:33 +03:00
|
|
|
#include <AK/DeprecatedString.h>
|
2019-09-08 10:51:28 +03:00
|
|
|
#include <AK/StringBuilder.h>
|
|
|
|
#include <AK/Types.h>
|
|
|
|
|
|
|
|
#define CMD_WILL 0xfb
|
|
|
|
#define CMD_WONT 0xfc
|
|
|
|
#define CMD_DO 0xfd
|
|
|
|
#define CMD_DONT 0xfe
|
|
|
|
#define SUB_ECHO 0x01
|
|
|
|
#define SUB_SUPPRESS_GO_AHEAD 0x03
|
|
|
|
|
|
|
|
struct Command {
|
|
|
|
u8 command;
|
|
|
|
u8 subcommand;
|
|
|
|
|
2022-12-06 04:12:49 +03:00
|
|
|
DeprecatedString to_deprecated_string() const
|
2019-09-08 10:51:28 +03:00
|
|
|
{
|
|
|
|
StringBuilder builder;
|
|
|
|
|
|
|
|
switch (command) {
|
|
|
|
case CMD_WILL:
|
2022-07-11 20:32:29 +03:00
|
|
|
builder.append("WILL"sv);
|
2019-09-08 10:51:28 +03:00
|
|
|
break;
|
|
|
|
case CMD_WONT:
|
2022-07-11 20:32:29 +03:00
|
|
|
builder.append("WONT"sv);
|
2019-09-08 10:51:28 +03:00
|
|
|
break;
|
|
|
|
case CMD_DO:
|
2022-07-11 20:32:29 +03:00
|
|
|
builder.append("DO"sv);
|
2019-09-08 10:51:28 +03:00
|
|
|
break;
|
|
|
|
case CMD_DONT:
|
2022-07-11 20:32:29 +03:00
|
|
|
builder.append("DONT"sv);
|
2019-09-08 10:51:28 +03:00
|
|
|
break;
|
|
|
|
default:
|
2022-12-04 21:02:33 +03:00
|
|
|
builder.append(DeprecatedString::formatted("UNKNOWN<{:02x}>", command));
|
2019-09-08 10:51:28 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-07-11 20:32:29 +03:00
|
|
|
builder.append(" "sv);
|
2019-09-08 10:51:28 +03:00
|
|
|
|
|
|
|
switch (subcommand) {
|
|
|
|
case SUB_ECHO:
|
2022-07-11 20:32:29 +03:00
|
|
|
builder.append("ECHO"sv);
|
2019-09-08 10:51:28 +03:00
|
|
|
break;
|
|
|
|
case SUB_SUPPRESS_GO_AHEAD:
|
2022-07-11 20:32:29 +03:00
|
|
|
builder.append("SUPPRESS_GO_AHEAD"sv);
|
2019-09-08 10:51:28 +03:00
|
|
|
break;
|
|
|
|
default:
|
2022-12-04 21:02:33 +03:00
|
|
|
builder.append(DeprecatedString::formatted("UNKNOWN<{:02x}>", subcommand));
|
2019-09-08 10:51:28 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-12-06 04:12:49 +03:00
|
|
|
return builder.to_deprecated_string();
|
2023-07-08 05:48:11 +03:00
|
|
|
}
|
2019-09-08 10:51:28 +03:00
|
|
|
};
|