Skip to content

[WIP] Rename MessageType::Req to MessageType::Cmd and update protocol#13

Closed
Copilot wants to merge 1 commit into
mainfrom
copilot/rename-message-type-req-to-cmd
Closed

[WIP] Rename MessageType::Req to MessageType::Cmd and update protocol#13
Copilot wants to merge 1 commit into
mainfrom
copilot/rename-message-type-req-to-cmd

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 22, 2026

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Original prompt

Goal

Rename MessageType::Req to MessageType::Cmd (command), use wire byte 'C' for new outgoing frames, and preserve backward compatibility by accepting legacy 'R' wire byte when parsing. Update tests, examples, and docs to prefer the new Cmd/'C' encoding and replace uses of MessageType::Req with MessageType::Cmd across the repo.

Why

  • The protocol will more often send commands than requests; "Cmd" is clearer.
  • To avoid breaking existing deployed devices, existing "R" frames must still be accepted by parsers; new frames and docs should use 'C'.

Scope of changes (what to modify)

  1. Add/modify header src/protocol/MessageType.h
  • Ensure the file defines the enum MessageType with members Data, Debug, Cmd, Done using underlying type uint8_t.
  • MessageType::Cmd should map to wire byte 'C'.
  • Provide helpers:
    • inline bool message_type_from_wire(uint8_t b, MessageType &out); // accepts 'C' and legacy 'R'
    • inline uint8_t message_type_to_wire(MessageType t); // emits 'C'
    • inline const char* message_type_to_string(MessageType t);

Include the exact content:

#ifndef TINYLINK_MESSAGETYPE_H
#define TINYLINK_MESSAGETYPE_H

#include <stdint.h>

namespace tinylink {

    enum class MessageType : uint8_t {
        Data  = 'D',
        Debug = 'g',
        Cmd   = 'C',  // renamed from Req -> Cmd, use 'C' on the wire
        Done  = 'K'
    };

    inline bool message_type_from_wire(uint8_t b, MessageType &out) {
        switch (b) {
            case static_cast<uint8_t>(MessageType::Data):  out = MessageType::Data;  return true;
            case static_cast<uint8_t>(MessageType::Debug): out = MessageType::Debug; return true;
            case static_cast<uint8_t>(MessageType::Cmd):   out = MessageType::Cmd;   return true;
            case 'R': /* legacy: Req */                    out = MessageType::Cmd;   return true;
            case static_cast<uint8_t>(MessageType::Done):  out = MessageType::Done;  return true;
            default: return false;
        }
    }

    inline uint8_t message_type_to_wire(MessageType t) {
        return static_cast<uint8_t>(t);
    }

    inline const char* message_type_to_string(MessageType t) {
        switch (t) {
            case MessageType::Data:  return "Data";
            case MessageType::Debug: return "Debug";
            case MessageType::Cmd:   return "Cmd";
            case MessageType::Done:  return "Done";
            default:                 return "Unknown";
        }
    }

} // namespace tinylink

#endif // TINYLINK_MESSAGETYPE_H
  1. Update any source files that reference MessageType::Req or the literal 'R'
  • Replace MessageType::Req with MessageType::Cmd.
  • Replace places that construct frames using the literal 'R' or expecting 'R' to use 'C' where appropriate (i.e., when creating/sending frames or documentation).
  • Leave parsing code that accepts 'R' untouched or ensure it uses message_type_from_wire so 'R' remains accepted.

Files to update (search & replace across repository):

  • src/TinyProtocol.h (if it defined Req originally) — update to include the new header or change the enum name.
  • Any examples in examples/ referencing Req or 'R'.
  • Tests in test/ that assert wire bytes or use MessageType::Req — update tests to expect 'C' for new frames and/or use message_type_from_wire.
  • README.md and other docs that mention "Request" or use 'R' should be updated to use "Cmd"/'C'. Add a short migration note: parsers accept both 'R' and 'C', but new code should use 'C'.
  1. Tests
  • Modify tests that build frames using MessageType::Req or 'R' to use MessageType::Cmd (and 'C').
  • Ensure tests that verify parsing of legacy 'R' frames continue to pass (keep or add a test that parsing accepts 'R' and maps to MessageType::Cmd).
  1. Examples & README
  • Update example sketches and README quick-start snippets to use MessageType::Cmd (or use tinylink::MessageType where appropriate) when calling link.send(...) if they previously used TYPE_REQ/TYPE_DATA constants.
  • Add a short migration note in README: "MessageType::Req was renamed to MessageType::Cmd and uses 'C' on the wire; parsers continue to accept 'R' for compatibility."
  1. Backwards compatibility and API notes
  • Keep mapping from 'R' to MessageType::Cmd in message_type_from_wire to maintain compatibility.
  • message_type_to_wire should return 'C' for MessageType::Cmd.
  • No change to the public TinyLink API surface beyond enum renaming; the PR will update call sites to the new name.

Commit & PR

  • Create a branch named fix/message-type-cmd.
  • Add/modify files as described above.
  • Run repository unit tests (native test runner) and ensure all tests pass.
  • Open a pull request titled "Rename MessageType::Req to MessageType::Cmd (wire 'C'), accept legacy 'R'" with a summary of changes, migration notes, and list of modified files.

Repository

petesramek/tiny-link

The following is the prior conversation context from the user's chat exploration (may be truncated):

Assistant: I'll start by fetching the reposi...

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

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.

2 participants