Use Cow's in TextComponent
We now don't always convert &str to Strings allowing us to use stack allocations
This commit is contained in:
1 parent
dfc0b8afe9
commit
a6d9ed216d
26 files changed
+134
-149
No files matched your search
@@ -7,7 +7,7 @@ use crate::{BitSet, ClientPacket, ServerPacket, VarInt, VarIntType};
|
||||
|
||||
use super::{deserializer, serializer, ByteBuffer, DeserializerError};
|
||||
|
||||
impl Serialize for BitSet<'static> {
|
||||
impl<'a> Serialize for BitSet<'a> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
|
||||
@@ -11,7 +11,7 @@ pub struct CConfigAddResourcePack<'a> {
|
||||
url: &'a str,
|
||||
hash: &'a str, // max 40
|
||||
forced: bool,
|
||||
prompt_message: Option<TextComponent>,
|
||||
prompt_message: Option<TextComponent<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> CConfigAddResourcePack<'a> {
|
||||
@@ -20,7 +20,7 @@ impl<'a> CConfigAddResourcePack<'a> {
|
||||
url: &'a str,
|
||||
hash: &'a str,
|
||||
forced: bool,
|
||||
prompt_message: Option<TextComponent>,
|
||||
prompt_message: Option<TextComponent<'a>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
uuid,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{bytebuf::ByteBuffer, ClientPacket};
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x01)]
|
||||
|
||||
@@ -4,12 +4,12 @@ use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x4C)]
|
||||
pub struct CActionBar {
|
||||
action_bar: TextComponent,
|
||||
pub struct CActionBar<'a> {
|
||||
action_bar: TextComponent<'a>,
|
||||
}
|
||||
|
||||
impl CActionBar {
|
||||
pub fn new(action_bar: TextComponent) -> Self {
|
||||
impl<'a> CActionBar<'a> {
|
||||
pub fn new(action_bar: TextComponent<'a>) -> Self {
|
||||
Self { action_bar }
|
||||
}
|
||||
}
|
||||
@@ -6,19 +6,19 @@ use crate::VarInt;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x1E)]
|
||||
pub struct CDisguisedChatMessage {
|
||||
message: TextComponent,
|
||||
pub struct CDisguisedChatMessage<'a> {
|
||||
message: TextComponent<'a>,
|
||||
chat_type: VarInt,
|
||||
sender_name: TextComponent,
|
||||
target_name: Option<TextComponent>,
|
||||
sender_name: TextComponent<'a>,
|
||||
target_name: Option<TextComponent<'a>>,
|
||||
}
|
||||
|
||||
impl CDisguisedChatMessage {
|
||||
impl<'a> CDisguisedChatMessage<'a> {
|
||||
pub fn new(
|
||||
message: TextComponent,
|
||||
message: TextComponent<'a>,
|
||||
chat_type: VarInt,
|
||||
sender_name: TextComponent,
|
||||
target_name: Option<TextComponent>,
|
||||
sender_name: TextComponent<'a>,
|
||||
target_name: Option<TextComponent<'a>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
message,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::VarInt;
|
||||
use crate::{position::WorldPosition, VarInt};
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x2B)]
|
||||
@@ -23,7 +23,7 @@ pub struct CLogin<'a> {
|
||||
previous_gamemode: i8,
|
||||
debug: bool,
|
||||
is_flat: bool,
|
||||
death_dimension_name: Option<(String, i64)>, // POSITION NOT STRING
|
||||
death_dimension_name: Option<(WorldPosition, i64)>,
|
||||
portal_cooldown: VarInt,
|
||||
enforce_secure_chat: bool,
|
||||
}
|
||||
@@ -47,7 +47,7 @@ impl<'a> CLogin<'a> {
|
||||
previous_gamemode: i8,
|
||||
debug: bool,
|
||||
is_flat: bool,
|
||||
death_dimension_name: Option<(String, i64)>,
|
||||
death_dimension_name: Option<(WorldPosition, i64)>,
|
||||
portal_cooldown: VarInt,
|
||||
enforce_secure_chat: bool,
|
||||
) -> Self {
|
||||
|
||||
@@ -6,14 +6,14 @@ use crate::VarInt;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x33)]
|
||||
pub struct COpenScreen {
|
||||
pub struct COpenScreen<'a> {
|
||||
window_id: VarInt,
|
||||
window_type: VarInt,
|
||||
window_title: TextComponent,
|
||||
window_title: TextComponent<'a>,
|
||||
}
|
||||
|
||||
impl COpenScreen {
|
||||
pub fn new(window_id: VarInt, window_type: VarInt, window_title: TextComponent) -> Self {
|
||||
impl<'a> COpenScreen<'a> {
|
||||
pub fn new(window_id: VarInt, window_type: VarInt, window_title: TextComponent<'a>) -> Self {
|
||||
Self {
|
||||
window_id,
|
||||
window_type,
|
||||
|
||||
@@ -4,12 +4,12 @@ use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x1D)]
|
||||
pub struct CPlayDisconnect {
|
||||
reason: TextComponent,
|
||||
pub struct CPlayDisconnect<'a> {
|
||||
reason: TextComponent<'a>,
|
||||
}
|
||||
|
||||
impl CPlayDisconnect {
|
||||
pub fn new(reason: TextComponent) -> Self {
|
||||
impl<'a> CPlayDisconnect<'a> {
|
||||
pub fn new(reason: TextComponent<'a>) -> Self {
|
||||
Self { reason }
|
||||
}
|
||||
}
|
||||
@@ -11,19 +11,18 @@ pub struct CPlayerChatMessage<'a> {
|
||||
sender: UUID,
|
||||
index: VarInt,
|
||||
message_signature: Option<&'a [u8]>,
|
||||
message: String,
|
||||
message: &'a str,
|
||||
timestamp: i64,
|
||||
salt: i64,
|
||||
previous_messages_count: VarInt,
|
||||
previous_messages: &'a [PreviousMessage<'a>], // max 20
|
||||
unsigned_content: Option<TextComponent>,
|
||||
unsigned_content: Option<TextComponent<'a>>,
|
||||
/// See `FilterType`
|
||||
filter_type: VarInt,
|
||||
// TODO: THIS IS A HACK, We currently don't support writing or reading bitsets
|
||||
filter_type_bits: bool,
|
||||
filter_type_bits: Option<BitSet<'a>>,
|
||||
chat_type: VarInt,
|
||||
sender_name: TextComponent,
|
||||
target_name: Option<TextComponent>,
|
||||
sender_name: TextComponent<'a>,
|
||||
target_name: Option<TextComponent<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> CPlayerChatMessage<'a> {
|
||||
@@ -32,15 +31,16 @@ impl<'a> CPlayerChatMessage<'a> {
|
||||
sender: UUID,
|
||||
index: VarInt,
|
||||
message_signature: Option<&'a [u8]>,
|
||||
message: String,
|
||||
message: &'a str,
|
||||
timestamp: i64,
|
||||
salt: i64,
|
||||
previous_messages: &'a [PreviousMessage<'a>],
|
||||
unsigned_content: Option<TextComponent>,
|
||||
unsigned_content: Option<TextComponent<'a>>,
|
||||
filter_type: VarInt,
|
||||
filter_type_bits: Option<BitSet<'a>>,
|
||||
chat_type: VarInt,
|
||||
sender_name: TextComponent,
|
||||
target_name: Option<TextComponent>,
|
||||
sender_name: TextComponent<'a>,
|
||||
target_name: Option<TextComponent<'a>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
sender,
|
||||
@@ -53,7 +53,7 @@ impl<'a> CPlayerChatMessage<'a> {
|
||||
previous_messages,
|
||||
unsigned_content,
|
||||
filter_type,
|
||||
filter_type_bits: false,
|
||||
filter_type_bits,
|
||||
chat_type,
|
||||
sender_name,
|
||||
target_name,
|
||||
|
||||
@@ -4,12 +4,12 @@ use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x65)]
|
||||
pub struct CTitleText {
|
||||
title: TextComponent,
|
||||
pub struct CTitleText<'a> {
|
||||
title: TextComponent<'a>,
|
||||
}
|
||||
|
||||
impl CTitleText {
|
||||
pub fn new(title: TextComponent) -> Self {
|
||||
impl<'a> CTitleText<'a> {
|
||||
pub fn new(title: TextComponent<'a>) -> Self {
|
||||
Self { title }
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,12 @@ use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x63)]
|
||||
pub struct CSubtitle {
|
||||
subtitle: TextComponent,
|
||||
pub struct CSubtitle<'a> {
|
||||
subtitle: TextComponent<'a>,
|
||||
}
|
||||
|
||||
impl CSubtitle {
|
||||
pub fn new(subtitle: TextComponent) -> Self {
|
||||
impl<'a> CSubtitle<'a> {
|
||||
pub fn new(subtitle: TextComponent<'a>) -> Self {
|
||||
Self { subtitle }
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,13 @@ use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x6C)]
|
||||
pub struct CSystemChatMessge {
|
||||
content: TextComponent,
|
||||
pub struct CSystemChatMessge<'a> {
|
||||
content: TextComponent<'a>,
|
||||
overlay: bool,
|
||||
}
|
||||
|
||||
impl CSystemChatMessge {
|
||||
pub fn new(content: TextComponent, overlay: bool) -> Self {
|
||||
impl<'a> CSystemChatMessge<'a> {
|
||||
pub fn new(content: TextComponent<'a>, overlay: bool) -> Self {
|
||||
Self { content, overlay }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
use bytebuf::{packet_id::Packet, ByteBuffer, DeserializerError};
|
||||
use bytes::Buf;
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::io::{self, Write};
|
||||
use thiserror::Error;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{ByteBuffer, DeserializerError},
|
||||
ServerPacket,
|
||||
ServerPacket, VarInt,
|
||||
};
|
||||
|
||||
// derive(Deserialize)]
|
||||
@@ -12,7 +12,7 @@ pub struct SChatMessage {
|
||||
pub timestamp: i64,
|
||||
pub salt: i64,
|
||||
pub signature: Option<Vec<u8>>,
|
||||
// pub messagee_count: VarInt,
|
||||
pub messagee_count: VarInt,
|
||||
// acknowledged: BitSet,
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ impl ServerPacket for SChatMessage {
|
||||
timestamp: bytebuf.get_i64(),
|
||||
salt: bytebuf.get_i64(),
|
||||
signature: bytebuf.get_option(|v| v.get_slice().to_vec()),
|
||||
//messagee_count: bytebuf.get_var_int(),
|
||||
messagee_count: bytebuf.get_var_int(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
use std::char::MAX;
|
||||
|
||||
use num_derive::FromPrimitive;
|
||||
use num_traits::FromPrimitive;
|
||||
|
||||
Reference in new issue
Block a user