RocketMQ-Rust Macros
Using macros to automate repetitive tasks.
Overview
This crate is primarily for the macros used in RocketMQ-Rust. The currently defined macros are as follows:
- RequestHeaderCodec(Derive Macros)
- RemotingSerializable(Derive Macros) - Currently not in use, implemented via alternative methods.
RequestHeaderCodec Macro
The RequestHeaderCodec macro implements serialization and deserialization for RocketMQ's RequestHeader. It automatically implements the CommandCustomHeader trait and the FromMap trait. This macro includes an attribute: required, which indicates that a field of the struct must be present during deserialization; otherwise, it will result in an error.
Note: The
requiredattribute corresponds to the@CFNotNullannotation in the Java version and is implemented in this way in Rust.
Example usage is shown below:
In this example, the SendMessageRequestHeader struct is annotated with the RequestHeaderCodec derive macro, along with other standard Rust attributes like Debug, Clone, Serialize, Deserialize, and Default. The #[required] attribute is used on the producer_group field to denote that it is mandatory for successful deserialization.