pub trait CommandCustomHeader: AsAny {
Show 18 methods
// Required method
fn to_map(&self) -> Option<HashMap<CheetahString, CheetahString>>;
// Provided methods
fn check_fields(&self) -> Result<()> { ... }
fn encode_into_map(&self, out: &mut HeaderMap) { ... }
fn try_encode_into_map(
&self,
out: &mut HeaderMap,
) -> Result<(), ProtocolContractViolation> { ... }
fn resolve_wire_key(&self, _key: &str) -> Option<ResolvedHeaderKey> { ... }
fn canonical_wire_key(&self, key: &str) -> Option<&'static str> { ... }
fn contains_wire_key(&self, key: &str) -> bool { ... }
fn encoded_len_hint(&self) -> usize { ... }
fn encode_capability(&self) -> HeaderEncodeCapability { ... }
fn encode_direct_binary(
&self,
_out: &mut BytesMut,
) -> Result<(), ProtocolContractViolation> { ... }
fn supports_direct_json_fields(&self) -> bool { ... }
fn encode_direct_json_fields(
&self,
_out: &mut BytesMut,
) -> Result<(), ProtocolContractViolation> { ... }
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>,
) -> Result<()> { ... }
fn support_fast_codec(&self) -> bool { ... }
fn get_and_check_not_none(
&self,
map: &HashMap<CheetahString, CheetahString>,
field: &CheetahString,
) -> Result<CheetahString> { ... }
fn get_and_check_not_none_ref<'a>(
&self,
map: &'a HashMap<CheetahString, CheetahString>,
field: &CheetahString,
) -> Result<&'a 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 map is returned; explicitly audited
fieldless headers return an empty map. If conversion fails, None is
returned.
Provided Methods§
Sourcefn check_fields(&self) -> Result<()>
fn check_fields(&self) -> Result<()>
Checks the fields of the implementing type.
Returns a typed result indicating whether the fields are valid.
If the fields are valid, the Ok variant is returned with an empty () value.
If the fields are invalid, an error governed by a stable
rocketmq_error::ErrorDescriptor is returned.
Sourcefn encode_into_map(&self, out: &mut HeaderMap)
fn encode_into_map(&self, out: &mut HeaderMap)
Appends this header’s extension fields to an existing map.
Generated implementations write directly into out. The default preserves compatibility
for handwritten implementations.
Sourcefn try_encode_into_map(
&self,
out: &mut HeaderMap,
) -> Result<(), ProtocolContractViolation>
fn try_encode_into_map( &self, out: &mut HeaderMap, ) -> Result<(), ProtocolContractViolation>
Validates and appends this header’s fields to an existing map.
Typed codecs override this method to preserve classified failures. The
default adapts handwritten implementations without changing their object-safe
trait surface or silently treating None as a successful conversion.
§Errors
Returns ProtocolContractViolation::LegacyValidation when check_fields
fails, or ProtocolContractViolation::LegacyMapConversionFailed when a legacy
to_map implementation returns None.
Sourcefn resolve_wire_key(&self, _key: &str) -> Option<ResolvedHeaderKey>
fn resolve_wire_key(&self, _key: &str) -> Option<ResolvedHeaderKey>
Resolves a canonical key or decode alias for typed headers.
Sourcefn canonical_wire_key(&self, key: &str) -> Option<&'static str>
fn canonical_wire_key(&self, key: &str) -> Option<&'static str>
Resolves a key and returns its canonical wire key.
Sourcefn contains_wire_key(&self, key: &str) -> bool
fn contains_wire_key(&self, key: &str) -> bool
Returns whether a canonical key or alias belongs to this header schema.
Sourcefn encoded_len_hint(&self) -> usize
fn encoded_len_hint(&self) -> usize
Returns a saturating extension-field payload capacity hint.
Sourcefn encode_capability(&self) -> HeaderEncodeCapability
fn encode_capability(&self) -> HeaderEncodeCapability
Returns the authoritative encoding path for this header.
Sourcefn encode_direct_binary(
&self,
_out: &mut BytesMut,
) -> Result<(), ProtocolContractViolation>
fn encode_direct_binary( &self, _out: &mut BytesMut, ) -> Result<(), ProtocolContractViolation>
Appends this header directly to a ROCKETMQ extension-field payload.
Implementations must require only shared access so cloned remoting
commands can encode the same immutable header. Callers must check
Self::encode_capability before invoking this method. Implementations
are responsible for validating the header before the first write; the
frame entrypoint does not pre-validate because map and binary encoders
already own the authoritative validation boundary.
§Errors
Returns a classified header codec error when validation or binary representation fails. The default reports that direct encoding is unavailable.
Sourcefn supports_direct_json_fields(&self) -> bool
fn supports_direct_json_fields(&self) -> bool
Returns whether this header can write its complete JSON extension-field
object without first materializing a HeaderMap.
Sourcefn encode_direct_json_fields(
&self,
_out: &mut BytesMut,
) -> Result<(), ProtocolContractViolation>
fn encode_direct_json_fields( &self, _out: &mut BytesMut, ) -> Result<(), ProtocolContractViolation>
Writes this header as one complete JSON extension-field object.
Callers must check Self::supports_direct_json_fields before invoking
this method. Implementations must validate before writing and must leave
rollback to the enclosing frame encoder.
§Errors
Returns a classified header codec error when direct JSON encoding is unavailable or validation fails.
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 aBytesMutbuffer where thekeywill 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)
Compatibility adapter for the legacy mutable fast-encoding API.
Production serialization uses Self::encode_capability and
Self::encode_direct_binary directly. This adapter cannot propagate
errors and remains only for existing callers during migration.
Sourcefn decode_fast(
&mut self,
_fields: &HashMap<CheetahString, CheetahString>,
) -> Result<()>
fn decode_fast( &mut self, _fields: &HashMap<CheetahString, CheetahString>, ) -> Result<()>
A placeholder function for fast decoding.
This function currently does nothing and can be overridden by implementing types.
§Arguments
_fields- A reference to aHashMapthat 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 legacy capability is limited to hand-written fast decoding. Direct
binary encoding is reported independently by Self::encode_capability.
The default remains false so enabling generated direct encoding cannot
route decoding through an unimplemented legacy hook.
Sourcefn get_and_check_not_none(
&self,
map: &HashMap<CheetahString, CheetahString>,
field: &CheetahString,
) -> Result<CheetahString>
fn get_and_check_not_none( &self, map: &HashMap<CheetahString, CheetahString>, field: &CheetahString, ) -> Result<CheetahString>
Retrieves the value associated with the specified field from the provided map.
§Arguments
map- A reference to aHashMapcontainingCheetahStringkeys and values.field- A reference to aCheetahStringrepresenting the field to retrieve.
§Returns
Ok(CheetahString)- If the field is found in the map, returns the associated value.Err(Error)- If the field is not found in the map, returns an error indicating the field is required.
§Errors
This function returns a serialization error if the specified field is not found in the map.
Sourcefn get_and_check_not_none_ref<'a>(
&self,
map: &'a HashMap<CheetahString, CheetahString>,
field: &CheetahString,
) -> Result<&'a CheetahString>
fn get_and_check_not_none_ref<'a>( &self, map: &'a HashMap<CheetahString, CheetahString>, field: &CheetahString, ) -> Result<&'a CheetahString>
Retrieves a borrowed value associated with the specified field from the provided map.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".