diff --git a/rocketmq-remoting/src/protocol/header.rs b/rocketmq-remoting/src/protocol/header.rs index 20013153..beac6957 100644 --- a/rocketmq-remoting/src/protocol/header.rs +++ b/rocketmq-remoting/src/protocol/header.rs @@ -35,6 +35,7 @@ pub mod get_max_offset_response_header; pub mod get_min_offset_request_header; pub mod get_min_offset_response_header; pub mod get_topic_config_request_header; +pub mod get_topic_stats_info_request_header; pub mod get_topic_stats_request_header; pub mod heartbeat_request_header; pub mod lock_batch_mq_request_header; diff --git a/rocketmq-remoting/src/protocol/header/get_topic_stats_info_request_header.rs b/rocketmq-remoting/src/protocol/header/get_topic_stats_info_request_header.rs new file mode 100644 index 00000000..7b6e0fd4 --- /dev/null +++ b/rocketmq-remoting/src/protocol/header/get_topic_stats_info_request_header.rs @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +use cheetah_string::CheetahString; +use rocketmq_macros::RequestHeaderCodec; +use serde::Deserialize; +use serde::Serialize; + +use crate::protocol::header::namesrv::topic_operation_header::TopicRequestHeader; + +#[derive(Clone, Debug, Serialize, Deserialize, Default, RequestHeaderCodec)] +#[serde(rename_all = "camelCase")] +pub struct QueryConsumeTimeSpanRequestHeader { + #[required] + pub topic: CheetahString, + + #[serde(flatten)] + pub topic_request_header: Option, +} + +#[cfg(test)] +mod tests { + use cheetah_string::CheetahString; + + use super::*; + + #[test] + fn query_consume_time_span_request_header_serializes_correctly() { + let header = QueryConsumeTimeSpanRequestHeader { + topic: CheetahString::from_static_str("test_topic"), + topic_request_header: None, + }; + let serialized = serde_json::to_string(&header).unwrap(); + let expected = r#"{"topic":"test_topic"}"#; + assert_eq!(serialized, expected); + } + + #[test] + fn query_consume_time_span_request_header_deserializes_correctly() { + let data = r#"{"topic":"test_topic"}"#; + let header: QueryConsumeTimeSpanRequestHeader = serde_json::from_str(data).unwrap(); + assert_eq!(header.topic, CheetahString::from_static_str("test_topic")); + assert!(!header.topic_request_header.is_none()); + } + + #[test] + fn query_consume_time_span_request_header_handles_missing_optional_fields() { + let data = r#"{"topic":"test_topic"}"#; + let header: QueryConsumeTimeSpanRequestHeader = serde_json::from_str(data).unwrap(); + assert_eq!(header.topic, CheetahString::from_static_str("test_topic")); + assert!(!header.topic_request_header.is_none()); + } + + #[test] + fn query_consume_time_span_request_header_handles_invalid_data() { + let data = r#"{"topic":12345}"#; + let result: Result = serde_json::from_str(data); + assert!(result.is_err()); + } +}