|
@@ -8,6 +8,7 @@ import (
|
|
|
|
|
|
|
|
func RegisterFuzzyDecoders() {
|
|
func RegisterFuzzyDecoders() {
|
|
|
jsoniter.RegisterTypeDecoder("string", &FuzzyStringDecoder{})
|
|
jsoniter.RegisterTypeDecoder("string", &FuzzyStringDecoder{})
|
|
|
|
|
+ jsoniter.RegisterTypeDecoder("int", &FuzzyIntDecoder{})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type FuzzyStringDecoder struct {
|
|
type FuzzyStringDecoder struct {
|
|
@@ -26,3 +27,21 @@ func (decoder *FuzzyStringDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Ite
|
|
|
iter.ReportError("FuzzyStringDecoder", "not number or string")
|
|
iter.ReportError("FuzzyStringDecoder", "not number or string")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+type FuzzyIntDecoder struct {
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (decoder *FuzzyIntDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) {
|
|
|
|
|
+ valueType := iter.WhatIsNext()
|
|
|
|
|
+ switch valueType {
|
|
|
|
|
+ case jsoniter.Number:
|
|
|
|
|
+ // use current iterator
|
|
|
|
|
+ case jsoniter.String:
|
|
|
|
|
+ str := iter.ReadString()
|
|
|
|
|
+ iter = iter.Config().BorrowIterator([]byte(str))
|
|
|
|
|
+ defer iter.Config().ReturnIterator(iter)
|
|
|
|
|
+ default:
|
|
|
|
|
+ iter.ReportError("FuzzyIntDecoder", "not number or string")
|
|
|
|
|
+ }
|
|
|
|
|
+ *((*int)(ptr)) = iter.ReadInt()
|
|
|
|
|
+}
|