Browse Source

Rename `buffer` into `length_buffer`

feature_link
Anton Tarasenko 3 years ago
parent
commit
f118767e3f
  1. 12
      src/link/mod.rs

12
src/link/mod.rs

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

Loading…
Cancel
Save