* feat(protocol): Implement char serialization and deserialization
This commit introduces support for serializing and deserializing individual characters within the pumpkin-protocol. Characters are handled as big-endian u32 Unicode scalar values.
Key changes:
- Implemented `Serializer::serialize_char` to write a `char` as a `u32`.
- Implemented `Deserializer::deserialize_char` to read a `u32` and convert it to a `char`, including validation for invalid scalar values.
- Added a new test suite `test_char_reserialize` with cases for ASCII, multi-byte Unicode characters (e.g., 'Ω'), and characters requiring 4-byte UTF-8 representation (e.g., '🎃').
- Corrected warnings related to unused mutable variables in the new tests.
Additionally, to support the testing and building of related crates:
- fix(build): Enabled the `io-util` feature for the `tokio` workspace dependency in the root `Cargo.toml`. This resolved compilation errors in the `pumpkin-world` crate by providing necessary async I/O utilities like `AsyncReadExt` and `AsyncWriteExt`.
* feat(protocol): Implement i128/u128 serialization and deserialization
This commit adds support for serializing and deserializing 128-bit integer types (i128 and u128) in the pumpkin-protocol. These values are written and read as 16 bytes in big-endian order.
Key changes:
- Implemented `Serializer::serialize_i128` and `Serializer::serialize_u128` to write i128/u128 values.
- Added `NetworkReadExt::get_i128_be` and `NetworkReadExt::get_u128_be` for reading these types.
- Implemented `Deserializer::deserialize_i128` and `Deserializer::deserialize_u128`.
- Added new test cases `test_i128_reserialize` and `test_u128_reserialize` to ensure correctness for both positive and negative i128 values, and positive u128 values.
* feat(protocol): Implement unit type (de)serialization
This commit introduces serialization and deserialization logic for Rust's unit type `()` and unit structs.
- `Serializer::serialize_unit` now correctly writes no bytes for unit types, as they carry no value.
- `Deserializer::deserialize_unit` and `Deserializer::deserialize_unit_struct` are implemented to
consume no input and correctly reconstruct unit types/structs.
- Added `test_unit_reserialize` to verify that serializing and deserializing unit structs, both standalone and as fields within other structs, behaves as expected (i.e., no bytes are written or read for the unit components).
* feat(protocol): Implement enum (de)serialization for all variant types
This commit introduces comprehensive support for serializing and
deserializing Rust enums, including unit, newtype, tuple, and
struct variants.
Key changes:
- `serializer.rs`:
- Implemented `serialize_struct_variant` to correctly write the
variant index (as a VarInt) and then delegate to the
`SerializeStructVariant` trait for field serialization.
- Implemented `SerializeStructVariant` to serialize individual
fields of a struct variant.
- `deserializer.rs`:
- Implemented `deserialize_enum` to use `visitor.visit_enum`.
- Implemented `EnumAccess` to read the variant index (as a VarInt,
converted to u32) and deserialize the correct variant.
- Implemented `VariantAccess` to handle deserialization of
unit, newtype, tuple, and struct variants.
- `ser/mod.rs`:
- Added `test_enum_reserialize` to thoroughly test (de)serialization
of enums with unit, newtype (e.g., `Enum::B(i32)`), and struct
variants (e.g., `Enum::C { field: T }`).
This ensures that enums with various structures can be reliably
transmitted over the network protocol.
* cargo fmt
* feat(protocol): Implement (de)serialization for tuple structs
This commit adds support for serializing and deserializing tuple
structs within the network protocol.
Key changes:
- `serializer.rs`:
- `serialize_tuple_struct` in the main serializer now delegates
to the `SerializeTupleStruct` trait implementation.
- Implemented `SerializeTupleStruct` to serialize fields of a
tuple struct sequentially.
- Updated `SerializeTupleVariant::serialize_field` to correctly
serialize tuple variant fields.
- `deserializer.rs`:
- Implemented `deserialize_tuple_struct` to reuse the existing
`deserialize_tuple` logic, as their serialization format is
identical.
- `ser/mod.rs`:
- Added `test_tuple_struct_reserialize` to verify the correct
(de)serialization of tuple structs.
These changes ensure that tuple structs are handled correctly by the
protocol.
* feat(protocol): Implement (de)serialization for maps
This commit introduces support for serializing and deserializing
maps (specifically `std::collections::HashMap`) within the network
protocol.
Key changes:
- `serializer.rs`:
- `serialize_map` now requires a known length for the map and
writes this length as a VarInt before serializing key-value
pairs.
- Implemented `ser::SerializeMap` to handle the sequential
serialization of map keys and values.
- `deserializer.rs`:
- `deserialize_map` reads the VarInt length prefix.
- Implemented `de::MapAccess` to deserialize key-value pairs
according to the read length.
- `ser/mod.rs`:
- Added `test_map_reserialize` to verify the correct
(de)serialization of `HashMap<String, i32>`, including
empty maps and maps with multiple entries.
These changes enable generic map types to be transmitted via the
protocol, with their length explicitly prefixed.