Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[ISSUE #1515]♻️Refactor DeleteKVConfigRequestHeader with derive marco RequestHeaderCodec #2140

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
}
}

#[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 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
Loading