aboutsummaryrefslogtreecommitdiff
path: root/azalea-chat/src/component.rs
diff options
context:
space:
mode:
authorEightFactorial <murphkev000@gmail.com>2022-12-03 17:08:05 -0800
committerGitHub <noreply@github.com>2022-12-03 19:08:05 -0600
commit3b93fc641250c4d01ab7f0764b7d5faec2f8ae5b (patch)
tree727b94c9f90bba59f8571ecebeab1a33e0f4af07 /azalea-chat/src/component.rs
parent661c3622bebc111a1523bc80792dc90d9d571b24 (diff)
downloadazalea-drasl-3b93fc641250c4d01ab7f0764b7d5faec2f8ae5b.tar.xz
Serialize Component (#47)
* Serializing ClientboundStatusResponsePacket Enable serialization of ClientboundStatusResponsePacket * Update clientbound_status_response_packet.rs Add options previewsChat and enforcesSecureChat * Serialize Style and TextColor * Serialize BaseComponent * Serialize TextComponent * Fix Style * Serialize Component * Fix multiple formats per message, fix reset tag * Fix Style, again * Use FlatMapSerializer * Forgot italics * Count struct fields, reorganize logic * Serialize TranslatableComponent * Rewrite TextComponent Serializer * Fix using TextColor::Parse * Code Cleanup * Add default attribute, just in case * Clippy * use serde derive feature + preferred formatting choices Co-authored-by: BuildTools <unconfigured@null.spigotmc.org> Co-authored-by: mat <github@matdoes.dev>
Diffstat (limited to 'azalea-chat/src/component.rs')
-rwxr-xr-xazalea-chat/src/component.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs
index 9362a66b..95387248 100755
--- a/azalea-chat/src/component.rs
+++ b/azalea-chat/src/component.rs
@@ -6,14 +6,15 @@ use crate::{
};
use azalea_buf::{BufReadError, McBufReadable, McBufWritable};
use once_cell::sync::Lazy;
-use serde::{de, Deserialize, Deserializer};
+use serde::{de, Deserialize, Deserializer, Serialize};
use std::{
fmt::Display,
io::{Cursor, Write},
};
/// A chat component, basically anything you can see in chat.
-#[derive(Clone, Debug, PartialEq)]
+#[derive(Clone, Debug, PartialEq, Serialize)]
+#[serde(untagged)]
pub enum Component {
Text(TextComponent),
Translatable(TranslatableComponent),
@@ -262,11 +263,10 @@ impl McBufReadable for Component {
}
impl McBufWritable for Component {
- fn write_into(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> {
- // let json = serde_json::to_string(self).unwrap();
- // json.write_into(_buf);
- // Ok(())
- todo!()
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
+ let json = serde_json::to_string(self).unwrap();
+ json.write_into(buf)?;
+ Ok(())
}
}