Skip to content

Commit

Permalink
[ISSUE #1515]♻️Refactor DeleteKVConfigRequestHeader with derive marco…
Browse files Browse the repository at this point in the history
… RequestHeaderCodec
  • Loading branch information
mxsm committed Jan 7, 2025
1 parent 3581f72 commit 5ee8605
Showing 1 changed file with 4 additions and 46 deletions.
50 changes: 4 additions & 46 deletions rocketmq-remoting/src/protocol/header/namesrv/kv_config_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ impl GetKVConfigResponseHeader {
}
}

#[derive(Debug, Clone, Deserialize, Serialize, Default)]
#[derive(Debug, Clone, Deserialize, Serialize, Default, RequestHeaderCodec)]

Check warning on line 91 in rocketmq-remoting/src/protocol/header/namesrv/kv_config_header.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-remoting/src/protocol/header/namesrv/kv_config_header.rs#L91

Added line #L91 was not covered by tests
pub struct DeleteKVConfigRequestHeader {
#[required]
pub namespace: CheetahString,

#[required]
pub key: CheetahString,
}

impl DeleteKVConfigRequestHeader {
const KEY: &'static str = "key";
const NAMESPACE: &'static str = "namespace";

pub fn new(namespace: impl Into<CheetahString>, key: impl Into<CheetahString>) -> Self {
Self {
namespace: namespace.into(),
Expand All @@ -106,48 +106,6 @@ impl DeleteKVConfigRequestHeader {
}
}

impl CommandCustomHeader for DeleteKVConfigRequestHeader {
fn to_map(&self) -> Option<HashMap<CheetahString, CheetahString>> {
Some(HashMap::from([
(
CheetahString::from_static_str(DeleteKVConfigRequestHeader::NAMESPACE),
self.namespace.clone(),
),
(
CheetahString::from_static_str(DeleteKVConfigRequestHeader::KEY),
self.key.clone(),
),
]))
}
}

impl FromMap for DeleteKVConfigRequestHeader {
type Error = crate::remoting_error::RemotingError;

type Target = DeleteKVConfigRequestHeader;

fn from(map: &HashMap<CheetahString, CheetahString>) -> Result<Self::Target, Self::Error> {
Ok(DeleteKVConfigRequestHeader {
namespace: map
.get(&CheetahString::from_static_str(
DeleteKVConfigRequestHeader::NAMESPACE,
))
.cloned()
.ok_or(Self::Error::RemotingCommandError(
"Miss namespace field".to_string(),
))?,
key: map
.get(&CheetahString::from_static_str(
DeleteKVConfigRequestHeader::KEY,
))
.cloned()
.ok_or(Self::Error::RemotingCommandError(
"Miss key field".to_string(),
))?,
})
}
}

#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct GetKVListByNamespaceRequestHeader {
pub namespace: CheetahString,
Expand Down

0 comments on commit 5ee8605

Please # to comment.