Skip to content

Unified packet parsing to use BufferReader#309

Merged
zjs81 merged 6 commits into
devfrom
dev-unifiedData
Mar 24, 2026
Merged

Unified packet parsing to use BufferReader#309
zjs81 merged 6 commits into
devfrom
dev-unifiedData

Conversation

@wel97459

Copy link
Copy Markdown
Collaborator

This pull request refactors and improves binary frame parsing and error handling in the MeshCoreConnector class, with a focus on safer, more consistent string extraction and robust parsing logic. It also introduces new fields for storage usage, improves error reporting, and updates protocol constants to support signed messages. The changes enhance code maintainability, reliability, and future extensibility.

Parsing and String Extraction Improvements

  • Replaced all uses of readString() with the safer readCString() method for extracting null-terminated strings, ensuring correct handling of C-style strings throughout the codebase. (lib/connector/meshcore_connector.dart, lib/connector/meshcore_protocol.dart) [1] [2] [3] [4] [5] [6] [7]
  • Refactored the contact message text parser to use BufferReader for sequential parsing, with explicit handling for signed messages and robust error catching. (lib/connector/meshcore_protocol.dart)

Frame Parsing and Error Handling

  • Refactored multiple frame handlers to use BufferReader for sequential binary parsing, improving readability and reducing manual offset calculations. Added comprehensive try/catch blocks to log errors and gracefully handle malformed frames. (lib/connector/meshcore_connector.dart) [1] [2] [3] [4] [5] [6] [7] [8] [9]

Protocol and Data Structure Updates

  • Added support for signed text messages by introducing the txtTypeSigned constant and updating message parsing logic to handle signatures. Also added signatureSize constant. (lib/connector/meshcore_protocol.dart) [1] [2] [3]
  • Introduced new fields and getters for storageUsedKb and storageTotalKb to track device storage usage. (lib/connector/meshcore_connector.dart) [1] [2] [3]

Utility and Helper Changes

  • Replaced repeated manual conversions of ack hashes to hex strings with a new ackHashToHex utility function for consistency. (lib/connector/meshcore_connector.dart, lib/connector/meshcore_protocol.dart) [1] [2] [3] [4] [5]

Miscellaneous

  • Added missing import for Flutter widgets to meshcore_protocol.dart. (lib/connector/meshcore_protocol.dart)

…r handling

- Added storageUsedKb and storageTotalKb properties to MeshCoreConnector.
- Updated battery and storage frame parsing with improved error handling.
- Refactored log RX data handling to use BufferReader for better readability and error management.
- Enhanced message parsing in ChannelMessage and Message classes to utilize BufferReader.
- Introduced new text type for signed messages in meshcore_protocol.dart.
- Updated BLE debug log screen to use BufferReader for payload parsing.
- Refactored message retry service to handle ACK hashes as integers instead of Uint8List.
- Improved message storage serialization and deserialization to accommodate new expectedAckHash type.
- Added wasPulled property to Contact model for better state management.
@wel97459

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@zjs81

zjs81 commented Mar 22, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 767dc1164e

ℹ️ 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 "@codex address that feedback".

Comment thread lib/models/channel_message.dart
Comment thread lib/storage/message_store.dart
Comment thread lib/connector/meshcore_connector.dart Outdated
@wel97459 wel97459 changed the base branch from dev to main March 23, 2026 15:16
Copilot AI review requested due to automatic review settings March 23, 2026 17:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors MeshCore binary parsing to use BufferReader more consistently (including C-string handling), updates ACK-hash handling to use uint32-style ints, and adds new UI flows for privacy/telemetry controls and clearing chats.

Changes:

  • Refactors multiple protocol/frame parsers to BufferReader + readCString and adds utility helpers like ackHashToHex.
  • Changes ACK hash representation from Uint8List(4) to int across retry logic, message models, persistence, and tests.
  • Adds privacy/telemetry UI settings, per-contact telemetry flags, chat/channel clear actions, and telemetry screen updates.

Reviewed changes

Copilot reviewed 54 out of 54 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
test/services/retry_and_protocol_test.dart Updates tests for ACK hash now represented as int + hex formatting.
lib/widgets/room_login_dialog.dart Caches resolved contact index for faster lookups.
lib/widgets/repeater_login_dialog.dart Caches resolved contact index for faster lookups.
lib/widgets/path_management_dialog.dart Caches resolved contact index for faster lookups.
lib/storage/message_store.dart Persists expectedAckHash as an int instead of base64 bytes.
lib/services/message_retry_service.dart Migrates retry/ACK matching to int ACK hashes.
lib/screens/telemetry_screen.dart Updates telemetry parsing/requests and adds chat-contact telemetry handling.
lib/screens/settings_screen.dart Replaces privacy-mode toggle dialog with a richer privacy/telemetry settings dialog.
lib/screens/repeater_status_screen.dart Caches resolved repeater index for faster lookups.
lib/screens/repeater_settings_screen.dart Caches resolved repeater index for faster lookups.
lib/screens/repeater_hub_screen.dart Updates TelemetryScreen navigation signature.
lib/screens/repeater_cli_screen.dart Caches resolved repeater index for faster lookups.
lib/screens/neighbors_screen.dart Caches resolved repeater index for faster lookups.
lib/screens/contacts_screen.dart Switches favorite toggle to setContactFlags(...).
lib/screens/chat_screen.dart Adds menu actions (info/settings/telemetry/clear chat) + contact settings UI.
lib/screens/channel_chat_screen.dart Adds “clear chat” menu action for channels.
lib/screens/ble_debug_log_screen.dart Refactors payload summaries to BufferReader parsing.
lib/models/message.dart Updates expectedAckHash type and message parsing to BufferReader.
lib/models/contact.dart Adds wasPulled and telemetry flag getters on Contact.
lib/models/channel_message.dart Refactors channel message parsing to BufferReader.
lib/models/channel.dart Refactors channel parsing to BufferReader/C-strings.
lib/l10n/app_en.arb Adds strings for privacy/telemetry/contact settings UI.
lib/l10n/app_de.arb Adds strings for privacy/telemetry/contact settings UI.
lib/l10n/app_es.arb Adds strings for privacy/telemetry/contact settings UI.
lib/l10n/app_fr.arb Adds strings for privacy/telemetry/contact settings UI.
lib/l10n/app_it.arb Adds strings for privacy/telemetry/contact settings UI.
lib/l10n/app_nl.arb Adds strings for privacy/telemetry/contact settings UI.
lib/l10n/app_pl.arb Adds strings for privacy/telemetry/contact settings UI.
lib/l10n/app_pt.arb Adds strings for privacy/telemetry/contact settings UI.
lib/l10n/app_ru.arb Adds strings for privacy/telemetry/contact settings UI.
lib/l10n/app_sk.arb Adds strings for privacy/telemetry/contact settings UI.
lib/l10n/app_sl.arb Adds strings for privacy/telemetry/contact settings UI.
lib/l10n/app_sv.arb Adds strings for privacy/telemetry/contact settings UI.
lib/l10n/app_uk.arb Adds strings for privacy/telemetry/contact settings UI.
lib/l10n/app_zh.arb Adds strings for privacy/telemetry/contact settings UI.
lib/l10n/app_bg.arb Adds strings and updates placeholders (but see comment).
lib/l10n/app_localizations.dart Exposes new localization keys in the base localization API.
lib/l10n/app_localizations_en.dart Implements new localization keys (en).
lib/l10n/app_localizations_de.dart Implements new localization keys (de).
lib/l10n/app_localizations_es.dart Implements new localization keys (es).
lib/l10n/app_localizations_fr.dart Implements new localization keys (fr).
lib/l10n/app_localizations_it.dart Implements new localization keys (it).
lib/l10n/app_localizations_nl.dart Implements new localization keys (nl).
lib/l10n/app_localizations_pl.dart Implements new localization keys (pl).
lib/l10n/app_localizations_pt.dart Implements new localization keys (pt).
lib/l10n/app_localizations_ru.dart Implements new localization keys (ru).
lib/l10n/app_localizations_sk.dart Implements new localization keys (sk).
lib/l10n/app_localizations_sl.dart Implements new localization keys (sl).
lib/l10n/app_localizations_sv.dart Implements new localization keys (sv).
lib/l10n/app_localizations_uk.dart Implements new localization keys (uk).
lib/l10n/app_localizations_zh.dart Implements new localization keys (zh).
lib/l10n/app_localizations_bg.dart Implements new localization keys (bg).
lib/connector/meshcore_protocol.dart Adds/updates protocol constants, parsing helpers, and telemetry request builder.
lib/connector/meshcore_connector.dart Updates frame handling/parsing, adds storage/telemetry params, adds clear-chat helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/models/channel_message.dart
Comment thread lib/connector/meshcore_protocol.dart
Comment thread lib/storage/message_store.dart
Comment thread lib/models/contact.dart
Comment thread lib/models/channel_message.dart Outdated
Comment thread lib/connector/meshcore_connector.dart Outdated
Comment thread lib/connector/meshcore_connector.dart
Comment thread lib/l10n/app_bg.arb Outdated
Comment thread lib/screens/settings_screen.dart
@wel97459 wel97459 changed the base branch from main to dev March 23, 2026 18:16
wel97459 and others added 2 commits March 23, 2026 11:18
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@wel97459

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@zjs81 zjs81 merged commit 1c376b0 into dev Mar 24, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants