You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by wo...@apache.org on 2021/03/14 13:09:34 UTC
[dubbo-go-hessian2] branch master updated: Fixes #232 Add go struct
refer to java.util.UUID (#256)
This is an automated email from the ASF dual-hosted git repository.
wongoo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-go-hessian2.git
The following commit(s) were added to refs/heads/master by this push:
new 5527e91 Fixes #232 Add go struct refer to java.util.UUID (#256)
5527e91 is described below
commit 5527e919611f7ab0f9b0b25489d38b10842d6e47
Author: zhangym <40...@users.noreply.github.com>
AuthorDate: Sun Mar 14 21:09:27 2021 +0800
Fixes #232 Add go struct refer to java.util.UUID (#256)
* add license checker
* dd javaProject java8time test code and add go hessian/java8_time strcut Year and testFunc
* alter author and error word
* add java.util.UUID encode
* Revert "reset go.mod after go fmt"
This reverts commit ab7254f3
* add UUID test
* alter .travis.yml
* alter code
* add license
* shift count type int, must be unsigned integer
* alter file name and delete test file
* alter file name
* delete file
* alter file name
* alter file name
* add uuid struct info and split import block.
* add java UUID encode and uuid.toString() equals go uuid.ToString() test func
* alter ToString() -> String()
* fix code review
Co-authored-by: zouyixian <zo...@shein.com>
Co-authored-by: wilson chen <wi...@gmail.com>
Co-authored-by: wangoo <wo...@apache.org>
---
.travis.yml | 2 +-
java_util.go | 29 +++++++++
java_util/README.md | 7 +++
java_util/README_CN.md | 7 +++
java_util/uuid.go | 70 ++++++++++++++++++++++
java_util_test.go | 55 +++++++++++++++++
test_hessian/src/main/java/test/Hessian.java | 2 +-
.../src/main/java/test/TestCustomReply.java | 13 ++++
8 files changed, 183 insertions(+), 2 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 6d72de7..0455511 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -29,4 +29,4 @@ after_success:
notifications:
webhooks:
- https://oapi.dingtalk.com/robot/send?access_token=27a5eb4510c8cf913b67a72832549b123a8c44655483d20443515604669de0ae
- - https://oapi.dingtalk.com/robot/send?access_token=8250008579ed1defda3a44fb8608a38d81a55700fdfb15466315a90a7dd2045f
+ - https://oapi.dingtalk.com/robot/send?access_token=8250008579ed1defda3a44fb8608a38d81a55700fdfb15466315a90a7dd2045f
\ No newline at end of file
diff --git a/java_util.go b/java_util.go
new file mode 100644
index 0000000..bbb4d99
--- /dev/null
+++ b/java_util.go
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package hessian
+
+import (
+ "github.com/apache/dubbo-go-hessian2/java_util"
+)
+
+func init() {
+ RegisterPOJO(&java_util.UUID{
+ MostSigBits: int64(200),
+ LeastSigBits: int64(200),
+ })
+}
diff --git a/java_util/README.md b/java_util/README.md
new file mode 100644
index 0000000..0b169cd
--- /dev/null
+++ b/java_util/README.md
@@ -0,0 +1,7 @@
+# UUID-info
+
+1. explain dubbo-go-hessian2 strut UUID
+- JavaServer -> create UUID -> GO Client -> UUID struct (PASS)
+- dubbo-go-hessian2 cannot create UUID strut
+- see jdk source code of class:[java.util.UUID] learning how to create UUID struct
+- see https://github.com/satori/go.uuid
diff --git a/java_util/README_CN.md b/java_util/README_CN.md
new file mode 100644
index 0000000..bc1281f
--- /dev/null
+++ b/java_util/README_CN.md
@@ -0,0 +1,7 @@
+# 说明
+
+1. dubbo-go-hessian2 中 UUID 目前解析情况
+- uuid.go 中提供了解析 Java 中生成好的 UUID 对象,测试通过,但是不提供生成 UUID 的功能
+- java-server 提供的 uuid 可以解析,可以通过 UUID 的 ToString()函数解析成字符串,但是 go 目前未提供生成 uuid 的功能
+- java uuid 生成可以参考 jdk 下 java.util.UUID 类的相关源码
+- uuid 结构体创建参考 https://github.com/satori/go.uuid
diff --git a/java_util/uuid.go b/java_util/uuid.go
new file mode 100644
index 0000000..b4ad3bf
--- /dev/null
+++ b/java_util/uuid.go
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java_util
+
+import (
+ "fmt"
+)
+
+// java.util.UUID
+type UUID struct {
+ MostSigBits int64 `hessian:"mostSigBits"`
+ LeastSigBits int64 `hessian:"leastSigBits"`
+}
+
+func (UUID) JavaClassName() string {
+ return "java.util.UUID"
+}
+
+//String returns a string object representing this UUID.
+//The UUID string representation is as described by this BNF:
+//
+// UUID = <time_low> "-" <time_mid> "-"
+// <time_high_and_version> "-"
+// <variant_and_sequence> "-"
+// <node>
+// time_low = 4*<hexOctet>
+// time_mid = 2*<hexOctet>
+// time_high_and_version = 2*<hexOctet>
+// variant_and_sequence = 2*<hexOctet>
+// node = 6*<hexOctet>
+// hexOctet = <hexDigit><hexDigit>
+// hexDigit =
+// "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
+// | "a" | "b" | "c" | "d" | "e" | "f"
+// | "A" | "B" | "C" | "D" | "E" | "F"
+//
+//Returns:
+//A string representation of this UUID
+func (uuid UUID) String() string {
+ uuidStr := fmt.Sprintf("%v-%v-%v-%v-%v",
+ uuidDigits(uuid.MostSigBits>>32, 8),
+ uuidDigits(uuid.MostSigBits>>16, 4),
+ uuidDigits(uuid.MostSigBits, 4),
+ uuidDigits(uuid.LeastSigBits>>48, 4),
+ uuidDigits(uuid.LeastSigBits, 12),
+ )
+ return uuidStr
+}
+
+// uuidDigits returns arg represented by the specified number of hex digits.
+func uuidDigits(arg int64, digits uint) string {
+ hi := int64(1) << (digits * 4)
+ i := hi | (arg & (hi - 1))
+ return fmt.Sprintf("%x", i)[1:]
+}
diff --git a/java_util_test.go b/java_util_test.go
new file mode 100644
index 0000000..ee6340e
--- /dev/null
+++ b/java_util_test.go
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package hessian
+
+import (
+ "testing"
+)
+
+import (
+ "github.com/stretchr/testify/assert"
+)
+
+import (
+ "github.com/apache/dubbo-go-hessian2/java_util"
+)
+
+func TestJavaUtil(t *testing.T) {
+ res, err := decodeJavaResponse(`customReplyUUID`, ``, false)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ m := res.(map[interface{}]interface{})
+
+ uuid1 := &java_util.UUID{LeastSigBits: int64(-7160773830801198154), MostSigBits: int64(459021424248441700)}
+
+ resUuid1 := m["uuid1"]
+ resUuid1String := m["uuid1_string"]
+ resUuid2 := m["uuid2"]
+ resUuid2String := m["uuid2_string"]
+
+ assert.NotNil(t, resUuid1)
+ assert.NotNil(t, resUuid1String)
+ assert.NotNil(t, resUuid2)
+ assert.NotNil(t, resUuid2String)
+
+ assert.Equal(t, uuid1, resUuid1)
+ assert.Equal(t, uuid1.String(), resUuid1String)
+ assert.Equal(t, (resUuid2.(*java_util.UUID)).String(), resUuid2String)
+}
diff --git a/test_hessian/src/main/java/test/Hessian.java b/test_hessian/src/main/java/test/Hessian.java
index c012885..613f265 100644
--- a/test_hessian/src/main/java/test/Hessian.java
+++ b/test_hessian/src/main/java/test/Hessian.java
@@ -102,4 +102,4 @@ public class Hessian {
output.writeObject(result);
output.flush();
}
-}
\ No newline at end of file
+}
diff --git a/test_hessian/src/main/java/test/TestCustomReply.java b/test_hessian/src/main/java/test/TestCustomReply.java
index 1f99785..d4c6d13 100644
--- a/test_hessian/src/main/java/test/TestCustomReply.java
+++ b/test_hessian/src/main/java/test/TestCustomReply.java
@@ -35,6 +35,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
public class TestCustomReply {
@@ -553,6 +554,18 @@ public class TestCustomReply {
output.writeObject(response);
output.flush();
}
+
+ public void customReplyUUID() throws Exception {
+ Map<String, Object> map = new HashMap<String, Object>();
+ UUID uuid1 = new UUID(459021424248441700L, -7160773830801198154L);
+ UUID uuid2 = UUID.randomUUID();
+ map.put("uuid1", uuid1);
+ map.put("uuid1_string", uuid1.toString());
+ map.put("uuid2", uuid2);
+ map.put("uuid2_string", uuid2.toString());
+ output.writeObject(map);
+ output.flush();
+ }
}
interface Leg {