Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:(native) StreamDecoder return error when run out of input buffer …
…while skiping value
- Loading branch information
Showing
2 changed files
with
104 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package issue_test | ||
|
||
import ( | ||
`bytes` | ||
`testing` | ||
|
||
`github.com/bytedance/sonic/ast` | ||
`github.com/bytedance/sonic/decoder` | ||
`github.com/davecgh/go-spew/spew` | ||
) | ||
|
||
|
||
type Response struct { | ||
Menu Menu `json:"menu"` | ||
} | ||
|
||
type Menu struct { | ||
Items []*Item `json:"items"` | ||
} | ||
|
||
type Item struct { | ||
ID string `json:"id"` | ||
} | ||
|
||
func (i *Item) UnmarshalJSON(buf []byte) error { return nil | ||
} | ||
|
||
func TestName(t *testing.T) { | ||
q := `{ | ||
"menu": { | ||
"items": [{ | ||
"id": "carrotcake", | ||
"name": { | ||
"en": "CarrotCake Name" | ||
}, | ||
"operational_name": "carrotCake-op", | ||
"description": null, | ||
"plu": "carrotCake45", | ||
"ian": "carrotCake_ian_45", | ||
"external_data": "", | ||
"image": { | ||
"url": "http://127.0.0.1:50207/image7.jpg" | ||
}, | ||
"tax_rate": "20", | ||
"modifier_ids": [ | ||
"add-hot-drinks-mod" | ||
], | ||
"contains_alcohol": false, | ||
"max_quantity": null, | ||
"is_eligible_for_substitution": true, | ||
"is_eligible_as_replacement": true | ||
}, | ||
{ | ||
"id": "cheeseburger", | ||
"name": { | ||
"en": "Cheeseburger Name" | ||
}, | ||
"operational_name": "cheeseburger-op", | ||
"description": null, | ||
"plu": "cheeseburger40", | ||
"ian": "cheeseburger_ian_40", | ||
"external_data": "", | ||
"image": { | ||
"url": "http://127.0.0.1:50207/image1.jpg" | ||
}, | ||
"tax_rate": "20", | ||
"modifier_ids": [ | ||
"add-drinks-mod" | ||
], | ||
"contains_alcohol": false, | ||
"max_quantity": null, | ||
"is_eligible_for_substitution": true, | ||
"is_eligible_as_replacement": true | ||
} | ||
] | ||
} | ||
}` | ||
|
||
n, err := ast.NewSearcher(q).GetByPath("menu", "items", 1) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
spew.Dump(n.Interface()) | ||
|
||
var response Response | ||
err = decoder.NewStreamDecoder(bytes.NewReader([]byte(q))).Decode(&response) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
} |