Add missing list attribute#9
Conversation
📝 WalkthroughWalkthroughRenamed the output API from Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Protocol
participant Attribute
participant Transport
participant Serial
Client->>Protocol: request: cmdAttributes / describe
Protocol->>Attribute: describe(out)
Attribute->>Transport: out.write(string/int/bool)
Transport->>Serial: print(...) / println(...)
Serial-->>Transport: ok
Transport-->>Attribute: written
Attribute-->>Protocol: done
Protocol-->>Client: response complete
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/SlvCtrlProtocol.h`:
- Around line 289-302: Describe currently emits unquoted string options (in
describe/ writeOption_ for the string-specialization), which makes outputs like
rw[str(off|on|auto)] ambiguous when options contain '|', ')' or ']'; update the
logic so string options are safely quoted or escaped per the protocol: either
wrap option values in quotes (e.g., "value") or escape special chars before
writing; implement this in writeOption_ (or the code path used by describe for T
!= int32_t) so all entries in options_ are emitted quoted/escaped and include
tests to ensure describe produces rw[str("off"|"on"|"a|b")]-style output
matching the protocol rule.
🧹 Nitpick comments (2)
examples/basic/src/main.cpp (1)
38-42: Inconsistent declaration style: missingstaticand&operator.
baudAttrandmodeAttrare missing thestatickeyword, unlike all other attribute declarations on lines 33–36. Similarly, function pointers are passed without the&prefix (e.g.,getBaudvs.&getSpeed). Both forms are valid C++, but the inconsistency in example code may confuse users.Proposed fix for consistency
-ListAttribute<int32_t> baudAttr("baud", getBaud, nullptr, kBaudOpts); +static ListAttribute<int32_t> baudAttr("baud", &getBaud, nullptr, kBaudOpts); static const char* kModeOpts[] = { "off", "on", "auto" }; -ListAttribute<const char*> modeAttr("mode", getMode, setMode, kModeOpts); +static ListAttribute<const char*> modeAttr("mode", &getMode, &setMode, kModeOpts);src/SlvCtrlProtocol.h (1)
241-263:ListAttributeconstructor: stores a pointer to a caller-owned array — document the lifetime requirement.The constructor captures
optionsas a rawconst T*. The caller must ensure the array outlives theListAttributeinstance. In the example code, file-scope arrays satisfy this, but a stack-local array passed here would be a use-after-free. Consider adding a brief comment on the lifetime contract.Suggested doc comment
public: + // `options` must outlive this attribute (pointer is stored, not copied). template <size_t N> ListAttribute(const char* name,
Summary by CodeRabbit
New Features
Refactor
Chores