mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-04 02:24:12 +02:00
remove some slice indexing
This commit is contained in:
parent
e0ec7db236
commit
1d71aa8ba6
9 changed files with 42 additions and 33 deletions
|
|
@ -197,12 +197,15 @@ impl PacketEntity {
|
|||
}
|
||||
|
||||
pub fn get_baseline_props<'a>(&self, parser_state: &'a ParserState) -> Cow<'a, [SendProp]> {
|
||||
let Some(send_table) = parser_state.send_tables.get(usize::from(self.server_class)) else {
|
||||
return Cow::default();
|
||||
};
|
||||
parser_state
|
||||
.get_baseline(
|
||||
self.baseline_index,
|
||||
self.entity_index,
|
||||
self.server_class,
|
||||
&parser_state.send_tables[usize::from(self.server_class)],
|
||||
send_table,
|
||||
self.delta.is_some(),
|
||||
)
|
||||
.unwrap_or_default()
|
||||
|
|
|
|||
|
|
@ -613,7 +613,13 @@ fn write_table_entry(
|
|||
if let Some((history_index, history_count)) = history_item {
|
||||
history_index.write_sized(stream, 5)?;
|
||||
history_count.write_sized(stream, 5)?;
|
||||
let diff_bytes = &text.as_bytes()[history_count..];
|
||||
let diff_bytes =
|
||||
text.as_bytes()
|
||||
.get(history_count..)
|
||||
.ok_or(BitError::IndexOutOfBounds {
|
||||
pos: history_count,
|
||||
size: text.len(),
|
||||
})?;
|
||||
stream.write_bytes(diff_bytes)?;
|
||||
0u8.write(stream)?; // writing the string as bytes doesn't add the null terminator
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -97,14 +97,10 @@ impl ParseBitSkip<'_> for TempEntitiesMessage {
|
|||
|
||||
impl Encode for TempEntitiesMessage {
|
||||
fn encode(&self, stream: &mut BitWriteStream<LittleEndian>, state: &ParserState) -> Result<()> {
|
||||
let count = if self.events.len() == 1 {
|
||||
if self.events[0].reliable {
|
||||
0
|
||||
} else {
|
||||
1
|
||||
}
|
||||
} else {
|
||||
self.events.len() as u8
|
||||
let count = match (self.events.len(), self.events.first()) {
|
||||
(1, Some(event)) if event.reliable => 0,
|
||||
(1, _) => 1,
|
||||
(len, _) => len as u8,
|
||||
};
|
||||
count.write(stream)?;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue