Skip to content

Commit ee50718

Browse files
committed
rename StructType & ListType
1 parent 2759873 commit ee50718

8 files changed

+27
-23
lines changed

hprose.go

+4
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ const (
147147
RealTypeBigFloat = io.RealTypeBigFloat
148148
MapTypeIIMap = io.MapTypeIIMap
149149
MapTypeSIMap = io.MapTypeSIMap
150+
StructTypePtr = io.StructTypePtr
151+
StructTypeValue = io.StructTypeValue
152+
ListTypeISlice = io.ListTypeISlice
153+
ListTypeSlice = io.ListTypeSlice
150154

151155
NoCookieManager = cookie.NoCookieManager
152156
GlobalCookieManager = cookie.GlobalCookieManager

io/decoder.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| io/decoder.go |
88
| |
9-
| LastModified: Feb 7, 2024 |
9+
| LastModified: Feb 18, 2024 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -66,17 +66,17 @@ const (
6666
type StructType int8
6767

6868
const (
69-
// StructTypeStructPointer represents the default type is *T.
70-
StructTypeStructPointer StructType = iota
71-
// StructTypeStructObject represents the default type is T.
72-
StructTypeStructObject
69+
// StructTypePtr represents the default type is *T.
70+
StructTypePtr StructType = iota
71+
// StructTypeValue represents the default type is T.
72+
StructTypeValue
7373
)
7474

7575
type ListType int8
7676

7777
const (
78-
// ListTypeInterfaceSlice represents the default type is []interface{}.
79-
ListTypeInterfaceSlice ListType = iota
78+
// ListTypeISlice represents the default type is []interface{}.
79+
ListTypeISlice ListType = iota
8080
// ListTypeSlice represents the default type is []T.
8181
ListTypeSlice
8282
)
@@ -365,8 +365,8 @@ func (dec *Decoder) ResetBuffer() *Decoder {
365365
dec.RealType = RealTypeFloat64
366366
dec.LongType = LongTypeInt
367367
dec.MapType = MapTypeIIMap
368-
dec.StructType = StructTypeStructPointer
369-
dec.ListType = ListTypeInterfaceSlice
368+
dec.StructType = StructTypePtr
369+
dec.ListType = ListTypeISlice
370370
return dec
371371
}
372372

io/interface_decoder_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| io/interface_decoder_test.go |
88
| |
9-
| LastModified: Feb 7, 2024 |
9+
| LastModified: Feb 18, 2024 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -131,7 +131,7 @@ func TestDecodeStructSliceToInterface(t *testing.T) {
131131
}
132132

133133
dec = NewDecoder(([]byte)(sb.String()))
134-
dec.StructType = StructTypeStructObject
134+
dec.StructType = StructTypeValue
135135
dec.Decode(&v)
136136
assert.Equal(t, expectedData2, v)
137137

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

148148
dec = NewDecoder(([]byte)(sb.String()))
149-
dec.StructType = StructTypeStructObject
149+
dec.StructType = StructTypeValue
150150
dec.ListType = ListTypeSlice
151151
dec.Decode(&v)
152152
assert.Equal(t, data, v)

io/interface_deocder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| io/interface_decoder.go |
88
| |
9-
| LastModified: Feb 7, 2024 |
9+
| LastModified: Feb 18, 2024 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -81,7 +81,7 @@ func (dec *Decoder) decodeListAsInterface(tag byte, p *interface{}) {
8181
var result []interface{}
8282
ifsdec.Decode(dec, &result, tag)
8383
n := len(result)
84-
if n == 0 || dec.ListType == ListTypeInterfaceSlice {
84+
if n == 0 || dec.ListType == ListTypeISlice {
8585
*p = result
8686
return
8787
}

io/struct_decoder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| io/struct_decoder.go |
88
| |
9-
| LastModified: Feb 7, 2024 |
9+
| LastModified: Feb 18, 2024 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -50,7 +50,7 @@ func (dec *Decoder) readObject(structInfo structInfo) interface{} {
5050
}
5151
}
5252
dec.Skip()
53-
if dec.StructType == StructTypeStructObject {
53+
if dec.StructType == StructTypeValue {
5454
return structInfo.t.UnsafeIndirect(ptr)
5555
}
5656
return obj

io/struct_decoder_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| io/struct_encoder_test.go |
88
| |
9-
| LastModified: Feb 7, 2024 |
9+
| LastModified: Feb 18, 2024 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -169,7 +169,7 @@ func TestDecodeStructAsInterface(t *testing.T) {
169169
dec.Decode(&ts)
170170
assert.Equal(t, &TestStruct{1, false, "hello", 3.14, 0}, ts)
171171
dec = NewDecoder(([]byte)(sb.String())).Simple(false)
172-
dec.StructType = StructTypeStructObject
172+
dec.StructType = StructTypeValue
173173
dec.Decode(&ts)
174174
assert.Equal(t, TestStruct{1, false, "hello", 3.14, 0}, ts)
175175
}
@@ -189,7 +189,7 @@ func TestDecodeSelfReferenceStructAsInterface(t *testing.T) {
189189
dec.Decode(&ts)
190190
assert.Equal(t, &src, ts)
191191
dec = NewDecoder(([]byte)(sb.String())).Simple(false)
192-
dec.StructType = StructTypeStructObject
192+
dec.StructType = StructTypeValue
193193
dec.Decode(&ts)
194194
assert.Equal(t, src, ts)
195195
}

rpc/mock/mock_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ func TestReturnStructSlice(t *testing.T) {
13431343
assert.NoError(t, err)
13441344
client := core.NewClient("mock://testReturnStructSlice")
13451345
client.Codec = core.NewClientCodec(
1346-
core.WithStructType(io.StructTypeStructObject),
1346+
core.WithStructType(io.StructTypeValue),
13471347
core.WithListType(io.ListTypeSlice),
13481348
)
13491349
var proxy struct {

rpc/rpc_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ func TestAutoTypeConvert(t *testing.T) {
404404
rpc.WithLongType(io.LongTypeBigInt),
405405
rpc.WithRealType(io.RealTypeBigFloat),
406406
rpc.WithMapType(io.MapTypeSIMap),
407-
rpc.WithStructType(io.StructTypeStructPointer),
408-
rpc.WithListType(io.ListTypeInterfaceSlice),
407+
rpc.WithStructType(io.StructTypePtr),
408+
rpc.WithListType(io.ListTypeISlice),
409409
)
410410
service.AddFunction(autoTypeConvert)
411411
server, err := net.Listen("tcp", "127.0.0.1:8412")
@@ -425,7 +425,7 @@ func TestAutoTypeConvert(t *testing.T) {
425425
rpc.WithLongType(io.LongTypeUint64),
426426
rpc.WithRealType(io.RealTypeFloat64),
427427
rpc.WithMapType(io.MapTypeIIMap),
428-
rpc.WithStructType(io.StructTypeStructObject),
428+
rpc.WithStructType(io.StructTypeValue),
429429
rpc.WithListType(io.ListTypeSlice),
430430
)
431431
client.UseService(&proxy)

0 commit comments

Comments
 (0)