From 3b93fc641250c4d01ab7f0764b7d5faec2f8ae5b Mon Sep 17 00:00:00 2001 From: EightFactorial Date: Sat, 3 Dec 2022 17:08:05 -0800 Subject: 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 Co-authored-by: mat --- azalea-chat/src/component.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'azalea-chat/src/component.rs') 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(()) } } -- cgit v1.2.3