Skip to content
Permalink
Browse files
format code
  • Loading branch information
wongoo committed Mar 8, 2021
1 parent c052455 commit 22f4e802e6001c17a3fb2d964ac10c4d3edc4910
Showing 38 changed files with 101 additions and 107 deletions.
@@ -69,6 +69,10 @@ jobs:
chmod u+x /tmp/tools/license/license-header-checker
/tmp/tools/license/license-header-checker -v -a -r -i vendor /tmp/tools/license/license.txt . go && [[ -z `git status -s` ]]
- name: format
run: |
gofmt -l -w . && [[ -z `git status -s` ]]
- name: Install go ci lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0

@@ -25,7 +25,7 @@ package hessian
// ::= 'T'
// ::= 'F'
func encBool(b []byte, v bool) []byte {
var c = BC_FALSE
c := BC_FALSE
if v {
c = BC_TRUE
}
@@ -118,35 +118,35 @@ func PackFloat64(v float64) []byte {
// UnpackInt16 unpacks int16 from byte array
//(0,2).unpack('n')
func UnpackInt16(b []byte) int16 {
var arr = b[:2]
arr := b[:2]
return int16(binary.BigEndian.Uint16(arr))
}

// UnpackUint16 unpacks int16 from byte array
//(0,2).unpack('n')
func UnpackUint16(b []byte) uint16 {
var arr = b[:2]
arr := b[:2]
return binary.BigEndian.Uint16(arr)
}

// UnpackInt32 unpacks int32 from byte array
//(0,4).unpack('N')
func UnpackInt32(b []byte) int32 {
var arr = b[:4]
arr := b[:4]
return int32(binary.BigEndian.Uint32(arr))
}

// UnpackInt64 unpacks int64 from byte array
//long (0,8).unpack('q>')
// long (0,8).unpack('q>')
func UnpackInt64(b []byte) int64 {
var arr = b[:8]
arr := b[:8]
return int64(binary.BigEndian.Uint64(arr))
}

// UnpackFloat64 unpacks float64 from byte array
//Double (0,8).unpack('G)
// Double (0,8).unpack('G)
func UnpackFloat64(b []byte) float64 {
var arr = b[:8]
arr := b[:8]
return math.Float64frombits(binary.BigEndian.Uint64(arr))
}

@@ -159,14 +159,14 @@ func UnpackPtr(v reflect.Value) reflect.Value {
return v
}

//PackPtr pack a Ptr value
// PackPtr pack a Ptr value
func PackPtr(v reflect.Value) reflect.Value {
vv := reflect.New(v.Type())
vv.Elem().Set(v)
return vv
}

//UnpackPtrType unpack pointer type to original type
// UnpackPtrType unpack pointer type to original type
func UnpackPtrType(typ reflect.Type) reflect.Type {
for typ.Kind() == reflect.Ptr {
typ = typ.Elem()
@@ -268,7 +268,7 @@ func EnsureInterface(in interface{}, err error) (interface{}, error) {
return in, nil
}

//EnsureRawValue pack the interface with value, and make sure it's not a ref holder
// EnsureRawValue pack the interface with value, and make sure it's not a ref holder
func EnsureRawValue(in interface{}) reflect.Value {
if v, ok := in.(reflect.Value); ok {
if v.IsValid() {
@@ -295,7 +295,7 @@ func SetValue(dest, v reflect.Value) {
return
}
}
//temporary process, only handle the same type of situation
// temporary process, only handle the same type of situation
if v.IsValid() && UnpackPtrType(dest.Type()) == UnpackPtrType(v.Type()) && dest.Kind() == reflect.Ptr && dest.CanSet() {
for dest.Type() != v.Type() {
v = PackPtr(v)
@@ -381,7 +381,7 @@ func AddrEqual(x, y interface{}) bool {
return v1.Pointer() == v2.Pointer()
}

//SetSlice set value into slice object
// SetSlice set value into slice object
func SetSlice(dest reflect.Value, objects interface{}) error {
if objects == nil {
return nil
@@ -422,7 +422,7 @@ func SetSlice(dest reflect.Value, objects interface{}) error {
return nil
}

//ConvertSliceValueType convert to slice of destination type
// ConvertSliceValueType convert to slice of destination type
func ConvertSliceValueType(destTyp reflect.Type, v reflect.Value) (reflect.Value, error) {
if destTyp == v.Type() {
return v, nil
@@ -25,7 +25,7 @@ import (
func TestPackUint16(t *testing.T) {
// var arr []byte
// t.Logf("0X%x\n", UnpackUint16(PackUint16(uint16(0xfedc), arr)))
var v = uint16(0xfedc)
v := uint16(0xfedc)
if r := UnpackUint16(PackUint16(v)); r != v {
t.Fatalf("v:0X%d, pack-unpack value:0X%x\n", v, r)
}
@@ -34,7 +34,7 @@ func TestPackUint16(t *testing.T) {
func TestPackInt16(t *testing.T) {
// var arr []byte
// t.Logf("0X%x\n", UnpackInt16(PackInt16(int16(0x1234), arr)))
var v = int16(0x1234)
v := int16(0x1234)
if r := UnpackInt16(PackInt16(v)); r != v {
t.Fatalf("v:0X%d, pack-unpack value:0X%x\n", v, r)
}
@@ -43,7 +43,7 @@ func TestPackInt16(t *testing.T) {
func TestPackInt32(t *testing.T) {
// var arr []byte
// t.Logf("0X%x\n", UnpackInt32(PackInt32(int32(0x12344678), arr)))
var v = int32(0x12344678)
v := int32(0x12344678)
if r := UnpackInt32(PackInt32(v)); r != v {
t.Fatalf("v:0X%d, pack-unpack value:0X%x\n", v, r)
}
@@ -52,7 +52,7 @@ func TestPackInt32(t *testing.T) {
func TestPackInt64(t *testing.T) {
// var arr []byte
// t.Logf("0X%x\n", UnpackInt64(PackInt64(int64(0x1234567890abcdef), arr)))
var v = int64(0x1234567890abcdef)
v := int64(0x1234567890abcdef)
if r := UnpackInt64(PackInt64(v)); r != v {
t.Fatalf("v:0X%d, pack-unpack value:0X%x\n", v, r)
}
@@ -36,7 +36,6 @@ var ZeroDate = time.Time{}
// ::= x4a b7 b6 b5 b4 b3 b2 b1 b0
// ::= x4b b3 b2 b1 b0 # minutes since epoch
func encDateInMs(b []byte, i interface{}) []byte {

value := UnpackPtrValue(reflect.ValueOf(i))
vi := value.Interface().(time.Time)
if vi == ZeroDate {
@@ -40,7 +40,7 @@ type DateDemo struct {
Date3 ***time.Time
}

//JavaClassName java fully qualified path
// JavaClassName java fully qualified path
func (DateDemo) JavaClassName() string {
return "test.model.DateDemo"
}
@@ -135,7 +135,6 @@ func TestEncDateNull(t *testing.T) {
assert.Equal(t, ZeroDate, *res.(*DateDemo).Date1)
assert.Equal(t, tz.Local().String(), (*res.(*DateDemo).Date2).String())
assert.Equal(t, tz.Local().String(), (*(*res.(*DateDemo).Date3)).String())

}

func TestDateNulJavaDecode(t *testing.T) {
@@ -147,7 +146,6 @@ func TestDateNulJavaDecode(t *testing.T) {
}

func TestDateNilDecode(t *testing.T) {

doTestDateNull(t, "customReplyTypedFixedDateNull")
}

@@ -40,7 +40,7 @@ type Encoder struct {

// NewEncoder generate an encoder instance
func NewEncoder() *Encoder {
var buffer = make([]byte, 64)
buffer := make([]byte, 64)

return &Encoder{
buffer: buffer[:0],
@@ -50,7 +50,7 @@ func NewEncoder() *Encoder {

// Clean clean the Encoder (room) for a new object encoding.
func (e *Encoder) Clean() {
var buffer = make([]byte, 64)
buffer := make([]byte, 64)
e.classInfoList = nil
e.buffer = buffer[:0]
e.refMap = make(map[unsafe.Pointer]_refElem, 7)
@@ -59,7 +59,6 @@ func javaDecodeValidate(t *testing.T, method string, target interface{}) (string
}()

out, err := cmd.Output()

if err != nil {
t.Logf("get java result error: %v", err)
return "", err
@@ -104,7 +104,6 @@ func (h *HessianCodec) Write(service Service, header DubboHeader, body interface

// ReadHeader uses hessian codec to read dubbo header
func (h *HessianCodec) ReadHeader(header *DubboHeader) error {

var err error

if h.reader.Size() < HEADER_LENGTH {
@@ -166,12 +165,10 @@ func (h *HessianCodec) ReadHeader(header *DubboHeader) error {
}

return perrors.WithStack(err)

}

// ReadBody uses hessian codec to read response body
func (h *HessianCodec) ReadBody(rspObj interface{}) error {

if h.reader.Buffered() < h.bodyLen {
return ErrBodyNotEnough
}
@@ -53,7 +53,7 @@ func (c CaseA) JavaClassName() string {
return "com.test.casea"
}

//JavaClassName java fully qualified path
// JavaClassName java fully qualified path
func (c Case) JavaClassName() string {
return "com.test.case"
}
@@ -35,5 +35,4 @@ func init() {
RegisterPOJO(&java8_time.OffsetDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 16}, Time: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}}, Offset: java8_time.ZoneOffSet{Seconds: 7200}})
RegisterPOJO(&java8_time.OffsetTime{LocalTime: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}, ZoneOffset: java8_time.ZoneOffSet{Seconds: 7200}})
RegisterPOJO(&java8_time.ZonedDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 16}, Time: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}}, Offset: java8_time.ZoneOffSet{Seconds: 7200}, ZoneId: "Z"})

}
@@ -16,7 +16,7 @@
*/
package java8_time

//java8-time java.time.Period
// java8-time java.time.Period
type Period struct {
Days int32 `hessian:"days"`
Months int32 `hessian:"months"`
@@ -16,7 +16,7 @@
*/
package java8_time

//java8-time java.time.Year
// java8-time java.time.Year
type Year struct {
Year int32 `hessian:"year"`
}
@@ -16,7 +16,7 @@
*/
package java8_time

//java8-time java.time.YearMonth
// java8-time java.time.YearMonth
type YearMonth struct {
Month int32 `hessian:"month"`
Year int32 `hessian:"year"`
@@ -18,8 +18,9 @@
package hessian

import (
"github.com/apache/dubbo-go-hessian2/java8_time"
"testing"

"github.com/apache/dubbo-go-hessian2/java8_time"
)

func TestJava8Time(t *testing.T) {
@@ -58,13 +58,10 @@ func isCollectionSerialize(name string) bool {
return getCollectionSerialize(name) != nil
}

type JavaCollectionSerializer struct {
}
type JavaCollectionSerializer struct{}

func (JavaCollectionSerializer) EncObject(e *Encoder, vv POJO) error {
var (
err error
)
var err error
v, ok := vv.(JavaCollectionObject)
if !ok {
return perrors.New("can not be converted into java collection object")
@@ -89,7 +86,7 @@ func (JavaCollectionSerializer) EncObject(e *Encoder, vv POJO) error {
}

func (JavaCollectionSerializer) DecObject(d *Decoder, typ reflect.Type, cls *classInfo) (interface{}, error) {
//for the java impl of hessian encode collections as list, which will not be decoded as object in go impl, this method should not be called
// for the java impl of hessian encode collections as list, which will not be decoded as object in go impl, this method should not be called
return nil, perrors.New("unexpected collection decode call")
}

@@ -34,7 +34,6 @@ func (e DuplicateFormatFlagsException) Error() string {
} else {
return e.DetailMessage + " flags=" + e.Flags
}

}

// JavaClassName java fully qualified path
@@ -50,7 +50,7 @@ func (e Throwable) Error() string {
return e.DetailMessage
}

//JavaClassName java fully qualified path
// JavaClassName java fully qualified path
func (Throwable) JavaClassName() string {
return "java.lang.Throwable"
}
@@ -80,7 +80,7 @@ func (e Exception) Error() string {
return e.DetailMessage
}

//JavaClassName java fully qualified path
// JavaClassName java fully qualified path
func (Exception) JavaClassName() string {
return "java.lang.Exception"
}
@@ -101,7 +101,7 @@ type StackTraceElement struct {
LineNumber int32
}

//JavaClassName java fully qualified path
// JavaClassName java fully qualified path
func (StackTraceElement) JavaClassName() string {
return "java.lang.StackTraceElement"
}
@@ -114,7 +114,7 @@ type Method struct {
Name string
}

//JavaClassName java fully qualified path
// JavaClassName java fully qualified path
func (Method) JavaClassName() string {
return "java.lang.reflect.Method"
}
@@ -31,8 +31,10 @@ type InvalidClassException struct {

// NewInvalidClassException is the constructor
func NewInvalidClassException(classname string, detailMessage string) *InvalidClassException {
return &InvalidClassException{DetailMessage: detailMessage, StackTrace: []StackTraceElement{},
Classname: classname}
return &InvalidClassException{
DetailMessage: detailMessage, StackTrace: []StackTraceElement{},
Classname: classname,
}
}

// Error output error message
@@ -41,7 +43,6 @@ func (e InvalidClassException) Error() string {
return e.DetailMessage
}
return fmt.Sprintf("%+v; %+v", e.Classname, e.DetailMessage)

}

// JavaClassName java fully qualified path
@@ -17,7 +17,7 @@

package java_exception

//UTFDataFormatException represents an exception of the same name in java
// UTFDataFormatException represents an exception of the same name in java
type UTFDataFormatException struct {
SerialVersionUID int64
DetailMessage string
@@ -31,12 +31,12 @@ func NewUTFDataFormatException(detailMessage string) *UTFDataFormatException {
return &UTFDataFormatException{DetailMessage: detailMessage}
}

//Error output error message
// Error output error message
func (e UTFDataFormatException) Error() string {
return e.DetailMessage
}

//JavaClassName java fully qualified path
// JavaClassName java fully qualified path
func (UTFDataFormatException) JavaClassName() string {
return "java.io.UTFDataFormatException"
}

0 comments on commit 22f4e80

Please sign in to comment.