Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[ISSUE #1513]♻️Refactor GetKVConfigRequestHeader with derive marco RequestHeaderCodec #2138

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 @@ -58,16 +58,16 @@
}
}

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

Check warning on line 61 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#L61

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

#[required]
pub key: CheetahString,
}

impl GetKVConfigRequestHeader {
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 @@ -76,48 +76,6 @@
}
}

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

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

type Target = GetKVConfigRequestHeader;

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

#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct GetKVConfigResponseHeader {
pub value: Option<CheetahString>,
Expand Down
Loading