Skip to content

Commit 7ff0da9

Browse files
Refactor rename
1 parent c7aa00e commit 7ff0da9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/client/terrain/util/buffer_serializer.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ pub struct RLEToken {
44
count: u16,
55
}
66

7+
const TOKEN_BYTE_COUNT: usize = 3;
8+
const SYMBOL_OFFSET: usize = 0;
9+
const COUNT_OFFSET: usize = 1;
10+
const COUNT_LENGTH: usize = 2;
11+
712
pub fn serialize_buffer(array: Vec<u8>) -> Vec<u8> {
813
let tokens = tokenize_buffer(array);
914

@@ -49,15 +54,15 @@ pub fn deserialize_buffer(bytes: &[u8]) -> Vec<u8> {
4954

5055
let mut i = 0;
5156
while i < bytes.len() {
52-
let symbol = bytes[i];
53-
let count_bytes = &bytes[i + 1..i + 3];
57+
let symbol = bytes[i + SYMBOL_OFFSET];
58+
let count_bytes = &bytes[i + COUNT_OFFSET..i + COUNT_OFFSET + COUNT_LENGTH];
5459
let count = u16::from_le_bytes(count_bytes.try_into().unwrap());
5560

5661
for _ in 0..count {
5762
vec.push(symbol);
5863
}
5964

60-
i += 3;
65+
i += TOKEN_BYTE_COUNT;
6166
}
6267

6368
vec

0 commit comments

Comments
 (0)