-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
27 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
| | | ||
| io/decoder.go | | ||
| | | ||
| LastModified: Feb 7, 2024 | | ||
| LastModified: Feb 18, 2024 | | ||
| Author: Ma Bingyao <[email protected]> | | ||
| | | ||
\*________________________________________________________*/ | ||
|
@@ -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 | ||
) | ||
|
@@ -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 | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
| | | ||
| io/interface_decoder_test.go | | ||
| | | ||
| LastModified: Feb 7, 2024 | | ||
| LastModified: Feb 18, 2024 | | ||
| Author: Ma Bingyao <[email protected]> | | ||
| | | ||
\*________________________________________________________*/ | ||
|
@@ -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) | ||
|
||
|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
| | | ||
| io/interface_decoder.go | | ||
| | | ||
| LastModified: Feb 7, 2024 | | ||
| LastModified: Feb 18, 2024 | | ||
| Author: Ma Bingyao <[email protected]> | | ||
| | | ||
\*________________________________________________________*/ | ||
|
@@ -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 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
| | | ||
| io/struct_decoder.go | | ||
| | | ||
| LastModified: Feb 7, 2024 | | ||
| LastModified: Feb 18, 2024 | | ||
| Author: Ma Bingyao <[email protected]> | | ||
| | | ||
\*________________________________________________________*/ | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
| | | ||
| io/struct_encoder_test.go | | ||
| | | ||
| LastModified: Feb 7, 2024 | | ||
| LastModified: Feb 18, 2024 | | ||
| Author: Ma Bingyao <[email protected]> | | ||
| | | ||
\*________________________________________________________*/ | ||
|
@@ -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) | ||
} | ||
|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters