[protocol] Packets now use std::string_view
This commit is contained in:
parent
1e2e6da787
commit
a2ac2531bb
|
@ -110,7 +110,7 @@ namespace Feather
|
||||||
{
|
{
|
||||||
Log::Info("Client Intention Packet: version={}, serverIp={}, port={}, intention={}\n",
|
Log::Info("Client Intention Packet: version={}, serverIp={}, port={}, intention={}\n",
|
||||||
handshake.protocolVersion,
|
handshake.protocolVersion,
|
||||||
handshake.serverIP.c_str(),
|
handshake.serverIP.data(),
|
||||||
handshake.port,
|
handshake.port,
|
||||||
handshake.intention
|
handshake.intention
|
||||||
);
|
);
|
||||||
|
@ -154,7 +154,8 @@ namespace Feather
|
||||||
// .uuid = { 4658857991808325907ull, 7518717155607718277ull },
|
// .uuid = { 4658857991808325907ull, 7518717155607718277ull },
|
||||||
// .username = start.username
|
// .username = start.username
|
||||||
//};
|
//};
|
||||||
client.SetUsername(start.username);
|
// TODO: This is copying...
|
||||||
|
client.SetUsername(std::string(start.username));
|
||||||
|
|
||||||
std::string uuid = "ecb99913-96a8-40a7-8529-a2ca6ad95768";
|
std::string uuid = "ecb99913-96a8-40a7-8529-a2ca6ad95768";
|
||||||
Login::ClientboundSuccess success =
|
Login::ClientboundSuccess success =
|
||||||
|
|
|
@ -74,11 +74,18 @@ namespace Feather
|
||||||
WriteData(string, stringSize);
|
WriteData(string, stringSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write string using std::string reference
|
||||||
inline void WriteString(const std::string& string)
|
inline void WriteString(const std::string& string)
|
||||||
{
|
{
|
||||||
WriteString(string.c_str(), string.length());
|
WriteString(string.c_str(), string.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write string using string_view
|
||||||
|
inline void WriteString(std::string_view view)
|
||||||
|
{
|
||||||
|
WriteString(view.data(), view.size());
|
||||||
|
}
|
||||||
|
|
||||||
inline void WritePosition(BlockPos pos)
|
inline void WritePosition(BlockPos pos)
|
||||||
{
|
{
|
||||||
Write<int64_t>(pos.Encode());
|
Write<int64_t>(pos.Encode());
|
||||||
|
|
|
@ -92,6 +92,7 @@ namespace Feather
|
||||||
return static_cast<T>(result);
|
return static_cast<T>(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// can be assigned to string&, string_view
|
||||||
string ReadString()
|
string ReadString()
|
||||||
{
|
{
|
||||||
int size = ReadVarInt();
|
int size = ReadVarInt();
|
||||||
|
|
|
@ -299,10 +299,7 @@ def print_definition(types, name, value, serverbound):
|
||||||
add_text('}} {};', resolved_name)
|
add_text('}} {};', resolved_name)
|
||||||
else:
|
else:
|
||||||
resolved_type = resolve_type(types, value)
|
resolved_type = resolve_type(types, value)
|
||||||
if not serverbound and resolved_type == 'std::string':
|
add_text('{} {};', resolved_type, resolved_name)
|
||||||
add_text('const {}& {};', resolved_type, resolved_name)
|
|
||||||
else:
|
|
||||||
add_text('{} {};', resolved_type, resolved_name)
|
|
||||||
|
|
||||||
|
|
||||||
def get_enum_type(dict, fallback = 'int32'):
|
def get_enum_type(dict, fallback = 'int32'):
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
string: {
|
string: {
|
||||||
type: std::string
|
type: std::string_view
|
||||||
method: String
|
method: String
|
||||||
// requires count: e.g. string[256]
|
// requires count: e.g. string[256]
|
||||||
// generated C type will not be an array
|
// generated C type will not be an array
|
||||||
|
|
Loading…
Reference in New Issue