✨ Introduce v18 - #5
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces protocol-versioned parameter parsing by wiring a ParameterParser into reader.Reader via construction-time options, and scaffolds a new (currently stubbed) v18 parameters package.
Changes:
- Add
reader.ParameterParser+reader.Optionsand update reader construction call sites to provide a versioned parameter decoder. - Refactor Protocol16 parameters into
internal/parameters/v16and update tests/imports accordingly. - Add a new
internal/parameters/v18package and exposeNewParserV16()/NewParserV18()constructors.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| reader.go | Removes top-level Reader re-export/wrapper API. |
| parser.go | Adds versioned constructors and wires v16/v18 parameter parsers into the underlying reader. |
| internal/reader/reader.go | Introduces ParameterParser + Options and updates NewReader signature accordingly. |
| internal/types/parameter.go | Formatting-only change. |
| internal/session/session_test.go | Updates reader construction to pass v16 parameter parser options. |
| internal/reader/reader_test.go | Updates reader construction to pass v16 parameter parser options. |
| internal/parameters/v16/parameters.go | Refactors v16 parsing to implement reader.ParameterParser (but currently breaks receiver state/hook emission). |
| internal/parameters/v16/string.go | Moves Protocol16 string parsing into package v16. |
| internal/parameters/v16/arrays.go | Moves Protocol16 array parsing into package v16. |
| internal/parameters/v16/dicts.go | Moves Protocol16 dict/hashtable parsing into package v16. |
| internal/parameters/v16/*_test.go | Updates imports/reader construction; still uses the old Parse call shape. |
| internal/parameters/v18/parameters.go | Adds v18 parameter parser stub (currently returns nil without reading). |
| internal/hooks/hooks_test.go | Updates imports/reader construction but still calls parameter parse with the old signature. |
| internal/command/sendReliable/reliable.go | Switches reliable parameter parsing to use the configured reader.ParameterParser. |
| internal/command/sendReliable/reliable_test.go | Updates reader construction to pass v16 parameter parser options. |
| internal/command/command_test.go | Updates reader construction to pass v16 parameter parser options. |
Comments suppressed due to low confidence (4)
internal/parameters/v16/dicts_test.go:97
p.Parse(reader)is still using the old 1-arg API, butv16.Parameter.Parsenow requires anout *types.Parameterargument. Update these tests to pass an output struct (or add a wrapper) so the suite compiles and the expected dictionary/hashtable values are asserted against the parsed output.
internal/parameters/v16/parameters.go:58Parameter.Parsepopulates theoutparameter but never updates the receiver (p.Parameter), yetemitsendsp.Parameterto hooks. This meansOnParameterhooks will receive zero-values and callers relying onp.Value/p.IDwon't see parsed data. Update the receiver to mirrorout(or changeemitto emitout) before emitting hooks.
internal/parameters/v16/parameters_test.go:173- This test still calls
param.Parse(reader)with the old 1-arg signature, butv16.Parameter.Parsenow requires anout *types.Parameterargument. This won't compile and also doesn't populateparam.Valueunless the receiver is updated. Adjust the tests to pass an output struct (or restore a 1-arg wrapper) and assert against that output.
internal/parameters/v16/arrays_test.go:57 p.Parse(reader)is still using the previous 1-arg API, butv16.Parameter.Parsenow requires anout *types.Parameterargument. Update these tests to pass an output parameter (or provide a compatibility wrapper) so they compile and validate the parsed value correctly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 31 out of 32 changed files in this pull request and generated 19 comments.
Comments suppressed due to low confidence (1)
internal/parameters/v16/parameters.go:50
Parsepopulatesout, butemitsendsp.Parameter(the receiver’s embedded field), which is never updated here. As a result, hooks will receive a zero-value parameter. Update the receiver (p.ParameterHeader/p.Value) before emitting, or changeemitto send theoutvalue.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 40 out of 41 changed files in this pull request and generated 16 comments.
Comments suppressed due to low confidence (6)
internal/command/reliable/reliable.go:62
Parsereturns(nil, nil)whenheader.Type >= ExchangeKeys, which will also matchOperationResponse (0x07)and causes the caller to treat parsing as successful while the reader cursor is left mid-command. This will desynchronize subsequent command parsing. This condition should likely beheader.Type == ExchangeKeys(or explicitly handle each type) and, if you intentionally skip parsing, you still need to consume the remaining bytes for this command.
internal/parameters/v16/parameters.go:61Parsepopulatesout, butemitsendsp.Parameter(the receiver's embedded field), which is never updated here. As a result, sync/async parameter hooks will receive a zero-value/stale parameter instead of the parsed one. Either assignp.ParameterHeader/p.Valuebefore emitting, or changeemitto take and emit*out.
internal/parameters/v16/parameters_test.go:192- The failure message uses
param.Value/param.Valueeven though assertions compareout.Value. Sinceparamisn't populated anymore, this error output will be misleading; useout.Value/out.Valuein the formatted message.
internal/command/reliable/reliable.go:120 - In the default branch,
reader.ReadBytes(int(length) - 14)ignores the returned error and can pass a negative length (iflength < 14), which will panic due to an invalid slice range. Compute the remaining bytes based on the current cursor (e.g.,remaining := int(length) - reader.Cursor) after validatinglengthagainst the command header size, then read and handle any error.
internal/command/reliable/reliable.go:111 - Return-code and debug-message reads ignore errors (
ReadInt16LittleEndian(),ReadByte()), which can silently corrupt cursor position on truncated packets. Capture and return these errors so parsing fails safely and stays synchronized.
internal/command/reliable/reliable_test.go:25 - This test calls
reliable.Parse(ctx)butreliable.Parsenow requires alength uint32argument. As written, this file will not compile; pass the appropriate length (e.g.,uint32(len(payload))if the payload is the full reliable message, or the command length if testing the command path).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
♻️ Remove type parameter use generics
♻️ Add iterators
V18 refacto optimization
No description provided.