|
|
|
@ -39,7 +39,7 @@ pub struct MessageReader {
|
|
|
|
|
is_broken: bool, |
|
|
|
|
reading_state: ReadingState, |
|
|
|
|
read_bytes: usize, |
|
|
|
|
buffer: [u8; 4], |
|
|
|
|
length_buffer: [u8; 4], |
|
|
|
|
current_message_length: usize, |
|
|
|
|
current_message: Vec<u8>, |
|
|
|
|
read_messages: VecDeque<String>, |
|
|
|
@ -63,7 +63,7 @@ impl MessageReader {
|
|
|
|
|
is_broken: false, |
|
|
|
|
reading_state: ReadingState::Head, |
|
|
|
|
read_bytes: 0, |
|
|
|
|
buffer: [0; 4], |
|
|
|
|
length_buffer: [0; 4], |
|
|
|
|
current_message_length: 0, |
|
|
|
|
// Will be recreated with `with_capacity` in `push_byte()`
|
|
|
|
|
current_message: Vec::new(), |
|
|
|
@ -88,18 +88,18 @@ impl MessageReader {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ReadingState::ReceivedBytes => { |
|
|
|
|
self.buffer[self.read_bytes] = input; |
|
|
|
|
self.length_buffer[self.read_bytes] = input; |
|
|
|
|
self.read_bytes += 1; |
|
|
|
|
if self.read_bytes >= UE_RECEIVED_FIELD_SIZE { |
|
|
|
|
self.ue_received_bytes += array_of_u8_to_u32(self.buffer) as u64; |
|
|
|
|
self.ue_received_bytes += array_of_u8_to_u32(self.length_buffer) as u64; |
|
|
|
|
self.change_state(ReadingState::Head); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ReadingState::Length => { |
|
|
|
|
self.buffer[self.read_bytes] = input; |
|
|
|
|
self.length_buffer[self.read_bytes] = input; |
|
|
|
|
self.read_bytes += 1; |
|
|
|
|
if self.read_bytes >= UE_LENGTH_FIELD_SIZE { |
|
|
|
|
self.current_message_length = array_of_u8_to_u32(self.buffer) as usize; |
|
|
|
|
self.current_message_length = array_of_u8_to_u32(self.length_buffer) as usize; |
|
|
|
|
self.change_state(ReadingState::Payload); |
|
|
|
|
if self.current_message_length > MAX_UE_MESSAGE_LENGTH { |
|
|
|
|
self.is_broken = true; |
|
|
|
|