pub trait FastCodesHeader {
// Required methods
fn encode_fast(&mut self, out: &mut BytesMut);
fn decode_fast(&mut self, fields: &HashMap<CheetahString, CheetahString>);
// Provided method
fn write_if_not_null(out: &mut BytesMut, key: &str, value: &str) { ... }
}Expand description
Trait for handling fast encoding and decoding headers in a RocketMQ message.
This trait provides methods for efficiently encoding and decoding message headers, leveraging RocketMQ’s serialization capabilities. It is designed for internal use within the RocketMQ client to optimize performance in message processing.
Required Methods§
Sourcefn encode_fast(&mut self, out: &mut BytesMut)
fn encode_fast(&mut self, out: &mut BytesMut)
Encodes the implementing object’s data into the provided output buffer.
This method should be implemented to encode the specific header fields of a message or another entity into a compact binary format for transmission or storage.
§Arguments
out- A mutable reference to the output buffer (bytes::BytesMut) where the encoded data is written.
Sourcefn decode_fast(&mut self, fields: &HashMap<CheetahString, CheetahString>)
fn decode_fast(&mut self, fields: &HashMap<CheetahString, CheetahString>)
Decodes data from a map of fields into the implementing object.
This method should be implemented to populate the object’s fields from a map containing header names and values. It is used to reconstruct an object from data received over the network or read from storage.
§Arguments
fields- A reference to aHashMapcontaining the header fields as key-value pairs.
Provided Methods§
Sourcefn write_if_not_null(out: &mut BytesMut, key: &str, value: &str)
fn write_if_not_null(out: &mut BytesMut, key: &str, value: &str)
Writes a key-value pair to the output buffer if the value is not null or empty.
This method is a utility function used during the encoding process to ensure that only non-empty values are written to the buffer, avoiding unnecessary serialization of empty strings.
§Arguments
out- A mutable reference to the output buffer (bytes::BytesMut) where the key-value pair is written.key- The key as a string slice.value- The value as a string slice.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.