Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting
| key = (message_type, little_endian) | ||
| encoder = self._encoders.get(key) | ||
| if encoder is None: | ||
| encoder = self._message_encoder(little_endian=little_endian) # type: ignore[call-arg] | ||
| self._encoders[key] = encoder | ||
| # Cache is keyed by endianness, so the header stays valid. | ||
| else: | ||
| encoder.reset() |
There was a problem hiding this comment.
Avoid clearing encoder buffer while SerializedMessage holds memoryview
The encoder cache introduced in serialize_message_view reuses a single CdrEncoder per message type and immediately calls encoder.reset() when the encoder is reused (lines 53‑60). However, CdrEncoder.save() now returns a SerializedMessage containing a memoryview of the encoder’s internal bytearray. When serialize_message_view is called again while the previous SerializedMessage is still alive, BytesWriter.clear() attempts to resize the buffer and Python raises BufferError: Existing exports of data: object cannot be re-sized. Even simple sequential calls like serialize_message_view(msg1); serialize_message_view(msg2) crash, making the zero-copy API unusable. The encoder should not be cleared until the previous view is released or the data should be copied before reset.
Useful? React with 👍 / 👎.
No description provided.