1use broadcast_common::{Parse, Serialize};
14
15use crate::RtmpError;
16use crate::chunk::Message;
17
18type Result<T> = core::result::Result<T, RtmpError>;
19
20pub mod msg_type {
26 pub const SET_CHUNK_SIZE: u8 = 1;
28 pub const ABORT: u8 = 2;
30 pub const ACKNOWLEDGEMENT: u8 = 3;
32 pub const USER_CONTROL: u8 = 4;
34 pub const WINDOW_ACK_SIZE: u8 = 5;
36 pub const SET_PEER_BANDWIDTH: u8 = 6;
38 pub const AUDIO: u8 = 8;
40 pub const VIDEO: u8 = 9;
42 pub const DATA_AMF3: u8 = 15;
44 pub const COMMAND_AMF3: u8 = 17;
46 pub const DATA_AMF0: u8 = 18;
48 pub const COMMAND_AMF0: u8 = 20;
50 pub const AGGREGATE: u8 = 22;
52}
53
54pub const CONTROL_CHUNK_STREAM_ID: u32 = 2;
57pub const CONTROL_MESSAGE_STREAM_ID: u32 = 0;
60
61const U32_LEN: usize = 4;
64const SET_PEER_BANDWIDTH_LEN: usize = U32_LEN + 1;
67
68const SET_CHUNK_SIZE_RESERVED_MASK: u32 = 0x8000_0000;
71const SET_CHUNK_SIZE_VALUE_MASK: u32 = 0x7FFF_FFFF;
74
75fn read_u32_be(b: &[u8]) -> u32 {
76 u32::from_be_bytes([b[0], b[1], b[2], b[3]])
77}
78
79fn need_u32(bytes: &[u8], what: &'static str) -> Result<u32> {
80 if bytes.len() < U32_LEN {
81 return Err(RtmpError::BufferTooShort {
82 need: U32_LEN,
83 have: bytes.len(),
84 what,
85 });
86 }
87 Ok(read_u32_be(bytes))
88}
89
90#[derive(Debug, Clone, Copy, PartialEq, Eq)]
94#[non_exhaustive]
95pub enum LimitType {
96 Hard,
98 Soft,
101 Dynamic,
104}
105
106impl LimitType {
107 #[must_use]
109 pub fn name(&self) -> &'static str {
110 match self {
111 LimitType::Hard => "hard",
112 LimitType::Soft => "soft",
113 LimitType::Dynamic => "dynamic",
114 }
115 }
116
117 pub const fn from_u8(v: u8) -> core::result::Result<Self, RtmpError> {
122 match v {
123 0 => Ok(LimitType::Hard),
124 1 => Ok(LimitType::Soft),
125 2 => Ok(LimitType::Dynamic),
126 _ => Err(RtmpError::Malformed {
127 what: "set peer bandwidth limit type (must be 0..=2)",
128 }),
129 }
130 }
131
132 #[must_use]
134 pub const fn to_u8(self) -> u8 {
135 match self {
136 LimitType::Hard => 0,
137 LimitType::Soft => 1,
138 LimitType::Dynamic => 2,
139 }
140 }
141}
142
143broadcast_common::impl_spec_display!(LimitType);
144
145#[non_exhaustive]
156#[derive(Debug, Clone, Copy, PartialEq, Eq)]
157pub enum ProtocolControl {
158 SetChunkSize(u32),
160 Abort {
163 chunk_stream_id: u32,
166 },
167 Acknowledgement(u32),
169 WindowAckSize(u32),
172 SetPeerBandwidth {
174 ack_window_size: u32,
176 limit_type: LimitType,
178 },
179}
180
181impl ProtocolControl {
182 #[must_use]
184 pub fn name(&self) -> &'static str {
185 match self {
186 ProtocolControl::SetChunkSize(_) => "set chunk size",
187 ProtocolControl::Abort { .. } => "abort message",
188 ProtocolControl::Acknowledgement(_) => "acknowledgement",
189 ProtocolControl::WindowAckSize(_) => "window acknowledgement size",
190 ProtocolControl::SetPeerBandwidth { .. } => "set peer bandwidth",
191 }
192 }
193
194 #[must_use]
196 pub fn message_type_id(&self) -> u8 {
197 match self {
198 ProtocolControl::SetChunkSize(_) => msg_type::SET_CHUNK_SIZE,
199 ProtocolControl::Abort { .. } => msg_type::ABORT,
200 ProtocolControl::Acknowledgement(_) => msg_type::ACKNOWLEDGEMENT,
201 ProtocolControl::WindowAckSize(_) => msg_type::WINDOW_ACK_SIZE,
202 ProtocolControl::SetPeerBandwidth { .. } => msg_type::SET_PEER_BANDWIDTH,
203 }
204 }
205
206 pub fn from_message(message: &Message) -> Result<Option<Self>> {
218 Self::from_payload(message.message_type_id, &message.payload)
219 }
220
221 pub fn from_payload(message_type_id: u8, payload: &[u8]) -> Result<Option<Self>> {
231 match message_type_id {
232 msg_type::SET_CHUNK_SIZE => {
233 let raw = need_u32(payload, "set chunk size payload")?;
234 if raw & SET_CHUNK_SIZE_RESERVED_MASK != 0 {
235 return Err(RtmpError::Malformed {
236 what: "set chunk size reserved top bit (must be 0)",
237 });
238 }
239 let size = raw & SET_CHUNK_SIZE_VALUE_MASK;
240 if size == 0 {
241 return Err(RtmpError::Malformed {
242 what: "set chunk size value (must be >= 1)",
243 });
244 }
245 Ok(Some(ProtocolControl::SetChunkSize(size)))
246 }
247 msg_type::ABORT => {
248 let chunk_stream_id = need_u32(payload, "abort message payload")?;
249 Ok(Some(ProtocolControl::Abort { chunk_stream_id }))
250 }
251 msg_type::ACKNOWLEDGEMENT => {
252 let sequence_number = need_u32(payload, "acknowledgement payload")?;
253 Ok(Some(ProtocolControl::Acknowledgement(sequence_number)))
254 }
255 msg_type::WINDOW_ACK_SIZE => {
256 let window = need_u32(payload, "window acknowledgement size payload")?;
257 Ok(Some(ProtocolControl::WindowAckSize(window)))
258 }
259 msg_type::SET_PEER_BANDWIDTH => {
260 if payload.len() < SET_PEER_BANDWIDTH_LEN {
261 return Err(RtmpError::BufferTooShort {
262 need: SET_PEER_BANDWIDTH_LEN,
263 have: payload.len(),
264 what: "set peer bandwidth payload",
265 });
266 }
267 let ack_window_size = read_u32_be(&payload[0..U32_LEN]);
268 let limit_type = LimitType::from_u8(payload[U32_LEN])?;
269 Ok(Some(ProtocolControl::SetPeerBandwidth {
270 ack_window_size,
271 limit_type,
272 }))
273 }
274 _ => Ok(None),
275 }
276 }
277
278 #[must_use]
290 pub fn to_message(&self) -> Message {
291 Message {
292 chunk_stream_id: CONTROL_CHUNK_STREAM_ID,
293 timestamp: 0,
294 message_type_id: self.message_type_id(),
295 message_stream_id: CONTROL_MESSAGE_STREAM_ID,
296 payload: self
297 .try_to_bytes()
298 .expect("documented panic: see `# Panics`; use try_to_message"),
299 }
300 }
301
302 pub fn try_to_message(&self) -> Result<Message> {
310 Ok(Message {
311 chunk_stream_id: CONTROL_CHUNK_STREAM_ID,
312 timestamp: 0,
313 message_type_id: self.message_type_id(),
314 message_stream_id: CONTROL_MESSAGE_STREAM_ID,
315 payload: self.try_to_bytes()?,
316 })
317 }
318}
319
320broadcast_common::impl_spec_display!(ProtocolControl);
321
322impl Serialize for ProtocolControl {
323 type Error = RtmpError;
324
325 fn serialized_len(&self) -> usize {
326 match self {
327 ProtocolControl::SetChunkSize(_)
328 | ProtocolControl::Abort { .. }
329 | ProtocolControl::Acknowledgement(_)
330 | ProtocolControl::WindowAckSize(_) => U32_LEN,
331 ProtocolControl::SetPeerBandwidth { .. } => SET_PEER_BANDWIDTH_LEN,
332 }
333 }
334
335 fn serialize_into(&self, buf: &mut [u8]) -> Result<usize> {
336 let written = self.serialized_len();
337 if buf.len() < written {
338 return Err(RtmpError::BufferTooShort {
339 need: written,
340 have: buf.len(),
341 what: "protocol control payload output",
342 });
343 }
344 match *self {
345 ProtocolControl::SetChunkSize(size) => {
346 if size == 0 || size & SET_CHUNK_SIZE_RESERVED_MASK != 0 {
347 return Err(RtmpError::Malformed {
348 what: "set chunk size value (must be 1..=0x7FFF_FFFF)",
349 });
350 }
351 buf[0..U32_LEN].copy_from_slice(&size.to_be_bytes());
352 }
353 ProtocolControl::Abort { chunk_stream_id } => {
354 buf[0..U32_LEN].copy_from_slice(&chunk_stream_id.to_be_bytes());
355 }
356 ProtocolControl::Acknowledgement(sequence_number) => {
357 buf[0..U32_LEN].copy_from_slice(&sequence_number.to_be_bytes());
358 }
359 ProtocolControl::WindowAckSize(window) => {
360 buf[0..U32_LEN].copy_from_slice(&window.to_be_bytes());
361 }
362 ProtocolControl::SetPeerBandwidth {
363 ack_window_size,
364 limit_type,
365 } => {
366 buf[0..U32_LEN].copy_from_slice(&ack_window_size.to_be_bytes());
367 buf[U32_LEN] = limit_type.to_u8();
368 }
369 }
370 Ok(written)
371 }
372}
373
374const EVENT_TYPE_LEN: usize = 2;
378
379mod event_type {
381 pub const STREAM_BEGIN: u16 = 0;
382 pub const STREAM_EOF: u16 = 1;
383 pub const STREAM_DRY: u16 = 2;
384 pub const SET_BUFFER_LENGTH: u16 = 3;
385 pub const STREAM_IS_RECORDED: u16 = 4;
386 pub const PING_REQUEST: u16 = 6;
388 pub const PING_RESPONSE: u16 = 7;
389}
390
391#[non_exhaustive]
400#[derive(Debug, Clone, Copy, PartialEq, Eq)]
401pub enum UserControl {
402 StreamBegin(u32),
406 StreamEof(u32),
409 StreamDry(u32),
412 SetBufferLength {
415 stream_id: u32,
417 buffer_ms: u32,
419 },
420 StreamIsRecorded(u32),
423 PingRequest(u32),
426 PingResponse(u32),
429}
430
431impl UserControl {
432 #[must_use]
434 pub fn name(&self) -> &'static str {
435 match self {
436 UserControl::StreamBegin(_) => "stream begin",
437 UserControl::StreamEof(_) => "stream eof",
438 UserControl::StreamDry(_) => "stream dry",
439 UserControl::SetBufferLength { .. } => "set buffer length",
440 UserControl::StreamIsRecorded(_) => "stream is recorded",
441 UserControl::PingRequest(_) => "ping request",
442 UserControl::PingResponse(_) => "ping response",
443 }
444 }
445
446 #[must_use]
448 pub fn event_type(&self) -> u16 {
449 match self {
450 UserControl::StreamBegin(_) => event_type::STREAM_BEGIN,
451 UserControl::StreamEof(_) => event_type::STREAM_EOF,
452 UserControl::StreamDry(_) => event_type::STREAM_DRY,
453 UserControl::SetBufferLength { .. } => event_type::SET_BUFFER_LENGTH,
454 UserControl::StreamIsRecorded(_) => event_type::STREAM_IS_RECORDED,
455 UserControl::PingRequest(_) => event_type::PING_REQUEST,
456 UserControl::PingResponse(_) => event_type::PING_RESPONSE,
457 }
458 }
459
460 #[must_use]
466 pub fn to_message(&self) -> Message {
467 Message {
468 chunk_stream_id: CONTROL_CHUNK_STREAM_ID,
469 timestamp: 0,
470 message_type_id: msg_type::USER_CONTROL,
471 message_stream_id: CONTROL_MESSAGE_STREAM_ID,
472 payload: self
473 .try_to_bytes()
474 .expect("UserControl serialize_into only fails on a short buffer; try_to_bytes sizes it exactly"),
475 }
476 }
477}
478
479broadcast_common::impl_spec_display!(UserControl);
480
481impl<'a> Parse<'a> for UserControl {
482 type Error = RtmpError;
483
484 fn parse(bytes: &'a [u8]) -> Result<Self> {
485 if bytes.len() < EVENT_TYPE_LEN {
486 return Err(RtmpError::BufferTooShort {
487 need: EVENT_TYPE_LEN,
488 have: bytes.len(),
489 what: "user control event type",
490 });
491 }
492 let event = u16::from_be_bytes([bytes[0], bytes[1]]);
493 let data = &bytes[EVENT_TYPE_LEN..];
494 match event {
495 event_type::STREAM_BEGIN => Ok(UserControl::StreamBegin(need_u32(
496 data,
497 "stream begin event data",
498 )?)),
499 event_type::STREAM_EOF => Ok(UserControl::StreamEof(need_u32(
500 data,
501 "stream eof event data",
502 )?)),
503 event_type::STREAM_DRY => Ok(UserControl::StreamDry(need_u32(
504 data,
505 "stream dry event data",
506 )?)),
507 event_type::SET_BUFFER_LENGTH => {
508 if data.len() < 2 * U32_LEN {
509 return Err(RtmpError::BufferTooShort {
510 need: 2 * U32_LEN,
511 have: data.len(),
512 what: "set buffer length event data",
513 });
514 }
515 Ok(UserControl::SetBufferLength {
516 stream_id: read_u32_be(&data[0..U32_LEN]),
517 buffer_ms: read_u32_be(&data[U32_LEN..2 * U32_LEN]),
518 })
519 }
520 event_type::STREAM_IS_RECORDED => Ok(UserControl::StreamIsRecorded(need_u32(
521 data,
522 "stream is recorded event data",
523 )?)),
524 event_type::PING_REQUEST => Ok(UserControl::PingRequest(need_u32(
525 data,
526 "ping request event data",
527 )?)),
528 event_type::PING_RESPONSE => Ok(UserControl::PingResponse(need_u32(
529 data,
530 "ping response event data",
531 )?)),
532 _ => Err(RtmpError::Unsupported {
533 what: "user control event type (unrecognised)",
534 }),
535 }
536 }
537}
538
539impl Serialize for UserControl {
540 type Error = RtmpError;
541
542 fn serialized_len(&self) -> usize {
543 let data_len = match self {
544 UserControl::SetBufferLength { .. } => 2 * U32_LEN,
545 _ => U32_LEN,
546 };
547 EVENT_TYPE_LEN + data_len
548 }
549
550 fn serialize_into(&self, buf: &mut [u8]) -> Result<usize> {
551 let written = self.serialized_len();
552 if buf.len() < written {
553 return Err(RtmpError::BufferTooShort {
554 need: written,
555 have: buf.len(),
556 what: "user control event output",
557 });
558 }
559 buf[0..EVENT_TYPE_LEN].copy_from_slice(&self.event_type().to_be_bytes());
560 let data = &mut buf[EVENT_TYPE_LEN..written];
561 match *self {
562 UserControl::StreamBegin(stream_id)
563 | UserControl::StreamEof(stream_id)
564 | UserControl::StreamDry(stream_id)
565 | UserControl::StreamIsRecorded(stream_id)
566 | UserControl::PingRequest(stream_id)
567 | UserControl::PingResponse(stream_id) => {
568 data[0..U32_LEN].copy_from_slice(&stream_id.to_be_bytes());
569 }
570 UserControl::SetBufferLength {
571 stream_id,
572 buffer_ms,
573 } => {
574 data[0..U32_LEN].copy_from_slice(&stream_id.to_be_bytes());
575 data[U32_LEN..2 * U32_LEN].copy_from_slice(&buffer_ms.to_be_bytes());
576 }
577 }
578 Ok(written)
579 }
580}
581
582#[cfg(test)]
583mod tests {
584 use super::*;
585
586 fn message(message_type_id: u8, payload: Vec<u8>) -> Message {
587 Message {
588 chunk_stream_id: CONTROL_CHUNK_STREAM_ID,
589 timestamp: 0,
590 message_type_id,
591 message_stream_id: CONTROL_MESSAGE_STREAM_ID,
592 payload,
593 }
594 }
595
596 #[test]
599 fn try_to_message_rejects_invalid_chunk_size() {
600 assert!(matches!(
601 ProtocolControl::SetChunkSize(0).try_to_message(),
602 Err(RtmpError::Malformed { .. })
603 ));
604 assert!(
605 ProtocolControl::SetChunkSize(0x8000_0000)
606 .try_to_message()
607 .is_err()
608 );
609 assert_eq!(
610 ProtocolControl::SetChunkSize(4096)
611 .try_to_message()
612 .unwrap(),
613 ProtocolControl::SetChunkSize(4096).to_message()
614 );
615 }
616
617 #[test]
618 fn limit_type_round_trip_and_name() {
619 for (byte, lt, name) in [
620 (0u8, LimitType::Hard, "hard"),
621 (1, LimitType::Soft, "soft"),
622 (2, LimitType::Dynamic, "dynamic"),
623 ] {
624 let parsed = LimitType::from_u8(byte).unwrap();
625 assert_eq!(parsed, lt);
626 assert_eq!(parsed.to_u8(), byte);
627 assert_eq!(parsed.name(), name);
628 assert_eq!(parsed.to_string(), name);
629 }
630 }
631
632 #[test]
633 fn limit_type_out_of_range_is_malformed() {
634 assert!(matches!(
635 LimitType::from_u8(3),
636 Err(RtmpError::Malformed { .. })
637 ));
638 }
639
640 fn protocol_control_round_trip(pc: ProtocolControl) {
643 let bytes = pc.try_to_bytes().unwrap();
644 let parsed = ProtocolControl::from_payload(pc.message_type_id(), &bytes)
645 .unwrap()
646 .expect("known protocol control type id");
647 assert_eq!(parsed, pc);
648
649 let msg = message(pc.message_type_id(), bytes.clone());
651 let via_message = ProtocolControl::from_message(&msg).unwrap().unwrap();
652 assert_eq!(via_message, pc);
653 assert_eq!(via_message.try_to_bytes().unwrap(), bytes);
654 }
655
656 #[test]
657 fn set_chunk_size_round_trips() {
658 protocol_control_round_trip(ProtocolControl::SetChunkSize(4096));
659 }
660
661 #[test]
662 fn abort_round_trips() {
663 protocol_control_round_trip(ProtocolControl::Abort { chunk_stream_id: 7 });
664 }
665
666 #[test]
667 fn acknowledgement_round_trips() {
668 protocol_control_round_trip(ProtocolControl::Acknowledgement(1_048_576));
669 }
670
671 #[test]
672 fn window_ack_size_round_trips() {
673 protocol_control_round_trip(ProtocolControl::WindowAckSize(2_500_000));
674 }
675
676 #[test]
677 fn set_peer_bandwidth_round_trips_every_limit_type() {
678 for limit_type in [LimitType::Hard, LimitType::Soft, LimitType::Dynamic] {
679 protocol_control_round_trip(ProtocolControl::SetPeerBandwidth {
680 ack_window_size: 2_500_000,
681 limit_type,
682 });
683 }
684 }
685
686 #[test]
687 fn set_chunk_size_reserved_top_bit_rejected_on_parse() {
688 let bytes = 0x8000_1000u32.to_be_bytes().to_vec();
689 assert!(matches!(
690 ProtocolControl::from_payload(msg_type::SET_CHUNK_SIZE, &bytes),
691 Err(RtmpError::Malformed { .. })
692 ));
693 }
694
695 #[test]
696 fn set_chunk_size_zero_rejected() {
697 let bytes = 0u32.to_be_bytes().to_vec();
698 assert!(matches!(
699 ProtocolControl::from_payload(msg_type::SET_CHUNK_SIZE, &bytes),
700 Err(RtmpError::Malformed { .. })
701 ));
702 assert!(matches!(
703 ProtocolControl::SetChunkSize(0).serialize_into(&mut [0u8; 4]),
704 Err(RtmpError::Malformed { .. })
705 ));
706 }
707
708 #[test]
709 fn set_chunk_size_serialize_layout_matches_spec() {
710 let bytes = ProtocolControl::SetChunkSize(1).try_to_bytes().unwrap();
712 assert_eq!(bytes, vec![0x00, 0x00, 0x00, 0x01]);
713 }
714
715 #[test]
716 fn set_peer_bandwidth_serialize_layout_matches_spec() {
717 let bytes = ProtocolControl::SetPeerBandwidth {
718 ack_window_size: 0x0002_5000,
719 limit_type: LimitType::Dynamic,
720 }
721 .try_to_bytes()
722 .unwrap();
723 assert_eq!(bytes, vec![0x00, 0x02, 0x50, 0x00, 0x02]);
724 }
725
726 #[test]
727 fn set_peer_bandwidth_wrong_limit_type_mapping_would_fail() {
728 assert_eq!(LimitType::Hard.to_u8(), 0);
730 assert_eq!(LimitType::Dynamic.to_u8(), 2);
731 assert_ne!(LimitType::Hard.to_u8(), LimitType::Dynamic.to_u8());
732 }
733
734 #[test]
735 fn from_message_none_for_non_control_type_id() {
736 let msg = message(msg_type::AUDIO, vec![0u8; 4]);
737 assert!(ProtocolControl::from_message(&msg).unwrap().is_none());
738 }
739
740 #[test]
741 fn from_message_some_for_control_type_id() {
742 let msg = message(
743 msg_type::WINDOW_ACK_SIZE,
744 1_000_000u32.to_be_bytes().to_vec(),
745 );
746 assert!(ProtocolControl::from_message(&msg).unwrap().is_some());
747 }
748
749 #[test]
750 fn to_message_uses_control_csid_and_stream_id() {
751 let msg = ProtocolControl::SetChunkSize(4096).to_message();
752 assert_eq!(msg.chunk_stream_id, CONTROL_CHUNK_STREAM_ID);
753 assert_eq!(msg.message_stream_id, CONTROL_MESSAGE_STREAM_ID);
754 assert_eq!(msg.message_type_id, msg_type::SET_CHUNK_SIZE);
755 }
756
757 #[test]
758 fn protocol_control_display_matches_name() {
759 assert_eq!(
760 ProtocolControl::Acknowledgement(1).to_string(),
761 ProtocolControl::Acknowledgement(1).name()
762 );
763 }
764
765 fn user_control_round_trip(uc: UserControl) {
768 let bytes = uc.try_to_bytes().unwrap();
769 let parsed = UserControl::parse(&bytes).unwrap();
770 assert_eq!(parsed, uc);
771 assert_eq!(parsed.try_to_bytes().unwrap(), bytes);
772 }
773
774 #[test]
775 fn stream_begin_round_trips() {
776 user_control_round_trip(UserControl::StreamBegin(1));
777 }
778
779 #[test]
780 fn stream_begin_serialize_layout_matches_spec() {
781 let bytes = UserControl::StreamBegin(1).try_to_bytes().unwrap();
783 assert_eq!(bytes, vec![0x00, 0x00, 0x00, 0x00, 0x00, 0x01]);
784 }
785
786 #[test]
787 fn stream_eof_round_trips() {
788 user_control_round_trip(UserControl::StreamEof(1));
789 }
790
791 #[test]
792 fn stream_dry_round_trips() {
793 user_control_round_trip(UserControl::StreamDry(1));
794 }
795
796 #[test]
797 fn set_buffer_length_round_trips() {
798 user_control_round_trip(UserControl::SetBufferLength {
799 stream_id: 1,
800 buffer_ms: 3000,
801 });
802 }
803
804 #[test]
805 fn stream_is_recorded_round_trips() {
806 user_control_round_trip(UserControl::StreamIsRecorded(1));
807 }
808
809 #[test]
810 fn ping_request_round_trips() {
811 user_control_round_trip(UserControl::PingRequest(0x1234_5678));
812 }
813
814 #[test]
815 fn ping_response_round_trips() {
816 user_control_round_trip(UserControl::PingResponse(0x1234_5678));
817 }
818
819 #[test]
820 fn unrecognised_event_type_is_unsupported() {
821 let bytes = [0x00, 0x05, 0x00, 0x00, 0x00, 0x01];
823 assert!(matches!(
824 UserControl::parse(&bytes),
825 Err(RtmpError::Unsupported { .. })
826 ));
827 }
828
829 #[test]
830 fn user_control_event_type_wrong_mapping_would_fail() {
831 assert_eq!(UserControl::StreamBegin(0).event_type(), 0);
834 assert_eq!(UserControl::StreamEof(0).event_type(), 1);
835 }
836
837 #[test]
838 fn user_control_display_matches_name() {
839 assert_eq!(
840 UserControl::StreamBegin(1).to_string(),
841 UserControl::StreamBegin(1).name()
842 );
843 }
844
845 #[test]
846 fn to_message_uses_control_csid_and_user_control_type_id() {
847 let msg = UserControl::StreamBegin(1).to_message();
848 assert_eq!(msg.chunk_stream_id, CONTROL_CHUNK_STREAM_ID);
849 assert_eq!(msg.message_stream_id, CONTROL_MESSAGE_STREAM_ID);
850 assert_eq!(msg.message_type_id, msg_type::USER_CONTROL);
851 }
852}