You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2019/12/14 12:45:23 UTC

[dubbo-go-hessian2] branch master updated: Add: java & go type mapping

This is an automated email from the ASF dual-hosted git repository.

alexstocks 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 70585d0  Add: java & go type mapping
70585d0 is described below

commit 70585d02d8c6f7cab1598780dfbce6f7593406f4
Author: yuyu <yu...@alipay.com>
AuthorDate: Sat Dec 14 20:45:06 2019 +0800

    Add: java & go type mapping
---
 README.md | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/README.md b/README.md
index f7cac61..5373648 100644
--- a/README.md
+++ b/README.md
@@ -20,6 +20,40 @@ It's a golang hessian library used by [Apache/dubbo-go](https://github.com/apach
 * [Skipping unregistered POJO](https://github.com/apache/dubbo-go-hessian2/pull/128)
 * [Emoji](https://github.com/apache/dubbo-go-hessian2/issues/129)
 
+## hessian type mapping between Java and Go
+
+Cross languages message definition should be careful, the following situations should be avoided:
+
+- define object that only exists in a special language
+- using various java exceptions (using error code/message instead)
+
+So we can maintain a cross language type mapping:
+
+| hessian type |  java type  |  golang type | 
+| --- | --- | --- | 
+| **null** | null | nil | 
+| **binary** | byte[] | []byte | 
+| **boolean** | boolean | bool |
+| **date** | java.util.Date | time.Time |
+| **double** | double | float64 |
+| **int** | int | int32 |
+| **long** | long | int64 |
+| **string** | java.lang.String | string |
+| **list** | java.util.List | slice |
+| **map** | java.util.Map | map |
+| **object** | custom define object | custom define struct|
+| **OTHER COMMON USING TYPE** | | | 
+| **big decimal** | java.math.BigDecimal | github.com/dubbogo/gost/math/big/Decimal |
+| **big integer** | java.math.BigInteger | github.com/dubbogo/gost/math/big/Integer |
+| **Boolean** | Boolean | \*bool (TODO) |
+| **Integer** | Integer | \*int32 (TODO)|
+| **Long** | Long | \*int64 (TODO)|
+| **Double** | Double | \*float64 (TODO) |
+
+## reference
+
+- [hessian serialization](http://hessian.caucho.com/doc/hessian-serialization.html)
+
 ## Basic Usage Examples
 
 ### Encode To Bytes
@@ -152,6 +186,7 @@ type MyUser struct {
 You can use `hessian.SetTagIdentifier` to customize tag-identifier of hessian, which takes effect to both encoder and decoder.
 
 Example:
+
 ```go
 hessian.SetTagIdentifier("json")
 
@@ -177,6 +212,7 @@ if err != nil {
 ```
 
 The encoded bytes of the struct `MyUser` is as following:
+
 ```text
  00000000  43 12 63 6f 6d 2e 63 6f  6d 70 61 6e 79 2e 6d 79  |C.com.company.my|
  00000010  75 73 65 72 92 0e 75 73  65 72 5f 66 75 6c 6c 5f  |user..user_full_|