Mod: delete chinese remark
diff --git a/codec.go b/codec.go
index b62a4d0..72f6918 100644
--- a/codec.go
+++ b/codec.go
@@ -72,48 +72,38 @@
}
//[10].pack('N').bytes => [0, 0, 0, 10]
-// func PackInt16(v int16, b []byte) []byte {
func PackInt16(v int16) []byte {
var array [2]byte
binary.BigEndian.PutUint16(array[:2], uint16(v))
- // return append(b, array[:2]...)
return array[:]
}
//[10].pack('N').bytes => [0, 0, 0, 10]
-// func PackUint16(v uint16, b []byte) []byte {
func PackUint16(v uint16) []byte {
var array [2]byte
binary.BigEndian.PutUint16(array[:2], v)
- // return append(b, array[:2]...)
return array[:]
}
//[10].pack('N').bytes => [0, 0, 0, 10]
-// func PackInt32(v int32, b []byte) []byte {
func PackInt32(v int32) []byte {
var array [4]byte
binary.BigEndian.PutUint32(array[:4], uint32(v))
- // return append(b, array[:4]...)
return array[:]
}
//[10].pack('q>').bytes => [0, 0, 0, 0, 0, 0, 0, 10]
-// func PackInt64(v int64, b []byte) []byte {
func PackInt64(v int64) []byte {
var array [8]byte
binary.BigEndian.PutUint64(array[:8], uint64(v))
- // return append(b, array[:8]...)
return array[:]
}
//[10].pack('G').bytes => [64, 36, 0, 0, 0, 0, 0, 0]
-// func PackFloat64(v float64, b []byte) []byte {
-// 直接使用math库相关函数优化float64的pack/unpack
+// PackFloat64 invokes go's official math library function Float64bits.
func PackFloat64(v float64) []byte {
var array [8]byte
binary.BigEndian.PutUint64(array[:8], math.Float64bits(v))
- // return append(b, array[:8]...)
return array[:]
}
@@ -180,7 +170,7 @@
return v
}
-//将字节数组格式化成 hex
+// SprintHex converts the []byte to a Hex string.
func SprintHex(b []byte) (rs string) {
rs = fmt.Sprintf("[]byte{")
for _, v := range b {
diff --git a/const.go b/const.go
index 1b4ac4f..a883fd1 100644
--- a/const.go
+++ b/const.go
@@ -33,10 +33,13 @@
package hessian
import (
- jerrors "github.com/juju/errors"
"regexp"
)
+import (
+ jerrors "github.com/juju/errors"
+)
+
const (
mask = byte(127)
flag = byte(128)
@@ -188,12 +191,12 @@
)
/**
- * 协议头是16字节的定长数据
- * 2字节magic字符串0xdabb,0-7高位,8-15低位
- * 1字节的消息标志位。16-20序列id,21 event,22 two way,23请求或响应标识
- * 1字节状态。当消息类型为响应时,设置响应状态。24-31位。
- * 8字节,消息ID,long类型,32-95位。
- * 4字节,消息长度,96-127位
+ * the dubbo protocol header length is 16 Bytes.
+ * the first 2 Bytes is magic code '0xdabb'
+ * the next 1 Byte is message flags, in which its 16-20 bit is serial id, 21 for event, 22 for two way, 23 for request/response flag
+ * the next 1 Bytes is response state.
+ * the next 8 Bytes is package DI.
+ * the next 4 Bytes is package length.
**/
const (
// header length.
diff --git a/double_test.go b/double_test.go
index fe941ab..2ceae8e 100644
--- a/double_test.go
+++ b/double_test.go
@@ -14,7 +14,9 @@
package hessian
-import "testing"
+import (
+ "testing"
+)
func TestEncDouble(t *testing.T) {
var (
diff --git a/pojo.go b/pojo.go
index 3647909..de80b03 100644
--- a/pojo.go
+++ b/pojo.go
@@ -32,7 +32,7 @@
// !!! Pls attention that Every field name should be upper case.
// Otherwise the app may panic.
type POJO interface {
- JavaClassName() string // 获取对应的java classs的package name
+ JavaClassName() string // got a go struct's Java Class package name which should be a POJO class.
}
type POJOEnum interface {
@@ -87,12 +87,10 @@
pojoRegistry.Unlock()
}
-// Register a POJO instance.
-// The return value is -1 if @o has been registered.
-//
-// # definition for an object (compact map)
-// class-def ::= 'C' string int string*
+// Register a POJO instance. The return value is -1 if @o has been registered.
func RegisterPOJO(o POJO) int {
+ // # definition for an object (compact map)
+ // class-def ::= 'C' string int string*
var (
ok bool
b []byte