diff options
| author | mat <github@matdoes.dev> | 2022-01-02 17:19:04 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-01-02 17:19:04 -0600 |
| commit | 094c210dada7c0ee83c19965739312d2d00e4099 (patch) | |
| tree | 00b678a2aa0c03bbfde12475431d749c0b2b837f /azalea-protocol/packet-macros/src | |
| parent | bb566aa54131a23b6d9e605c81a8ff4d1d1c21d7 (diff) | |
| download | azalea-drasl-094c210dada7c0ee83c19965739312d2d00e4099.tar.xz | |
switch all current macro types to the new system
Diffstat (limited to 'azalea-protocol/packet-macros/src')
| -rw-r--r-- | azalea-protocol/packet-macros/src/lib.rs | 46 |
1 files changed, 5 insertions, 41 deletions
diff --git a/azalea-protocol/packet-macros/src/lib.rs b/azalea-protocol/packet-macros/src/lib.rs index 5b2088a1..ba963111 100644 --- a/azalea-protocol/packet-macros/src/lib.rs +++ b/azalea-protocol/packet-macros/src/lib.rs @@ -25,31 +25,14 @@ fn as_packet_derive( // if it's a string, use buf.write_string match field_type { syn::Type::Path(syn::TypePath { path, .. }) => { - if path.is_ident("String") { - quote! { buf.write_utf(&self.#field_name)?; } - } else if path.is_ident("ResourceLocation") { - quote! { buf.write_resource_location(&self.#field_name)?; } - } else if path.is_ident("u32") { - if f.attrs.iter().any(|attr| attr.path.is_ident("varint")) { - quote! { buf.write_varint(self.#field_name as i32)?; } - } else { - quote! { buf.write_u32(self.#field_name)?; } + if f.attrs.iter().any(|attr| attr.path.is_ident("varint")) { + quote! { + crate::mc_buf::McBufVarintWritable::varint_write_into(&self.#field_name, buf)?; } - } else if path.is_ident("u16") { - quote! { buf.write_short(self.#field_name as i16)?; } - } else if path.is_ident("ConnectionProtocol") { - quote! { buf.write_varint(self.#field_name.clone() as i32)?; } } else { - if f.attrs.iter().any(|attr| attr.path.is_ident("varint")) { - quote! { - crate::mc_buf::McBufVarintWritable::varint_write_into(&self.#field_name, buf)?; - } - } else { - quote! { - crate::mc_buf::McBufWritable::write_into(&self.#field_name, buf)?; - } + quote! { + crate::mc_buf::McBufWritable::write_into(&self.#field_name, buf)?; } - } } _ => panic!( @@ -70,24 +53,6 @@ fn as_packet_derive( // if it's a string, use buf.write_string match field_type { syn::Type::Path(syn::TypePath { path, .. }) => { - if path.is_ident("String") { - quote! { let #field_name = buf.read_utf().await?; } - } else if path.is_ident("ResourceLocation") { - quote! { let #field_name = buf.read_resource_location().await?; } - } else if path.is_ident("u32") { - if f.attrs.iter().any(|a| a.path.is_ident("varint")) { - quote! { let #field_name = buf.read_varint().await? as u32; } - } else { - quote! { let #field_name = buf.read_u32().await?; } - } - } else if path.is_ident("u16") { - quote! { let #field_name = buf.read_short().await? as u16; } - } else if path.is_ident("ConnectionProtocol") { - quote! { - let #field_name = ConnectionProtocol::from_i32(buf.read_varint().await?) - .ok_or_else(|| "Invalid intention".to_string())?; - } - } else { if f.attrs.iter().any(|a| a.path.is_ident("varint")) { quote! { let #field_name = crate::mc_buf::McBufVarintReadable::varint_read_into(buf).await?; @@ -96,7 +61,6 @@ fn as_packet_derive( quote! { let #field_name = crate::mc_buf::McBufReadable::read_into(buf).await?; } - } } } _ => panic!( |
