Skip to content

Commit

Permalink
raise error on too many channels
Browse files Browse the repository at this point in the history
  • Loading branch information
james-rms committed Jan 7, 2025
1 parent d4818ca commit 74965a7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ pub enum McapError {
ChunkBufferTooLarge(u64),
#[error("length exceeds usize max: `{0}`")]
TooLong(u64),
#[error("cannot write more than 65335 channels to one MCAP")]
TooManyChannels,
#[error("cannot write more than 65334 schemas to one MCAP")]
TooManySchemas,
}

pub type McapResult<T> = Result<T, McapError>;
Expand Down
19 changes: 16 additions & 3 deletions rust/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,20 @@ impl<W: Write + Seek> Writer<W> {
}) {
return Ok(id);
}
while self.schemas.contains_right(&self.next_schema_id) {
if self.next_schema_id == u16::MAX {
return Err(McapError::TooManySchemas);
}
self.next_schema_id += 1;
}
let id = self.next_schema_id;
self.next_schema_id += 1;
self.write_schema(Schema {
id,
name: name.into(),
encoding: encoding.into(),
data: Cow::Owned(data.into()),
})?;
self.next_schema_id += 1;
Ok(id)
}

Expand Down Expand Up @@ -347,12 +353,19 @@ impl<W: Write + Seek> Writer<W> {
}) {
return Ok(id);
}
let id = self.next_channel_id;
self.next_channel_id += 1;
if schema_id != 0 && self.schemas.get_by_right(&schema_id).is_none() {
return Err(McapError::UnknownSchema(topic.into(), schema_id));
}

while self.channels.contains_right(&self.next_channel_id) {
if self.next_channel_id == u16::MAX {
return Err(McapError::TooManyChannels);
}
self.next_channel_id += 1;
}
let id = self.next_channel_id;
self.next_channel_id += 1;

self.write_channel(records::Channel {
id,
schema_id,
Expand Down

0 comments on commit 74965a7

Please sign in to comment.