pub trait CommandCustomHeader: AsAny {
// Required method
fn to_map(&self) -> Option<HashMap<CheetahString, CheetahString>>;
// Provided methods
fn check_fields(&self) -> Result<(), Error> { ... }
fn write_if_not_null(&self, out: &mut BytesMut, key: &str, value: &str) { ... }
fn encode_fast(&mut self, _out: &mut BytesMut) { ... }
fn decode_fast(
&mut self,
_fields: &HashMap<CheetahString, CheetahString>,
) -> RocketMQResult<()> { ... }
fn support_fast_codec(&self) -> bool { ... }
fn get_and_check_not_none(
&self,
map: &HashMap<CheetahString, CheetahString>,
field: &CheetahString,
) -> RocketMQResult<CheetahString> { ... }
}
Required Methods§
Sourcefn to_map(&self) -> Option<HashMap<CheetahString, CheetahString>>
fn to_map(&self) -> Option<HashMap<CheetahString, CheetahString>>
Converts the implementing type to a map.
Returns an Option
that contains a HashMap
of string keys and string values,
representing the implementing type’s fields.
If the conversion is successful, a non-empty map is returned.
If the conversion fails, None
is returned.
Provided Methods§
Sourcefn check_fields(&self) -> Result<(), Error>
fn check_fields(&self) -> Result<(), Error>
Checks the fields of the implementing type.
Returns a Result
indicating whether the fields are valid or not.
If the fields are valid, the Ok
variant is returned with an empty ()
value.
If the fields are invalid, an Err
variant is returned with an associated Error
value.
Sourcefn write_if_not_null(&self, out: &mut BytesMut, key: &str, value: &str)
fn write_if_not_null(&self, out: &mut BytesMut, key: &str, value: &str)
Writes the provided key
to the out
buffer if the value
is not empty.
§Arguments
out
- A mutable reference to aBytesMut
buffer where thekey
will be written.key
- A string slice that represents the key to be written.value
- A string slice that represents the value associated with the key.
§Behavior
If value
is not empty, the function will write the key
to the out
buffer twice,
first with a short length prefix and then with a long length prefix.
Sourcefn encode_fast(&mut self, _out: &mut BytesMut)
fn encode_fast(&mut self, _out: &mut BytesMut)
A placeholder function for fast encoding.
This function currently does nothing and can be overridden by implementing types.
Sourcefn decode_fast(
&mut self,
_fields: &HashMap<CheetahString, CheetahString>,
) -> RocketMQResult<()>
fn decode_fast( &mut self, _fields: &HashMap<CheetahString, CheetahString>, ) -> RocketMQResult<()>
A placeholder function for fast decoding.
This function currently does nothing and can be overridden by implementing types.
§Arguments
_fields
- A reference to aHashMap
that contains the fields to be decoded.
Sourcefn support_fast_codec(&self) -> bool
fn support_fast_codec(&self) -> bool
Indicates whether the implementing type supports fast codec.
§Returns
This function returns false
by default, indicating that the implementing type does not
support fast codec. This can be overridden by implementing types.
Sourcefn get_and_check_not_none(
&self,
map: &HashMap<CheetahString, CheetahString>,
field: &CheetahString,
) -> RocketMQResult<CheetahString>
fn get_and_check_not_none( &self, map: &HashMap<CheetahString, CheetahString>, field: &CheetahString, ) -> RocketMQResult<CheetahString>
Retrieves the value associated with the specified field from the provided map.
§Arguments
map
- A reference to aHashMap
containingCheetahString
keys and values.field
- A reference to aCheetahString
representing the field to retrieve.
§Returns
Ok(CheetahString)
- If the field is found in the map, returns the associated value.Err(RocketmqError::DeserializeHeaderError)
- If the field is not found in the map, returns an error indicating the field is required.
§Errors
This function returns a RocketmqError::DeserializeHeaderError
if the specified field is
not found in the map.