GerardGao commented on code in PR #399:
URL: https://github.com/apache/dubbo-go-hessian2/pull/399#discussion_r3853420136
##########
null_test.go:
##########
@@ -132,5 +134,39 @@ func TestNullFieldStruct(t *testing.T) {
if e.Buffer() == nil {
t.Fail()
}
- assertEqual([]byte("NNNNN"), e.buffer[len(e.buffer)-5:], t)
+ assertEqual([]byte("NNNNNN"), e.buffer[len(e.buffer)-6:], t)
+}
+
+// Int64PtrFieldStruct verifies that a *int64 struct field is encoded as a
+// hessian long, so that a java consumer can deserialize it into a
+// java.lang.Long field, see apache/dubbo-go#2410.
+type Int64PtrFieldStruct struct {
+ Total *int64
+}
+
+func (*Int64PtrFieldStruct) JavaClassName() string {
+ return "Int64PtrFieldStruct"
+}
+
+func TestInt64PtrFieldStructEncode(t *testing.T) {
+ total := int64(12345)
+ e := NewEncoder()
+ if err := e.Encode(&Int64PtrFieldStruct{Total: &total}); err != nil {
+ t.Fatalf("encode Int64PtrFieldStruct: %v", err)
+ }
+ // 0x3c 0x30 0x39 is the hessian short-form long encoding of 12345
+ assertEqual([]byte{0x3c, 0x30, 0x39}, e.buffer[len(e.buffer)-3:], t)
+
+ d := NewDecoder(e.Buffer())
Review Comment:
@AlexStocks thanks for the review. Added the independent Java consumer
regression in 36d20ca:
- new `test.model.Int64ThenString` POJO with a `Long` followed by a
`String`, mirroring the `Int64ThenStringStruct` Go struct;
- `customArgInt64ThenString_nonNull` / `customArgInt64ThenString_nil` decode
the Go-encoded bytes with hessian-lite (same version as the #2410 report) and
assert **both** fields for nil and non-nil pointers;
- verified the test actually catches the legacy misalignment: a byte stream
simulating the old skip-nil-field behavior makes the Java consumer fail, while
correct encoding passes.
The byte-level assertions in `TestInt64PtrFieldStructEncode` are kept as
fast protocol unit tests.
--
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]