apache / dubbo-go-hessian2

caucho hessian2 implementation in Go for [apache/dubbo-go](https://github.com/apache/dubbo-go) which is compatible with [dubbo-hessian-lite](https://github.com/apache/dubbo-hessian-lite)
Apache License 2.0
209 stars 113 forks source link

Java ReferenceConfig方式调用 dubbogo 方法,负责的结构体解析不了 #301

Closed xfstart07 closed 2 years ago

xfstart07 commented 2 years ago

What happened:

DubboCodec.decodeRequest 方法中打印 requestBody

requestBody类似 "`NNNNNNNNNNNNNNNNNNNNNNNNNNNNTNN123456NNNNNasdfghH ", 有些字段是 N ,解析的时候不报错,但是有些传了的字段不会读取出来值

Java(DubboJava 版本 2.7) 数据类如下

https://github.com/xfstart07/dubbo-go-hessian2/blob/fix/javaclass/test_hessian/src/test/java/unit/GoStringTest.java

What you expected to happen:

期望解析出来传入有数据的字段

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

AlexStocks commented 2 years ago

@xfstart07 还请你把原始的 java 和 go 代码贴进来

wongoo commented 2 years ago

@xfstart07 can u try to simulate the issue problem following the example below:

xfstart07 commented 2 years ago

@xfstart07 can u try to simulate the issue problem following the example below:

构造了一个 https://github.com/xfstart07/dubbo-go-hessian2/blob/fix/javaclass/test_hessian/src/test/java/unit/GoStringTest.java

xfstart07 commented 2 years ago

查出的问题记录:

  1. https://github.com/apache/dubbo-go-hessian2/blob/master/object.go#L472 断言 bool 值是返回的 err = nil, 导致无法报出实际的错误

2.如果 Go 的结构体定义中存在小写开头字段,会导致解析出错,原本应该读取的数据没有读取,这样数据就错乱了 https://github.com/apache/dubbo-go-hessian2/blob/master/object.go#L397

binbin0325 commented 2 years ago

查出的问题记录:

  1. https://github.com/apache/dubbo-go-hessian2/blob/master/object.go#L472 断言 bool 值是返回的 err = nil, 导致无法报出实际的错误

2.如果 Go 的结构体定义中存在小写开头字段,会导致解析出错,原本应该读取的数据没有读取,这样数据就错乱了 https://github.com/apache/dubbo-go-hessian2/blob/master/object.go#L397

1: bool 在java 这边定义为boolean, 使用Boolean 现在还不支持. 2:go结构体字段不要定义为小写,定义为小写无法编解码.

xfstart07 commented 2 years ago
  1. 没明白 boolean 不支持是什么意思? 那 object.go#L472 支持的啥?
  2. 第二个问题准确的说是序列化读取数据时强依赖于 go struct 的定义,如果定义少了某个字段,数据读取就错乱了,我感觉是不合理的,不过我对 hessian 协议不是很理解,hessian 是有这个规定的吗?
binbin0325 commented 2 years ago

1:boolean 和 java.lang.Boolean 是不一样的,你使用的是Boolean在java那边定义,在go这边hessian2 暂时还不支持编解码,你可以改为boolean 2:dubbo-go-hessian2 因为是按照字节顺序读取的,不支持skip. 建议使用的时候 序列化/反序列化的结构体是对应的。

xfstart07 commented 2 years ago

1.但我看实际传过来的数据Boolean类型的值是 T, 源码 case tag == BC_TRUE: // 'T': //true 就有处理

wongoo commented 2 years ago

构造了一个 https://github.com/xfstart07/dubbo-go-hessian2/blob/fix/javaclass/test_hessian/src/test/java/unit/GoStringTest.java

@xfstart07 There is only classes definition,I don't find the unit test.