shubhamk0205 opened a new pull request, #405:
URL: https://github.com/apache/dubbo-go-hessian2/pull/405
**What this PR does**:
A named basic type like `type Status string` or `type Code int64` was
written as nothing by `Encode`, with no error. In a struct that shifts every
later field, so Java reads wrong values. A named `bool` (and `**bool`) panicked.
- `Encode`: a named string/int/uint/float value is converted to its unnamed
type and encoded the same way, so `Status("ok")` gives the same bytes as
`"ok"`. The bool case now reads the value with reflection instead of
`v.(*bool)`.
- Decode: `SetValue` can now set a decoded string or bool into a named
string or bool field, and `SetValueToPtrDest` handles pointer fields like
`*Status` / `*Code` / `*Flag`. Both panicked in `reflect.Set` before. Plain
named int/float fields already worked.
**Which issue(s) this PR fixes**:
Fixes #404
**Special notes for your reviewer**:
Tests:
- `TestEncodeNamedBasicTypes`: each named kind (plus pointers, nil pointers
and `**bool`) encodes to the same bytes as the plain type.
- `TestNamedTypesStruct`: a struct with named string/int64/bool/float64
fields, pointer-to-named fields, and a normal `Name` field after them. Go round
trip, Java reading what Go wrote (`customArgNamedTypes`, like #399), and Go
reading what Java wrote (`customReplyNamedTypes`).
Both tests fail on master (empty bytes / panic). Named int32 was already
fine and is not touched.
How I tested, with JDK 8 + Go 1.25 like CI: `mvn test -f
test_hessian/pom.xml`, `mvn package -f test_dubbo/pom.xml`, `go fmt` +
imports-formatter (no changes), golangci-lint v2.4.0 (0 issues), `go test ./...
-race` and the benchmark run all pass. I didn't run the license-checker step,
but the new Java file has the same header as the others.
**Does this PR introduce a user-facing change?**:
```release-note
Named basic types (e.g. `type Status string`, `type Flag bool`) are now
encoded like their underlying types instead of being skipped or panicking, and
can be decoded into struct fields of those types (including pointer fields like
`*Status`). Slices of named types (`[]Status`) are not changed.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]