Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #232 Add go struct refer to java.util.UUID #256

Merged
merged 24 commits into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2c6c772
add license checker
Mar 28, 2020
384263a
dd javaProject java8time test code and add go hessian/java8_time strc…
zhangymPerson Jul 4, 2020
bb39912
alter author and error word
zhangymPerson Jul 4, 2020
22adeb6
Merge pull request #3 from zhangymPerson/feature/issue193
willson-chen Jul 6, 2020
93c2a43
Merge remote-tracking branch 'origin/master'
zhangymPerson Jan 23, 2021
24eef7f
Merge branch 'feature/AddLicenseChcker' of https://github.com/willson…
zhangymPerson Jan 23, 2021
2c799ac
Merge branch 'master' of https://github.com/apache/dubbo-go-hessian2
zhangymPerson Jan 23, 2021
9588106
add java.util.UUID encode
zhangymPerson Jan 23, 2021
2558a8d
Revert "reset go.mod after go fmt"
zhangymPerson Jan 27, 2021
c509ac4
add UUID test
zhangymPerson Jan 27, 2021
661738a
alter .travis.yml
zhangymPerson Jan 27, 2021
088ee6c
alter code
zhangymPerson Jan 27, 2021
2bf9f0c
add license
zhangymPerson Jan 27, 2021
7a9bd56
shift count type int, must be unsigned integer
zhangymPerson Jan 31, 2021
b869609
alter file name and delete test file
zhangymPerson Mar 5, 2021
9367cc2
alter file name
zhangymPerson Mar 5, 2021
079fd68
delete file
zhangymPerson Mar 5, 2021
7705871
alter file name
zhangymPerson Mar 5, 2021
fb1378c
alter file name
zhangymPerson Mar 5, 2021
20ec0e1
add uuid struct info and split import block.
zhangymPerson Mar 11, 2021
cab32a4
add java UUID encode and uuid.toString() equals go uuid.ToString() te…
zhangymPerson Mar 12, 2021
06613ee
alter ToString() -> String()
zhangymPerson Mar 12, 2021
3d81e3b
Merge branch 'master' into java.util
wongoo Mar 13, 2021
dae1b38
fix code review
wongoo Mar 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 29 additions & 0 deletions java_util.go
Original file line number Diff line number Diff line change
@@ -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),
})
}
7 changes: 7 additions & 0 deletions java_util/README.md
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions java_util/README_CN.md
Original file line number Diff line number Diff line change
@@ -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
70 changes: 70 additions & 0 deletions java_util/uuid.go
Original file line number Diff line number Diff line change
@@ -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:]
}
55 changes: 55 additions & 0 deletions java_util_test.go
Original file line number Diff line number Diff line change
@@ -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 (
wongoo marked this conversation as resolved.
Show resolved Hide resolved
"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)
}
2 changes: 1 addition & 1 deletion test_hessian/src/main/java/test/Hessian.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ private static void testCustomClassMethod(String methodName, String className) t
output.writeObject(result);
output.flush();
}
}
}
13 changes: 13 additions & 0 deletions test_hessian/src/main/java/test/TestCustomReply.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;


public class TestCustomReply {
Expand Down Expand Up @@ -553,6 +554,18 @@ public void customReplyGenericResponseBusinessData() throws Exception {
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 {
Expand Down