Skip to content

Commit

Permalink
rename StructType & ListType
Browse files Browse the repository at this point in the history
  • Loading branch information
andot committed Feb 18, 2024
1 parent 2759873 commit ee50718
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 23 deletions.
4 changes: 4 additions & 0 deletions hprose.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ const (
RealTypeBigFloat = io.RealTypeBigFloat
MapTypeIIMap = io.MapTypeIIMap
MapTypeSIMap = io.MapTypeSIMap
StructTypePtr = io.StructTypePtr
StructTypeValue = io.StructTypeValue
ListTypeISlice = io.ListTypeISlice
ListTypeSlice = io.ListTypeSlice

NoCookieManager = cookie.NoCookieManager
GlobalCookieManager = cookie.GlobalCookieManager
Expand Down
18 changes: 9 additions & 9 deletions io/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| |
| io/decoder.go |
| |
| LastModified: Feb 7, 2024 |
| LastModified: Feb 18, 2024 |
| Author: Ma Bingyao <[email protected]> |
| |
\*________________________________________________________*/
Expand Down Expand Up @@ -66,17 +66,17 @@ const (
type StructType int8

const (
// StructTypeStructPointer represents the default type is *T.
StructTypeStructPointer StructType = iota
// StructTypeStructObject represents the default type is T.
StructTypeStructObject
// StructTypePtr represents the default type is *T.
StructTypePtr StructType = iota
// StructTypeValue represents the default type is T.
StructTypeValue
)

type ListType int8

const (
// ListTypeInterfaceSlice represents the default type is []interface{}.
ListTypeInterfaceSlice ListType = iota
// ListTypeISlice represents the default type is []interface{}.
ListTypeISlice ListType = iota
// ListTypeSlice represents the default type is []T.
ListTypeSlice
)
Expand Down Expand Up @@ -365,8 +365,8 @@ func (dec *Decoder) ResetBuffer() *Decoder {
dec.RealType = RealTypeFloat64
dec.LongType = LongTypeInt
dec.MapType = MapTypeIIMap
dec.StructType = StructTypeStructPointer
dec.ListType = ListTypeInterfaceSlice
dec.StructType = StructTypePtr
dec.ListType = ListTypeISlice
return dec
}

Expand Down
6 changes: 3 additions & 3 deletions io/interface_decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| |
| io/interface_decoder_test.go |
| |
| LastModified: Feb 7, 2024 |
| LastModified: Feb 18, 2024 |
| Author: Ma Bingyao <[email protected]> |
| |
\*________________________________________________________*/
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestDecodeStructSliceToInterface(t *testing.T) {
}

dec = NewDecoder(([]byte)(sb.String()))
dec.StructType = StructTypeStructObject
dec.StructType = StructTypeValue
dec.Decode(&v)
assert.Equal(t, expectedData2, v)

Expand All @@ -146,7 +146,7 @@ func TestDecodeStructSliceToInterface(t *testing.T) {
assert.Equal(t, expectedData3, v)

dec = NewDecoder(([]byte)(sb.String()))
dec.StructType = StructTypeStructObject
dec.StructType = StructTypeValue
dec.ListType = ListTypeSlice
dec.Decode(&v)
assert.Equal(t, data, v)
Expand Down
4 changes: 2 additions & 2 deletions io/interface_deocder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| |
| io/interface_decoder.go |
| |
| LastModified: Feb 7, 2024 |
| LastModified: Feb 18, 2024 |
| Author: Ma Bingyao <[email protected]> |
| |
\*________________________________________________________*/
Expand Down Expand Up @@ -81,7 +81,7 @@ func (dec *Decoder) decodeListAsInterface(tag byte, p *interface{}) {
var result []interface{}
ifsdec.Decode(dec, &result, tag)
n := len(result)
if n == 0 || dec.ListType == ListTypeInterfaceSlice {
if n == 0 || dec.ListType == ListTypeISlice {
*p = result
return
}
Expand Down
4 changes: 2 additions & 2 deletions io/struct_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| |
| io/struct_decoder.go |
| |
| LastModified: Feb 7, 2024 |
| LastModified: Feb 18, 2024 |
| Author: Ma Bingyao <[email protected]> |
| |
\*________________________________________________________*/
Expand Down Expand Up @@ -50,7 +50,7 @@ func (dec *Decoder) readObject(structInfo structInfo) interface{} {
}
}
dec.Skip()
if dec.StructType == StructTypeStructObject {
if dec.StructType == StructTypeValue {
return structInfo.t.UnsafeIndirect(ptr)
}
return obj
Expand Down
6 changes: 3 additions & 3 deletions io/struct_decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| |
| io/struct_encoder_test.go |
| |
| LastModified: Feb 7, 2024 |
| LastModified: Feb 18, 2024 |
| Author: Ma Bingyao <[email protected]> |
| |
\*________________________________________________________*/
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestDecodeStructAsInterface(t *testing.T) {
dec.Decode(&ts)
assert.Equal(t, &TestStruct{1, false, "hello", 3.14, 0}, ts)
dec = NewDecoder(([]byte)(sb.String())).Simple(false)
dec.StructType = StructTypeStructObject
dec.StructType = StructTypeValue
dec.Decode(&ts)
assert.Equal(t, TestStruct{1, false, "hello", 3.14, 0}, ts)
}
Expand All @@ -189,7 +189,7 @@ func TestDecodeSelfReferenceStructAsInterface(t *testing.T) {
dec.Decode(&ts)
assert.Equal(t, &src, ts)
dec = NewDecoder(([]byte)(sb.String())).Simple(false)
dec.StructType = StructTypeStructObject
dec.StructType = StructTypeValue
dec.Decode(&ts)
assert.Equal(t, src, ts)
}
2 changes: 1 addition & 1 deletion rpc/mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ func TestReturnStructSlice(t *testing.T) {
assert.NoError(t, err)
client := core.NewClient("mock://testReturnStructSlice")
client.Codec = core.NewClientCodec(
core.WithStructType(io.StructTypeStructObject),
core.WithStructType(io.StructTypeValue),
core.WithListType(io.ListTypeSlice),
)
var proxy struct {
Expand Down
6 changes: 3 additions & 3 deletions rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ func TestAutoTypeConvert(t *testing.T) {
rpc.WithLongType(io.LongTypeBigInt),
rpc.WithRealType(io.RealTypeBigFloat),
rpc.WithMapType(io.MapTypeSIMap),
rpc.WithStructType(io.StructTypeStructPointer),
rpc.WithListType(io.ListTypeInterfaceSlice),
rpc.WithStructType(io.StructTypePtr),
rpc.WithListType(io.ListTypeISlice),
)
service.AddFunction(autoTypeConvert)
server, err := net.Listen("tcp", "127.0.0.1:8412")
Expand All @@ -425,7 +425,7 @@ func TestAutoTypeConvert(t *testing.T) {
rpc.WithLongType(io.LongTypeUint64),
rpc.WithRealType(io.RealTypeFloat64),
rpc.WithMapType(io.MapTypeIIMap),
rpc.WithStructType(io.StructTypeStructObject),
rpc.WithStructType(io.StructTypeValue),
rpc.WithListType(io.ListTypeSlice),
)
client.UseService(&proxy)
Expand Down

0 comments on commit ee50718

Please sign in to comment.