use bytes::Bytes;
use bytes::BytesMut;
use super::RemotingCommand;
use crate::protocol::command_custom_header::CommandCustomHeader;
impl RemotingCommand {
#[deprecated(
note = "use create_success_response_command for SUCCESS or create_java_default_error_response_command for Java-compatible unset errors"
)]
pub fn create_response_command() -> Self {
Self::create_success_response_command()
}
#[deprecated(
note = "use create_success_response_command_with_header for SUCCESS or create_java_default_error_response_command_with_header for Java-compatible unset errors"
)]
pub fn create_response_command_with_header(header: impl CommandCustomHeader + Sync + Send + 'static) -> Self {
Self::create_success_response_command_with_header(header)
}
#[inline]
pub fn make_custom_header_to_net(&mut self) {
let _ = self.try_make_custom_header_to_net();
}
#[inline]
pub fn materialize_custom_header_to_ext_fields(&mut self) {
let _ = self.try_make_custom_header_to_net();
}
#[deprecated(
since = "1.0.0",
note = "use try_read_custom_header_ref; this compatibility alias is fallible despite its historical unchecked name"
)]
pub fn read_custom_header_ref_unchecked<T>(&self) -> rocketmq_error::Result<&T>
where
T: CommandCustomHeader + Sync + Send + 'static,
{
self.try_read_custom_header_ref::<T>()
}
#[deprecated(note = "use read_custom_header_mut; shared-reference mutation is no longer supported")]
pub fn read_custom_header_mut_from_ref<T>(&mut self) -> Option<&mut T>
where
T: CommandCustomHeader + Sync + Send + 'static,
{
self.try_read_custom_header_mut::<T>().ok()
}
#[deprecated(
since = "1.0.0",
note = "use try_read_custom_header_mut; this compatibility alias is fallible despite its historical unchecked name"
)]
pub fn read_custom_header_mut_unchecked<T>(&mut self) -> rocketmq_error::Result<&mut T>
where
T: CommandCustomHeader + Sync + Send + 'static,
{
self.try_read_custom_header_mut::<T>()
}
pub fn read_custom_header_ref<T>(&self) -> Option<&T>
where
T: CommandCustomHeader + Sync + Send + 'static,
{
self.try_read_custom_header_ref::<T>().ok()
}
pub fn read_custom_header_mut<T>(&mut self) -> Option<&mut T>
where
T: CommandCustomHeader + Sync + Send + 'static,
{
self.try_read_custom_header_mut::<T>().ok()
}
#[inline]
pub fn header_encode(&mut self) -> Option<Bytes> {
self.try_header_encode().ok()
}
#[inline]
pub fn fast_header_encode(&mut self, dst: &mut BytesMut) {
let _ = self.try_fast_header_encode(dst);
}
#[inline]
pub fn encode_header(&mut self) -> Option<Bytes> {
let body_length = self.body.as_ref().map_or(0, |b| b.len());
self.try_encode_header_with_body_length(body_length).ok()
}
#[inline]
pub fn encode_header_with_body_length(&mut self, body_length: usize) -> Option<Bytes> {
self.try_encode_header_with_body_length(body_length).ok()
}
}