npsd (Network Payload Serializer / Deserializer)
The npsd crate provides a flexible and efficient way to serialize and deserialize network payloads. It supports converting Rust types into byte streams suitable for network transmission and reconstructing those types from byte streams received over the network. This is particularly useful for networked applications that require efficient and reliable data exchange.
Features
- Serialize and deserialize complex Rust types to and from byte streams.
- Support for custom serialization contexts.
- Middleware support for extensible processing during serialization/deserialization.
Differences between npsd and serde
-
Purpose:
npsdis designed specifically for network payload serialization and deserialization, offering efficient handling of byte streams for network transmission.serde, on the other hand, is a general-purpose serialization framework supporting multiple formats (JSON, XML, etc.). -
Custom Contexts:
npsdsupports custom serialization contexts and middleware for extensible processing during serialization/deserialization, which is tailored for networked applications.serdefocuses on format-agnostic serialization. -
Procedural Macros: Both libraries provide procedural macros, but
npsdincludes specific macros (Schema,Bitmap,AsyncSchema,AsyncBitmap,Info) for network-related serialization scenarios.
Procedural Macros
The npsd crate also provides procedural macros for deriving serialization and deserialization implementations.
Schema
The Schema macro derives implementations for serializing and deserializing complex Rust types.
Example
use ;
Bitmap
The Bitmap macro derives implementations for serializing and deserializing bitmaps.
Example
use ;
AsyncSchema
The AsyncSchema macro derives implementations for asynchronous serializing and deserializing complex Rust types.
Example
use ;
async
AsyncBitmap
The AsyncBitmap macro derives implementations for asynchronous serializing and deserializing bitmaps.
Example
use ;
Traits
PayloadContext
The PayloadContext trait provides a way to unwrap the context used in the payload processing.
Middleware
The Middleware trait defines methods for converting types to and from payloads of bytes.
AsyncMiddleware
The AsyncMiddleware trait defines asynchronous methods for converting types to and from payloads of bytes.
IntoPayload
The IntoPayload trait is used to convert a type into a payload of bytes.
AsyncIntoPayload
The AsyncIntoPayload trait is used for asynchronous methods for converting types into payloads of bytes.
FromPayload
The FromPayload trait is used to convert a payload of bytes back into a type.
AsyncFromPayload
The AsyncFromPayload trait is used for asynchronous methods for converting payloads of bytes back into types.
PayloadInfo
The PayloadInfo trait provides metadata about the payload. Here are the associated constants and their descriptions:
const HASH: u64: A constant hash value associated with the type. This hash is calculated using the type's string representation and provides a unique identifier for the payload type.const TYPE: &'static str: A string representing the type of the payload. This is used to identify the payload type in a human-readable format.const SIZE: Option<usize>: An optional constant representing the size of the payload. This can be used to specify a fixed size for the payload, if applicable.
Payload
The Payload trait combines IntoPayload and FromPayload to facilitate complete serialization and deserialization of types.
AsyncPayload
The AsyncPayload trait combines AsyncIntoPayload and AsyncFromPayload to asynchronous methods for complete serialization and deserialization of types.
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue if you encounter any problems or have suggestions for improvements.
License
This project is licensed under the Apache 2.0 License.