rocketmq_protocol/protocol/header/
notification_response_header.rs1use rocketmq_macros::RequestHeaderCodec;
16use serde::Deserialize;
17use serde::Serialize;
18
19#[derive(Debug, Clone, Deserialize, Serialize, Default, RequestHeaderCodec)]
20#[serde(rename_all = "camelCase")]
21#[header(
22 type_id = "rocketmq_protocol::protocol::header::notification_response_header::NotificationResponseHeader",
23 java_class = "org.apache.rocketmq.remoting.protocol.header.NotificationResponseHeader"
24)]
25pub struct NotificationResponseHeader {
26 #[header(required)]
27 pub has_msg: bool,
28
29 #[serde(default)]
30 #[header(default, default_semantic = "literal:false")]
31 pub polling_full: bool,
32}
33
34#[cfg(test)]
35mod tests {
36 use super::*;
37
38 #[test]
39 fn notification_response_header_serializes_java_camel_case_fields() {
40 let header = NotificationResponseHeader {
41 has_msg: true,
42 polling_full: true,
43 };
44
45 let serialized = serde_json::to_string(&header).unwrap();
46
47 assert_eq!(serialized, r#"{"hasMsg":true,"pollingFull":true}"#);
48 assert!(!serialized.contains("has_msg"));
49 assert!(!serialized.contains("polling_full"));
50 }
51
52 #[test]
53 fn notification_response_header_deserializes_java_camel_case_fields() {
54 let json = r#"{"hasMsg":true,"pollingFull":true}"#;
55
56 let header: NotificationResponseHeader = serde_json::from_str(json).unwrap();
57
58 assert!(header.has_msg);
59 assert!(header.polling_full);
60 }
61
62 #[test]
63 fn notification_response_header_defaults_missing_polling_full_like_java() {
64 let json = r#"{"hasMsg":true}"#;
65
66 let header: NotificationResponseHeader = serde_json::from_str(json).unwrap();
67
68 assert!(header.has_msg);
69 assert!(!header.polling_full);
70 }
71}