[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",
|
||||
handshake.protocolVersion,
|
||||
handshake.serverIP.c_str(),
|
||||
handshake.serverIP.data(),
|
||||
handshake.port,
|
||||
handshake.intention
|
||||
);
|
||||
|
@ -154,7 +154,8 @@ namespace Feather
|
|||
// .uuid = { 4658857991808325907ull, 7518717155607718277ull },
|
||||
// .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";
|
||||
Login::ClientboundSuccess success =
|
||||
|
|
|
@ -74,11 +74,18 @@ namespace Feather
|
|||
WriteData(string, stringSize);
|
||||
}
|
||||
|
||||
// Write string using std::string reference
|
||||
inline void WriteString(const std::string& string)
|
||||
{
|
||||
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)
|
||||
{
|
||||
Write<int64_t>(pos.Encode());
|
||||
|
|
|
@ -92,6 +92,7 @@ namespace Feather
|
|||
return static_cast<T>(result);
|
||||
}
|
||||
|
||||
// can be assigned to string&, string_view
|
||||
string ReadString()
|
||||
{
|
||||
int size = ReadVarInt();
|
||||
|
|
|
@ -299,9 +299,6 @@ def print_definition(types, name, value, serverbound):
|
|||
add_text('}} {};', resolved_name)
|
||||
else:
|
||||
resolved_type = resolve_type(types, value)
|
||||
if not serverbound and resolved_type == 'std::string':
|
||||
add_text('const {}& {};', resolved_type, resolved_name)
|
||||
else:
|
||||
add_text('{} {};', resolved_type, resolved_name)
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
}
|
||||
|
||||
string: {
|
||||
type: std::string
|
||||
type: std::string_view
|
||||
method: String
|
||||
// requires count: e.g. string[256]
|
||||
// generated C type will not be an array
|
||||
|
|
Loading…
Reference in New Issue