-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: export NextToken to check token info #442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Change-Id: Ia335036825df098503f7008bf013b9442fe14298
Codecov Report
@@ Coverage Diff @@
## master #442 +/- ##
==========================================
+ Coverage 86.46% 86.51% +0.04%
==========================================
Files 41 41
Lines 5106 5108 +2
==========================================
+ Hits 4415 4419 +4
+ Misses 555 553 -2
Partials 136 136
Continue to review full report at Codecov.
|
|
|
ping @AllenX2018 |
hello, @AllenX2018 , |
@ShannonDing @xujianhai666 I'm sorry for the late reply and I've been busy these days. I will check it this weekend. |
I've checkout your reference information here. I'm sorry that I'm not familiar with alibaba fastjson. But I guess what you want to decode is a json like:
If so, I suggest that you register an extension to decode such a "struct" type map key. You can check the example below: func main() {
data := []byte(`
{
"mqTable":{
{"whatEverKey":"key1"}:{"whatEverValue":"value1"},
{"whatEverKey":"key2"}:{"whatEverValue":"value2"}
}
}`)
table := make(map[keyStruct]valueStruct)
jsoniter.ConfigCompatibleWithStandardLibrary.RegisterExtension(&structKeyMapExt{})
iter := jsoniter.ParseBytes(jsoniter.ConfigCompatibleWithStandardLibrary, data)
_ = iter.ReadMapCB(func(iterator *jsoniter.Iterator, key string) bool {
if key == "mqTable" {
iter.ReadVal(&table)
}
return true
})
if iter.Error != nil && iter.Error != io.EOF {
fmt.Println(iter.Error)
} else {
fmt.Printf("%+v\n", table)
}
}
type keyStruct struct {
WhatEverKey string `json:"whatEverKey"`
}
type valueStruct struct {
WhatEverValue string `json:"whatEverValue"`
}
type structKeyMapExt struct {
jsoniter.DummyExtension
}
func (e *structKeyMapExt) CreateMapKeyDecoder(typ reflect2.Type) jsoniter.ValDecoder {
if typ == reflect2.TypeOf(keyStruct{}) {
return &structKeyDecoder{}
}
return nil
}
type structKeyDecoder struct {
}
func (dec *structKeyDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) {
iter.ReadVal((*keyStruct)(ptr))
} You can try it to decode your json. But please use the json-iterator/go with the latest commit on master branch(don't use v1.1.9 because it has a bug). Please let me know if you have any question. |
I support this commit in the case of custom Unmarshal implementation, since its required to check for bytes left after unmarshaling why a custom Unmarshal implementation could be needed ? thanks ! |
just realized that this commit will not compile, since only exports the definition without updating references, just created #481 |
iter.ReadMapCB
, we need to use NextToken to check is there more token, for example, we check ',' token to know the end.Change-Id: Ia335036825df098503f7008bf013b9442fe14298