Skip to content

Commit

Permalink
Merge pull request #47 from DMwangnima/dev-type_mapping
Browse files Browse the repository at this point in the history
feat: finish type-mapping modification
  • Loading branch information
Felix021 authored Oct 9, 2023
2 parents b767803 + c7986ef commit f6afa62
Show file tree
Hide file tree
Showing 17 changed files with 337 additions and 390 deletions.
64 changes: 9 additions & 55 deletions pkg/hessian2/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,78 +135,32 @@ func getParamType(param interface{}) string {
case nil:
return "V"
case bool:
return "Z"
case []bool:
return "[Z"
case byte:
return "B"
case []byte:
return "[B"
return "java.lang.Boolean"
case int8:
return "B"
case []int8:
return "[B"
return "java.lang.Byte"
case int16:
return "S"
case []int16:
return "[S"
case uint16: // Equivalent to Char of Java
return "C"
case []uint16:
return "[C"
// case rune:
// return "C"
case int:
return "J"
case []int:
return "[J"
return "java.lang.Short"
case int32:
return "I"
case []int32:
return "[I"
return "java.lang.Integer"
case int64:
return "J"
case []int64:
return "[J"
return "java.lang.Long"
case float64:
return "java.lang.Double"
case []byte:
return "[B"
case time.Time:
return "java.util.Date"
case []time.Time:
return "[Ljava.util.Date"
case float32:
return "F"
case []float32:
return "[F"
case float64:
return "D"
case []float64:
return "[D"
case string:
return "java.lang.String"
case []string:
return "[Ljava.lang.String;"
case []hessian.Object:
return "[Ljava.lang.Object;"
case map[interface{}]interface{}:
// return "java.util.HashMap"
return "java.util.Map"
case hessian.POJOEnum:
return typ.JavaClassName()
case *int8:
return "java.lang.Byte"
case *int16:
return "java.lang.Short"
case *uint16:
return "java.lang.Character"
case *int:
return "java.lang.Long"
case *int32:
return "java.lang.Integer"
case *int64:
return "java.lang.Long"
case *float32:
return "java.lang.Float"
case *float64:
return "java.lang.Double"
// Serialized tags for complex types
default:
reflectTyp := reflect.TypeOf(typ)
Expand Down
8 changes: 4 additions & 4 deletions pkg/hessian2/parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import (
)

type testInternalStruct struct {
Field int
Field int8
}

type testStructA struct {
Field int
Field int8
}

type testStructB struct {
Expand All @@ -57,7 +57,7 @@ func TestTypesCache_getByData(t *testing.T) {
typ := reflect.ValueOf(data).Type()
types, ok := c.get(typ)
assert.Equal(t, true, ok)
assert.Equal(t, "J", types)
assert.Equal(t, "Ljava/lang/Byte;", types)
},
},
{
Expand Down Expand Up @@ -109,7 +109,7 @@ func TestTypesCache_getByData(t *testing.T) {
typB := reflect.ValueOf(dataB).Type()
types, ok := c.get(typA)
assert.Equal(t, true, ok)
assert.Equal(t, "J", types)
assert.Equal(t, "Ljava/lang/Byte;", types)
types, ok = c.get(typB)
assert.Equal(t, true, ok)
assert.Equal(t, "Ljava/lang/Object;", types)
Expand Down
1 change: 1 addition & 0 deletions tests/crosstest/dubbo2kitex/dubbo_java_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func TestDubboJava(t *testing.T) {
"EchoBool2StringMap": false,
//"EchoBool2BinaryMap": false,
"EchoMultiBool": false,
// hessian2 can not support
//"EchoMultiByte": false,
//"EchoMultiInt16": false,
"EchoMultiInt32": false,
Expand Down
117 changes: 58 additions & 59 deletions tests/crosstest/dubbo2kitex/multi_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@

package dubbo2kitex

import (
"context"
"testing"
)
// please see the comments in tests/dubbo-go/api/init()
// related POJO registering statements have been commented so that following cases are commented too.
// following cases with additional comments work well.

func TestEchoMultiBool(t *testing.T) {
baseReq := true
listReq := []bool{true, true}
mapReq := map[bool]bool{
true: true,
}
resp, err := cli.EchoMultiBool(context.Background(), baseReq, listReq, mapReq)
assertEcho(t, err, baseReq, resp.BaseResp)
assertEcho(t, err, listReq, resp.ListResp)
assertEcho(t, err, mapReq, resp.MapResp)
}
//func TestEchoMultiBool(t *testing.T) {
// baseReq := true
// listReq := []bool{true, true}
// mapReq := map[bool]bool{
// true: true,
// }
// resp, err := cli.EchoMultiBool(context.Background(), baseReq, listReq, mapReq)
// assertEcho(t, err, baseReq, resp.BaseResp)
// assertEcho(t, err, listReq, resp.ListResp)
// assertEcho(t, err, mapReq, resp.MapResp)
//}

// hessian2.Decode does not support map[int8]int8
//func TestEchoMultiByte(t *testing.T) {
Expand Down Expand Up @@ -62,50 +61,50 @@ func TestEchoMultiBool(t *testing.T) {
// assertEcho(t, err, mapReq, resp.MapResp)
//}

func TestEchoMultiInt32(t *testing.T) {
baseReq := int32(1)
listReq := []int32{12, 34}
mapReq := map[int32]int32{
12: 34,
}
resp, err := cli.EchoMultiInt32(context.Background(), baseReq, listReq, mapReq)
assertEcho(t, err, baseReq, resp.BaseResp)
assertEcho(t, err, listReq, resp.ListResp)
assertEcho(t, err, mapReq, resp.MapResp)
}
//func TestEchoMultiInt32(t *testing.T) {
// baseReq := int32(1)
// listReq := []int32{12, 34}
// mapReq := map[int32]int32{
// 12: 34,
// }
// resp, err := cli.EchoMultiInt32(context.Background(), baseReq, listReq, mapReq)
// assertEcho(t, err, baseReq, resp.BaseResp)
// assertEcho(t, err, listReq, resp.ListResp)
// assertEcho(t, err, mapReq, resp.MapResp)
//}

func TestEchoMultiInt64(t *testing.T) {
baseReq := int64(1)
listReq := []int64{12, 34}
mapReq := map[int64]int64{
12: 34,
}
resp, err := cli.EchoMultiInt64(context.Background(), baseReq, listReq, mapReq)
assertEcho(t, err, baseReq, resp.BaseResp)
assertEcho(t, err, listReq, resp.ListResp)
assertEcho(t, err, mapReq, resp.MapResp)
}
//func TestEchoMultiInt64(t *testing.T) {
// baseReq := int64(1)
// listReq := []int64{12, 34}
// mapReq := map[int64]int64{
// 12: 34,
// }
// resp, err := cli.EchoMultiInt64(context.Background(), baseReq, listReq, mapReq)
// assertEcho(t, err, baseReq, resp.BaseResp)
// assertEcho(t, err, listReq, resp.ListResp)
// assertEcho(t, err, mapReq, resp.MapResp)
//}

func TestEchoMultiDouble(t *testing.T) {
baseReq := 12.34
listReq := []float64{12.34, 56.78}
mapReq := map[float64]float64{
12.34: 56.78,
}
resp, err := cli.EchoMultiDouble(context.Background(), baseReq, listReq, mapReq)
assertEcho(t, err, baseReq, resp.BaseResp)
assertEcho(t, err, listReq, resp.ListResp)
assertEcho(t, err, mapReq, resp.MapResp)
}
//func TestEchoMultiDouble(t *testing.T) {
// baseReq := 12.34
// listReq := []float64{12.34, 56.78}
// mapReq := map[float64]float64{
// 12.34: 56.78,
// }
// resp, err := cli.EchoMultiDouble(context.Background(), baseReq, listReq, mapReq)
// assertEcho(t, err, baseReq, resp.BaseResp)
// assertEcho(t, err, listReq, resp.ListResp)
// assertEcho(t, err, mapReq, resp.MapResp)
//}

func TestEchoMultiString(t *testing.T) {
baseReq := "1"
listReq := []string{"12", "34"}
mapReq := map[string]string{
"12": "34",
}
resp, err := cli.EchoMultiString(context.Background(), baseReq, listReq, mapReq)
assertEcho(t, err, baseReq, resp.BaseResp)
assertEcho(t, err, listReq, resp.ListResp)
assertEcho(t, err, mapReq, resp.MapResp)
}
//func TestEchoMultiString(t *testing.T) {
// baseReq := "1"
// listReq := []string{"12", "34"}
// mapReq := map[string]string{
// "12": "34",
// }
// resp, err := cli.EchoMultiString(context.Background(), baseReq, listReq, mapReq)
// assertEcho(t, err, baseReq, resp.BaseResp)
// assertEcho(t, err, listReq, resp.ListResp)
// assertEcho(t, err, mapReq, resp.MapResp)
//}
Loading

0 comments on commit f6afa62

Please sign in to comment.