rocketmq_protocol/protocol/header/
get_max_offset_response_header.rs1use rocketmq_macros::RequestHeaderCodec;
16use serde::Deserialize;
17use serde::Serialize;
18
19#[derive(Debug, Clone, Deserialize, Serialize, Default, RequestHeaderCodec)]
20#[header(
21 type_id = "rocketmq_protocol::protocol::header::get_max_offset_response_header::GetMaxOffsetResponseHeader",
22 java_class = "org.apache.rocketmq.remoting.protocol.header.GetMaxOffsetResponseHeader"
23)]
24pub struct GetMaxOffsetResponseHeader {
25 #[header(required)]
26 pub offset: i64,
27}
28
29#[cfg(test)]
30mod tests {
31 use std::collections::HashMap;
32
33 use cheetah_string::CheetahString;
34
35 use super::*;
36 use crate::protocol::command_custom_header::FromMap;
37
38 #[test]
39 fn get_max_offset_response_header_serialization() {
40 let header = GetMaxOffsetResponseHeader { offset: 12345 };
41 let json = serde_json::to_string(&header).unwrap();
42 assert_eq!(json, r#"{"offset":12345}"#);
43 }
44
45 #[test]
46 fn get_max_offset_response_header_deserialization() {
47 let json = r#"{"offset":12345}"#;
48 let header: GetMaxOffsetResponseHeader = serde_json::from_str(json).unwrap();
49 assert_eq!(header.offset, 12345);
50 }
51
52 #[test]
53 fn get_max_offset_response_header_from_map() {
54 let mut map = HashMap::new();
55 map.insert(CheetahString::from("offset"), CheetahString::from("12345"));
56 let header = <GetMaxOffsetResponseHeader as FromMap>::from(&map).unwrap();
57 assert_eq!(header.offset, 12345);
58 }
59}