Skip to content

Commit a46f881

Browse files
committed
Clarify documentation considering resource comparisions
1 parent 168d497 commit a46f881

File tree

8 files changed

+52
-9
lines changed

8 files changed

+52
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "godot-mcap"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2024"
55
license = "MIT"
66

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func _on_replay_message(msg: MCAPMessage) -> void:
202202
```
203203

204204

205-
## API highlights
205+
## API Overview
206206

207207
Writer: `MCAPWriter` (RefCounted)
208208
- `open(path: String) -> bool`
@@ -243,6 +243,22 @@ Types (Resources)
243243
- Summary/index wrappers: `MCAPSummary`, `MCAPFooter`, `MCAPChunkIndex`, `MCAPMessageIndexEntry`, `MCAPAttachmentIndex`, `MCAPMetadataIndex`
244244

245245

246+
### Object identity and equality
247+
248+
When reading, this extension constructs new Godot Resource instances every time:
249+
250+
- Each call to `MCAPReader.messages()`, `raw_messages()`, `attachments()`, `metadata_entries()`, or when iterating via `MCAPMessageIterator`, creates new `MCAPMessage`, `MCAPChannel`, `MCAPSchema`, `MCAPAttachment`, and `MCAPMetadata` objects.
251+
- The same logical channel or schema may therefore be represented by different Resource instances across calls. Do not compare objects by identity/reference.
252+
253+
Compare by stable properties instead:
254+
255+
- Channels: compare `channel.id` (preferred) or `channel.topic`.
256+
- Schemas: compare `schema.id` (preferred), optionally with `schema.name`/`schema.encoding`.
257+
- Messages: compare `message.channel.id` together with `message.sequence` or `message.log_time`.
258+
- Attachments: compare a tuple such as `(name, log_time)` or use offsets if you maintain them externally.
259+
- Metadata: compare `name` (and/or specific keys in `metadata`).
260+
261+
246262
## Compression features
247263

248264
By default, both `zstd` and `lz4` features are enabled and passed through to the underlying `mcap` crate.

src/reader/iterator.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use std::collections::HashSet;
1414
/// - Iterates messages in log-time order across chunks and channels.
1515
/// - Supports optional per-channel filtering and multiple seek helpers.
1616
/// - Requires a Summary section in the file.
17+
/// - Identity note: messages and their nested channel/schema are newly constructed per iteration step.
18+
/// Compare by fields (e.g. `msg.channel.id`, `msg.sequence`, `msg.log_time`) rather than by object identity.
1719
///
1820
/// Usage (GDScript)
1921
/// ```gdscript

src/reader/mcap_reader.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ use std::sync::Arc;
2222
/// - Loads an MCAP file into memory for fast random access and optional indexed queries.
2323
/// - Provides direct streaming of messages (`messages`, `raw_messages`) and an indexed iterator (`stream_messages_iterator`).
2424
/// - Exposes attachment and metadata access via summary indexes when present.
25+
/// - Identity note: every read constructs new Godot Resources (`MCAPMessage`, `MCAPChannel`, `MCAPSchema`, etc.).
26+
/// Do not rely on instance equality across calls; compare by stable fields instead (e.g. `channel.id`, `schema.id`).
2527
///
2628
/// Memory & I/O
2729
/// - When opening from a path, the reader first tries to memory-map (mmap) the file for zero-copy random access.

src/reader/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ mod mcap_reader;
55
mod replay;
66

77
pub use iterator::MCAPMessageIterator;
8+
#[allow(unused_imports)]
89
pub use mcap_reader::MCAPReader;
10+
#[allow(unused_imports)]
911
pub use replay::{MCAPReplay, ProcessingMode};

src/reader/replay.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl MCAPReplay {
216216
Some(r) => r.clone(),
217217
None => return false,
218218
};
219-
// Build a fresh iterator from reader
219+
// Build a new iterator from reader
220220
let mut it = reader.bind().stream_messages_iterator();
221221
// Fast-path single-channel filter
222222
if let Some(set) = &self.filter_channels {

src/types.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ pub struct MCAPSummary {
159159
pub metadata_indexes: Array<Gd<MCAPMetadataIndex>>,
160160
}
161161

162-
/// Describes a schema used by one or more [MCAPChannel]s in an MCAP file
162+
/// Describes a schema used by one or more [MCAPChannel]s in an MCAP file.
163+
///
164+
/// Identity note: Instances returned by the reader are newly constructed on
165+
/// each call/iteration. Do not compare by object identity/reference; prefer
166+
/// comparing by stable fields such as `id` (and optionally `name`/`encoding`).
163167
#[derive(GodotClass)]
164168
#[class(no_init, base=Resource)]
165169
pub struct MCAPSchema {
@@ -177,7 +181,11 @@ pub struct MCAPSchema {
177181
pub data: PackedByteArray,
178182
}
179183

180-
/// Describes a channel which [Message]s are published to in an MCAP file
184+
/// Describes a channel which [Message]s are published to in an MCAP file.
185+
///
186+
/// Identity note: Reader methods and iterators construct new `MCAPChannel`
187+
/// instances as needed. Compare channels by `id` (preferred) or by `topic`,
188+
/// not by object identity.
181189
#[derive(GodotClass)]
182190
#[class(no_init, base=Resource)]
183191
pub struct MCAPChannel {
@@ -198,7 +206,12 @@ pub struct MCAPChannel {
198206
pub metadata: Dictionary,
199207
}
200208

201-
/// An event in an MCAP file, published to a [MCAPChannel]
209+
/// An event in an MCAP file, published to a [MCAPChannel].
210+
///
211+
/// Identity note: The embedded `channel` Resource is newly constructed and may
212+
/// be a distinct instance from channels returned by other reads/iterations.
213+
/// Compare messages by fields like `channel.id` together with `sequence` or
214+
/// `log_time`, rather than by object identity.
202215
#[derive(GodotClass)]
203216
#[class(no_init, base=Resource)]
204217
pub struct MCAPMessage {
@@ -219,7 +232,11 @@ pub struct MCAPMessage {
219232
pub data: PackedByteArray,
220233
}
221234

222-
/// An attachment and its metadata in an MCAP file
235+
/// An attachment and its metadata in an MCAP file.
236+
///
237+
/// Identity note: Attachments returned by the reader are newly constructed.
238+
/// For equality, prefer comparing by content properties such as `(name, log_time)`
239+
/// or your own external keys, rather than by object identity.
223240
#[derive(GodotClass)]
224241
#[class(no_init, base=Resource)]
225242
pub struct MCAPAttachment {
@@ -258,7 +275,11 @@ pub struct MCAPMessageHeader {
258275
pub publish_time: i64,
259276
}
260277

261-
/// MCAP Metadata record
278+
/// MCAP Metadata record.
279+
///
280+
/// Identity note: Metadata objects are newly constructed on each read. For
281+
/// equality, compare by `name` (and relevant `metadata` keys) rather than by
282+
/// object identity.
262283
#[derive(GodotClass)]
263284
#[class(no_init, base=Resource)]
264285
pub struct MCAPMetadata {

0 commit comments

Comments
 (0)