|
|
@@ -43,26 +43,29 @@ import (
|
|
|
//--------------------------------
|
|
|
|
|
|
var (
|
|
|
- jsonLiterals = [...]byte{'t', 'r', 'u', 'e', 'f', 'a', 'l', 's', 'e', 'n', 'u', 'l', 'l'}
|
|
|
+ // jsonLiterals = [...]byte{'t', 'r', 'u', 'e', 'f', 'a', 'l', 's', 'e', 'n', 'u', 'l', 'l'}
|
|
|
|
|
|
- jsonFloat64Pow10 = [...]float64{
|
|
|
- 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
|
|
|
- 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
|
|
|
- 1e20, 1e21, 1e22,
|
|
|
- }
|
|
|
+ // jsonFloat64Pow10 = [...]float64{
|
|
|
+ // 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
|
|
|
+ // 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
|
|
|
+ // 1e20, 1e21, 1e22,
|
|
|
+ // }
|
|
|
|
|
|
- jsonUint64Pow10 = [...]uint64{
|
|
|
- 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
|
|
|
- 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
|
|
|
- }
|
|
|
+ // jsonUint64Pow10 = [...]uint64{
|
|
|
+ // 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
|
|
|
+ // 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
|
|
|
+ // }
|
|
|
|
|
|
// jsonTabs and jsonSpaces are used as caches for indents
|
|
|
jsonTabs, jsonSpaces string
|
|
|
|
|
|
- jsonCharHtmlSafeSet [utf8.RuneSelf]bool
|
|
|
- jsonCharSafeSet [utf8.RuneSelf]bool
|
|
|
- jsonCharWhitespaceSet [256]bool
|
|
|
- jsonNumSet [256]bool
|
|
|
+ jsonCharHtmlSafeSet bitset128
|
|
|
+ jsonCharSafeSet bitset128
|
|
|
+ jsonCharWhitespaceSet bitset256
|
|
|
+ jsonNumSet bitset256
|
|
|
+ // jsonIsFloatSet bitset256
|
|
|
+
|
|
|
+ jsonU4Set [256]byte
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
@@ -83,6 +86,8 @@ const (
|
|
|
jsonValidateSymbols = true
|
|
|
|
|
|
jsonSpacesOrTabsLen = 128
|
|
|
+
|
|
|
+ jsonU4SetErrVal = 128
|
|
|
)
|
|
|
|
|
|
func init() {
|
|
|
@@ -100,27 +105,42 @@ func init() {
|
|
|
// populate the safe values as true: note: ASCII control characters are (0-31)
|
|
|
// jsonCharSafeSet: all true except (0-31) " \
|
|
|
// jsonCharHtmlSafeSet: all true except (0-31) " \ < > &
|
|
|
- for i := 32; i < utf8.RuneSelf; i++ {
|
|
|
+ var i byte
|
|
|
+ for i = 32; i < utf8.RuneSelf; i++ {
|
|
|
switch i {
|
|
|
case '"', '\\':
|
|
|
- jsonCharSafeSet[i] = false
|
|
|
- jsonCharHtmlSafeSet[i] = false
|
|
|
case '<', '>', '&':
|
|
|
- jsonCharHtmlSafeSet[i] = false
|
|
|
- jsonCharSafeSet[i] = true
|
|
|
+ jsonCharSafeSet.set(i) // = true
|
|
|
default:
|
|
|
- jsonCharSafeSet[i] = true
|
|
|
- jsonCharHtmlSafeSet[i] = true
|
|
|
+ jsonCharSafeSet.set(i)
|
|
|
+ jsonCharHtmlSafeSet.set(i)
|
|
|
}
|
|
|
}
|
|
|
- for i := 0; i < 256; i++ {
|
|
|
+ for i = 0; i <= utf8.RuneSelf; i++ {
|
|
|
switch i {
|
|
|
case ' ', '\t', '\r', '\n':
|
|
|
- jsonCharWhitespaceSet[i] = true
|
|
|
+ jsonCharWhitespaceSet.set(i)
|
|
|
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'e', 'E', '.', '+', '-':
|
|
|
- jsonNumSet[i] = true
|
|
|
+ jsonNumSet.set(i)
|
|
|
}
|
|
|
}
|
|
|
+ for j := range jsonU4Set {
|
|
|
+ switch i = byte(j); i {
|
|
|
+ case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
|
|
+ jsonU4Set[i] = i - '0'
|
|
|
+ case 'a', 'b', 'c', 'd', 'e', 'f':
|
|
|
+ jsonU4Set[i] = i - 'a' + 10
|
|
|
+ case 'A', 'B', 'C', 'D', 'E', 'F':
|
|
|
+ jsonU4Set[i] = i - 'A' + 10
|
|
|
+ default:
|
|
|
+ jsonU4Set[i] = jsonU4SetErrVal
|
|
|
+ }
|
|
|
+ // switch i = byte(j); i {
|
|
|
+ // case 'e', 'E', '.':
|
|
|
+ // jsonIsFloatSet.set(i)
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ // jsonU4Set[255] = jsonU4SetErrVal
|
|
|
}
|
|
|
|
|
|
type jsonEncDriver struct {
|
|
|
@@ -143,48 +163,116 @@ type jsonEncDriver struct {
|
|
|
// - newline and indent are added before each ending,
|
|
|
// except there was no entry (so we can have {} or [])
|
|
|
|
|
|
-func (e *jsonEncDriver) sendContainerState(c containerState) {
|
|
|
- // determine whether to output separators
|
|
|
- if c == containerMapKey {
|
|
|
- if e.c != containerMapStart {
|
|
|
- e.w.writen1(',')
|
|
|
- }
|
|
|
- if e.d {
|
|
|
- e.writeIndent()
|
|
|
- }
|
|
|
- } else if c == containerMapValue {
|
|
|
- if e.d {
|
|
|
- e.w.writen2(':', ' ')
|
|
|
- } else {
|
|
|
- e.w.writen1(':')
|
|
|
- }
|
|
|
- } else if c == containerMapEnd {
|
|
|
- if e.d {
|
|
|
- e.dl--
|
|
|
- if e.c != containerMapStart {
|
|
|
- e.writeIndent()
|
|
|
- }
|
|
|
- }
|
|
|
- e.w.writen1('}')
|
|
|
- } else if c == containerArrayElem {
|
|
|
+func (e *jsonEncDriver) WriteArrayStart(length int) {
|
|
|
+ if e.d {
|
|
|
+ e.dl++
|
|
|
+ }
|
|
|
+ e.w.writen1('[')
|
|
|
+ e.c = containerArrayStart
|
|
|
+}
|
|
|
+
|
|
|
+func (e *jsonEncDriver) WriteArrayElem() {
|
|
|
+ if e.c != containerArrayStart {
|
|
|
+ e.w.writen1(',')
|
|
|
+ }
|
|
|
+ if e.d {
|
|
|
+ e.writeIndent()
|
|
|
+ }
|
|
|
+ e.c = containerArrayElem
|
|
|
+}
|
|
|
+
|
|
|
+func (e *jsonEncDriver) WriteArrayEnd() {
|
|
|
+ if e.d {
|
|
|
+ e.dl--
|
|
|
if e.c != containerArrayStart {
|
|
|
- e.w.writen1(',')
|
|
|
- }
|
|
|
- if e.d {
|
|
|
e.writeIndent()
|
|
|
}
|
|
|
- } else if c == containerArrayEnd {
|
|
|
- if e.d {
|
|
|
- e.dl--
|
|
|
- if e.c != containerArrayStart {
|
|
|
- e.writeIndent()
|
|
|
- }
|
|
|
+ }
|
|
|
+ e.w.writen1(']')
|
|
|
+ e.c = containerArrayEnd
|
|
|
+}
|
|
|
+
|
|
|
+func (e *jsonEncDriver) WriteMapStart(length int) {
|
|
|
+ if e.d {
|
|
|
+ e.dl++
|
|
|
+ }
|
|
|
+ e.w.writen1('{')
|
|
|
+ e.c = containerMapStart
|
|
|
+}
|
|
|
+
|
|
|
+func (e *jsonEncDriver) WriteMapElemKey() {
|
|
|
+ if e.c != containerMapStart {
|
|
|
+ e.w.writen1(',')
|
|
|
+ }
|
|
|
+ if e.d {
|
|
|
+ e.writeIndent()
|
|
|
+ }
|
|
|
+ e.c = containerMapKey
|
|
|
+}
|
|
|
+
|
|
|
+func (e *jsonEncDriver) WriteMapElemValue() {
|
|
|
+ if e.d {
|
|
|
+ e.w.writen2(':', ' ')
|
|
|
+ } else {
|
|
|
+ e.w.writen1(':')
|
|
|
+ }
|
|
|
+ e.c = containerMapValue
|
|
|
+}
|
|
|
+
|
|
|
+func (e *jsonEncDriver) WriteMapEnd() {
|
|
|
+ if e.d {
|
|
|
+ e.dl--
|
|
|
+ if e.c != containerMapStart {
|
|
|
+ e.writeIndent()
|
|
|
}
|
|
|
- e.w.writen1(']')
|
|
|
}
|
|
|
- e.c = c
|
|
|
+ e.w.writen1('}')
|
|
|
+ e.c = containerMapEnd
|
|
|
}
|
|
|
|
|
|
+// func (e *jsonEncDriver) sendContainerState(c containerState) {
|
|
|
+// // determine whether to output separators
|
|
|
+// switch c {
|
|
|
+// case containerMapKey:
|
|
|
+// if e.c != containerMapStart {
|
|
|
+// e.w.writen1(',')
|
|
|
+// }
|
|
|
+// if e.d {
|
|
|
+// e.writeIndent()
|
|
|
+// }
|
|
|
+// case containerMapValue:
|
|
|
+// if e.d {
|
|
|
+// e.w.writen2(':', ' ')
|
|
|
+// } else {
|
|
|
+// e.w.writen1(':')
|
|
|
+// }
|
|
|
+// case containerMapEnd:
|
|
|
+// if e.d {
|
|
|
+// e.dl--
|
|
|
+// if e.c != containerMapStart {
|
|
|
+// e.writeIndent()
|
|
|
+// }
|
|
|
+// }
|
|
|
+// e.w.writen1('}')
|
|
|
+// case containerArrayElem:
|
|
|
+// if e.c != containerArrayStart {
|
|
|
+// e.w.writen1(',')
|
|
|
+// }
|
|
|
+// if e.d {
|
|
|
+// e.writeIndent()
|
|
|
+// }
|
|
|
+// case containerArrayEnd:
|
|
|
+// if e.d {
|
|
|
+// e.dl--
|
|
|
+// if e.c != containerArrayStart {
|
|
|
+// e.writeIndent()
|
|
|
+// }
|
|
|
+// }
|
|
|
+// e.w.writen1(']')
|
|
|
+// }
|
|
|
+// e.c = c
|
|
|
+// }
|
|
|
+
|
|
|
func (e *jsonEncDriver) writeIndent() {
|
|
|
e.w.writen1('\n')
|
|
|
if x := len(e.ds) * int(e.dl); x <= jsonSpacesOrTabsLen {
|
|
|
@@ -201,14 +289,14 @@ func (e *jsonEncDriver) writeIndent() {
|
|
|
}
|
|
|
|
|
|
func (e *jsonEncDriver) EncodeNil() {
|
|
|
- e.w.writeb(jsonLiterals[9:13]) // null
|
|
|
+ e.w.writen4('n', 'u', 'l', 'l') // e.w.writeb(jsonLiterals[9:13]) // null
|
|
|
}
|
|
|
|
|
|
func (e *jsonEncDriver) EncodeBool(b bool) {
|
|
|
if b {
|
|
|
- e.w.writeb(jsonLiterals[0:4]) // true
|
|
|
+ e.w.writen4('t', 'r', 'u', 'e') // e.w.writeb(jsonLiterals[0:4]) // true
|
|
|
} else {
|
|
|
- e.w.writeb(jsonLiterals[4:9]) // false
|
|
|
+ e.w.writen5('f', 'a', 'l', 's', 'e') // e.w.writeb(jsonLiterals[4:9]) // false
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -217,20 +305,19 @@ func (e *jsonEncDriver) EncodeFloat32(f float32) {
|
|
|
}
|
|
|
|
|
|
func (e *jsonEncDriver) EncodeFloat64(f float64) {
|
|
|
- // e.w.writestr(strconv.FormatFloat(f, 'E', -1, 64))
|
|
|
e.encodeFloat(f, 64)
|
|
|
}
|
|
|
|
|
|
func (e *jsonEncDriver) encodeFloat(f float64, numbits int) {
|
|
|
x := strconv.AppendFloat(e.b[:0], f, 'G', -1, numbits)
|
|
|
- e.w.writeb(x)
|
|
|
- if bytes.IndexByte(x, 'E') == -1 && bytes.IndexByte(x, '.') == -1 {
|
|
|
- e.w.writen2('.', '0')
|
|
|
+ // if bytes.IndexByte(x, 'E') == -1 && bytes.IndexByte(x, '.') == -1 {
|
|
|
+ if !jsonIsFloatBytesB2(x) {
|
|
|
+ x = append(x, '.', '0')
|
|
|
}
|
|
|
+ e.w.writeb(x)
|
|
|
}
|
|
|
|
|
|
func (e *jsonEncDriver) EncodeInt(v int64) {
|
|
|
- // if e.h.IntegerAsString == 'A' || e.h.IntegerAsString == 'L' && (v > 1<<53 || v < -(1<<53)) {
|
|
|
if x := e.h.IntegerAsString; x == 'A' || x == 'L' && (v > 1<<53 || v < -(1<<53)) {
|
|
|
e.w.writen1('"')
|
|
|
e.w.writeb(strconv.AppendInt(e.b[:0], v, 10))
|
|
|
@@ -241,7 +328,6 @@ func (e *jsonEncDriver) EncodeInt(v int64) {
|
|
|
}
|
|
|
|
|
|
func (e *jsonEncDriver) EncodeUint(v uint64) {
|
|
|
- // if e.h.IntegerAsString == 'A' || e.h.IntegerAsString == 'L' && v > 1<<53 {
|
|
|
if x := e.h.IntegerAsString; x == 'A' || x == 'L' && v > 1<<53 {
|
|
|
e.w.writen1('"')
|
|
|
e.w.writeb(strconv.AppendUint(e.b[:0], v, 10))
|
|
|
@@ -253,7 +339,7 @@ func (e *jsonEncDriver) EncodeUint(v uint64) {
|
|
|
|
|
|
func (e *jsonEncDriver) EncodeExt(rv interface{}, xtag uint64, ext Ext, en *Encoder) {
|
|
|
if v := ext.ConvertExt(rv); v == nil {
|
|
|
- e.w.writeb(jsonLiterals[9:13]) // null // e.EncodeNil()
|
|
|
+ e.w.writen4('n', 'u', 'l', 'l') // e.w.writeb(jsonLiterals[9:13]) // null // e.EncodeNil()
|
|
|
} else {
|
|
|
en.encode(v)
|
|
|
}
|
|
|
@@ -262,35 +348,17 @@ func (e *jsonEncDriver) EncodeExt(rv interface{}, xtag uint64, ext Ext, en *Enco
|
|
|
func (e *jsonEncDriver) EncodeRawExt(re *RawExt, en *Encoder) {
|
|
|
// only encodes re.Value (never re.Data)
|
|
|
if re.Value == nil {
|
|
|
- e.w.writeb(jsonLiterals[9:13]) // null // e.EncodeNil()
|
|
|
+ e.w.writen4('n', 'u', 'l', 'l') // e.w.writeb(jsonLiterals[9:13]) // null // e.EncodeNil()
|
|
|
} else {
|
|
|
en.encode(re.Value)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (e *jsonEncDriver) EncodeArrayStart(length int) {
|
|
|
- if e.d {
|
|
|
- e.dl++
|
|
|
- }
|
|
|
- e.w.writen1('[')
|
|
|
- e.c = containerArrayStart
|
|
|
-}
|
|
|
-
|
|
|
-func (e *jsonEncDriver) EncodeMapStart(length int) {
|
|
|
- if e.d {
|
|
|
- e.dl++
|
|
|
- }
|
|
|
- e.w.writen1('{')
|
|
|
- e.c = containerMapStart
|
|
|
-}
|
|
|
-
|
|
|
func (e *jsonEncDriver) EncodeString(c charEncoding, v string) {
|
|
|
- // e.w.writestr(strconv.Quote(v))
|
|
|
e.quoteStr(v)
|
|
|
}
|
|
|
|
|
|
func (e *jsonEncDriver) EncodeSymbol(v string) {
|
|
|
- // e.EncodeString(c_UTF8, v)
|
|
|
e.quoteStr(v)
|
|
|
}
|
|
|
|
|
|
@@ -312,7 +380,6 @@ func (e *jsonEncDriver) EncodeStringBytes(c charEncoding, v []byte) {
|
|
|
e.w.writeb(e.bs)
|
|
|
e.w.writen1('"')
|
|
|
} else {
|
|
|
- // e.EncodeString(c, string(v))
|
|
|
e.quoteStr(stringView(v))
|
|
|
}
|
|
|
}
|
|
|
@@ -326,13 +393,13 @@ func (e *jsonEncDriver) quoteStr(s string) {
|
|
|
const hex = "0123456789abcdef"
|
|
|
w := e.w
|
|
|
w.writen1('"')
|
|
|
- start := 0
|
|
|
- for i := 0; i < len(s); {
|
|
|
+ var start int
|
|
|
+ for i, slen := 0, len(s); i < slen; {
|
|
|
// encode all bytes < 0x20 (except \r, \n).
|
|
|
// also encode < > & to prevent security holes when served to some browsers.
|
|
|
if b := s[i]; b < utf8.RuneSelf {
|
|
|
// if 0x20 <= b && b != '\\' && b != '"' && b != '<' && b != '>' && b != '&' {
|
|
|
- if jsonCharHtmlSafeSet[b] || (e.h.HTMLCharsAsIs && jsonCharSafeSet[b]) {
|
|
|
+ if jsonCharHtmlSafeSet.isset(b) || (e.h.HTMLCharsAsIs && jsonCharSafeSet.isset(b)) {
|
|
|
i++
|
|
|
continue
|
|
|
}
|
|
|
@@ -390,6 +457,16 @@ func (e *jsonEncDriver) quoteStr(s string) {
|
|
|
w.writen1('"')
|
|
|
}
|
|
|
|
|
|
+func (e *jsonEncDriver) atEndOfEncode() {
|
|
|
+ if e.h.TermWhitespace {
|
|
|
+ if e.d {
|
|
|
+ e.w.writen1('\n')
|
|
|
+ } else {
|
|
|
+ e.w.writen1(' ')
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
type jsonDecDriver struct {
|
|
|
noBuiltInTypes
|
|
|
d *Decoder
|
|
|
@@ -400,6 +477,8 @@ type jsonDecDriver struct {
|
|
|
// tok is used to store the token read right after skipWhiteSpace.
|
|
|
tok uint8
|
|
|
|
|
|
+ fnull bool // found null from appendStringAsBytes
|
|
|
+
|
|
|
bstr [8]byte // scratch used for string \UXXX parsing
|
|
|
b [64]byte // scratch, used for parsing strings or numbers
|
|
|
b2 [64]byte // scratch, used only for decodeBytes (after base64)
|
|
|
@@ -412,7 +491,7 @@ type jsonDecDriver struct {
|
|
|
|
|
|
func jsonIsWS(b byte) bool {
|
|
|
// return b == ' ' || b == '\t' || b == '\r' || b == '\n'
|
|
|
- return jsonCharWhitespaceSet[b]
|
|
|
+ return jsonCharWhitespaceSet.isset(b)
|
|
|
}
|
|
|
|
|
|
func (d *jsonDecDriver) uncacheRead() {
|
|
|
@@ -422,47 +501,167 @@ func (d *jsonDecDriver) uncacheRead() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (d *jsonDecDriver) sendContainerState(c containerState) {
|
|
|
+func (d *jsonDecDriver) ReadMapStart() int {
|
|
|
if d.tok == 0 {
|
|
|
d.tok = d.r.skip(&jsonCharWhitespaceSet)
|
|
|
}
|
|
|
- var xc uint8 // char expected
|
|
|
- if c == containerMapKey {
|
|
|
- if d.c != containerMapStart {
|
|
|
- xc = ','
|
|
|
- }
|
|
|
- } else if c == containerMapValue {
|
|
|
- xc = ':'
|
|
|
- } else if c == containerMapEnd {
|
|
|
- xc = '}'
|
|
|
- } else if c == containerArrayElem {
|
|
|
- if d.c != containerArrayStart {
|
|
|
- xc = ','
|
|
|
+ if d.tok != '{' {
|
|
|
+ d.d.errorf("json: expect char '%c' but got char '%c'", '{', d.tok)
|
|
|
+ }
|
|
|
+ d.tok = 0
|
|
|
+ d.c = containerMapStart
|
|
|
+ return -1
|
|
|
+}
|
|
|
+
|
|
|
+func (d *jsonDecDriver) ReadArrayStart() int {
|
|
|
+ if d.tok == 0 {
|
|
|
+ d.tok = d.r.skip(&jsonCharWhitespaceSet)
|
|
|
+ }
|
|
|
+ if d.tok != '[' {
|
|
|
+ d.d.errorf("json: expect char '%c' but got char '%c'", '[', d.tok)
|
|
|
+ }
|
|
|
+ d.tok = 0
|
|
|
+ d.c = containerArrayStart
|
|
|
+ return -1
|
|
|
+}
|
|
|
+
|
|
|
+func (d *jsonDecDriver) CheckBreak() bool {
|
|
|
+ if d.tok == 0 {
|
|
|
+ d.tok = d.r.skip(&jsonCharWhitespaceSet)
|
|
|
+ }
|
|
|
+ return d.tok == '}' || d.tok == ']'
|
|
|
+}
|
|
|
+
|
|
|
+func (d *jsonDecDriver) ReadArrayElem() {
|
|
|
+ if d.tok == 0 {
|
|
|
+ d.tok = d.r.skip(&jsonCharWhitespaceSet)
|
|
|
+ }
|
|
|
+ if d.c != containerArrayStart {
|
|
|
+ const xc uint8 = ','
|
|
|
+ if d.tok != xc {
|
|
|
+ d.d.errorf("json: expect char '%c' but got char '%c'", xc, d.tok)
|
|
|
}
|
|
|
- } else if c == containerArrayEnd {
|
|
|
- xc = ']'
|
|
|
+ d.tok = 0
|
|
|
}
|
|
|
- if xc != 0 {
|
|
|
+ d.c = containerArrayElem
|
|
|
+}
|
|
|
+
|
|
|
+func (d *jsonDecDriver) ReadArrayEnd() {
|
|
|
+ if d.tok == 0 {
|
|
|
+ d.tok = d.r.skip(&jsonCharWhitespaceSet)
|
|
|
+ }
|
|
|
+ const xc uint8 = ']'
|
|
|
+ if d.tok != xc {
|
|
|
+ d.d.errorf("json: expect char '%c' but got char '%c'", xc, d.tok)
|
|
|
+ }
|
|
|
+ d.tok = 0
|
|
|
+ d.c = containerArrayEnd
|
|
|
+}
|
|
|
+
|
|
|
+func (d *jsonDecDriver) ReadMapElemKey() {
|
|
|
+ if d.tok == 0 {
|
|
|
+ d.tok = d.r.skip(&jsonCharWhitespaceSet)
|
|
|
+ }
|
|
|
+ if d.c != containerMapStart {
|
|
|
+ const xc uint8 = ','
|
|
|
if d.tok != xc {
|
|
|
d.d.errorf("json: expect char '%c' but got char '%c'", xc, d.tok)
|
|
|
}
|
|
|
d.tok = 0
|
|
|
}
|
|
|
- d.c = c
|
|
|
+ d.c = containerMapKey
|
|
|
}
|
|
|
|
|
|
-func (d *jsonDecDriver) CheckBreak() bool {
|
|
|
+func (d *jsonDecDriver) ReadMapElemValue() {
|
|
|
if d.tok == 0 {
|
|
|
d.tok = d.r.skip(&jsonCharWhitespaceSet)
|
|
|
}
|
|
|
- return d.tok == '}' || d.tok == ']'
|
|
|
+ const xc uint8 = ':'
|
|
|
+ if d.tok != xc {
|
|
|
+ d.d.errorf("json: expect char '%c' but got char '%c'", xc, d.tok)
|
|
|
+ }
|
|
|
+ d.tok = 0
|
|
|
+ d.c = containerMapValue
|
|
|
+}
|
|
|
+
|
|
|
+func (d *jsonDecDriver) ReadMapEnd() {
|
|
|
+ if d.tok == 0 {
|
|
|
+ d.tok = d.r.skip(&jsonCharWhitespaceSet)
|
|
|
+ }
|
|
|
+ const xc uint8 = '}'
|
|
|
+ if d.tok != xc {
|
|
|
+ d.d.errorf("json: expect char '%c' but got char '%c'", xc, d.tok)
|
|
|
+ }
|
|
|
+ d.tok = 0
|
|
|
+ d.c = containerMapEnd
|
|
|
+}
|
|
|
+
|
|
|
+// func (d *jsonDecDriver) readContainerState(c containerState, xc uint8, check bool) {
|
|
|
+// if d.tok == 0 {
|
|
|
+// d.tok = d.r.skip(&jsonCharWhitespaceSet)
|
|
|
+// }
|
|
|
+// if check {
|
|
|
+// if d.tok != xc {
|
|
|
+// d.d.errorf("json: expect char '%c' but got char '%c'", xc, d.tok)
|
|
|
+// }
|
|
|
+// d.tok = 0
|
|
|
+// }
|
|
|
+// d.c = c
|
|
|
+// }
|
|
|
+
|
|
|
+// func (d *jsonDecDriver) sendContainerState(c containerState) {
|
|
|
+// if d.tok == 0 {
|
|
|
+// d.tok = d.r.skip(&jsonCharWhitespaceSet)
|
|
|
+// }
|
|
|
+// var xc uint8 // char expected
|
|
|
+// switch c {
|
|
|
+// case containerMapKey:
|
|
|
+// if d.c != containerMapStart {
|
|
|
+// xc = ','
|
|
|
+// }
|
|
|
+// case containerMapValue:
|
|
|
+// xc = ':'
|
|
|
+// case containerMapEnd:
|
|
|
+// xc = '}'
|
|
|
+// case containerArrayElem:
|
|
|
+// if d.c != containerArrayStart {
|
|
|
+// xc = ','
|
|
|
+// }
|
|
|
+// case containerArrayEnd:
|
|
|
+// xc = ']'
|
|
|
+// }
|
|
|
+// if xc != 0 {
|
|
|
+// if d.tok != xc {
|
|
|
+// d.d.errorf("json: expect char '%c' but got char '%c'", xc, d.tok)
|
|
|
+// }
|
|
|
+// d.tok = 0
|
|
|
+// }
|
|
|
+// d.c = c
|
|
|
+// }
|
|
|
+
|
|
|
+// func (d *jsonDecDriver) readLiteralIdx(fromIdx, toIdx uint8) {
|
|
|
+// bs := d.r.readx(int(toIdx - fromIdx))
|
|
|
+// d.tok = 0
|
|
|
+// if jsonValidateSymbols && !bytes.Equal(bs, jsonLiterals[fromIdx:toIdx]) {
|
|
|
+// d.d.errorf("json: expecting %s: got %s", jsonLiterals[fromIdx:toIdx], bs)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+func (d *jsonDecDriver) readSymbol3(v1, v2, v3 uint8) {
|
|
|
+ b1, b2, b3 := d.r.readn3()
|
|
|
+ d.tok = 0
|
|
|
+ if jsonValidateSymbols && (b1 != v1 || b2 != v2 || b3 != v3) {
|
|
|
+ d.d.errorf("json: expecting %c, %c, %c: got %c, %c, %c", b1, b2, b3, v1, v2, v3)
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-func (d *jsonDecDriver) readStrIdx(fromIdx, toIdx uint8) {
|
|
|
- bs := d.r.readx(int(toIdx - fromIdx))
|
|
|
+func (d *jsonDecDriver) readSymbol4(v1, v2, v3, v4 uint8) {
|
|
|
+ b1, b2, b3, b4 := d.r.readn4()
|
|
|
d.tok = 0
|
|
|
- if jsonValidateSymbols && !bytes.Equal(bs, jsonLiterals[fromIdx:toIdx]) {
|
|
|
- d.d.errorf("json: expecting %s: got %s", jsonLiterals[fromIdx:toIdx], bs)
|
|
|
+ if jsonValidateSymbols && (b1 != v1 || b2 != v2 || b3 != v3 || b4 != v4) {
|
|
|
+ d.d.errorf("json: expecting %c, %c, %c, %c: got %c, %c, %c, %c", b1, b2, b3, b4, v1, v2, v3, v4)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
@@ -472,7 +671,7 @@ func (d *jsonDecDriver) TryDecodeAsNil() bool {
|
|
|
d.tok = d.r.skip(&jsonCharWhitespaceSet)
|
|
|
}
|
|
|
if d.tok == 'n' {
|
|
|
- d.readStrIdx(10, 13) // ull
|
|
|
+ d.readSymbol3('u', 'l', 'l') // d.readLiteralIdx(10, 13) // ull
|
|
|
return true
|
|
|
}
|
|
|
return false
|
|
|
@@ -483,41 +682,17 @@ func (d *jsonDecDriver) DecodeBool() bool {
|
|
|
d.tok = d.r.skip(&jsonCharWhitespaceSet)
|
|
|
}
|
|
|
if d.tok == 'f' {
|
|
|
- d.readStrIdx(5, 9) // alse
|
|
|
+ d.readSymbol4('a', 'l', 's', 'e') // d.readLiteralIdx(5, 9) // alse
|
|
|
return false
|
|
|
}
|
|
|
if d.tok == 't' {
|
|
|
- d.readStrIdx(1, 4) // rue
|
|
|
+ d.readSymbol3('r', 'u', 'e') // d.readLiteralIdx(1, 4) // rue
|
|
|
return true
|
|
|
}
|
|
|
d.d.errorf("json: decode bool: got first char %c", d.tok)
|
|
|
return false // "unreachable"
|
|
|
}
|
|
|
|
|
|
-func (d *jsonDecDriver) ReadMapStart() int {
|
|
|
- if d.tok == 0 {
|
|
|
- d.tok = d.r.skip(&jsonCharWhitespaceSet)
|
|
|
- }
|
|
|
- if d.tok != '{' {
|
|
|
- d.d.errorf("json: expect char '%c' but got char '%c'", '{', d.tok)
|
|
|
- }
|
|
|
- d.tok = 0
|
|
|
- d.c = containerMapStart
|
|
|
- return -1
|
|
|
-}
|
|
|
-
|
|
|
-func (d *jsonDecDriver) ReadArrayStart() int {
|
|
|
- if d.tok == 0 {
|
|
|
- d.tok = d.r.skip(&jsonCharWhitespaceSet)
|
|
|
- }
|
|
|
- if d.tok != '[' {
|
|
|
- d.d.errorf("json: expect char '%c' but got char '%c'", '[', d.tok)
|
|
|
- }
|
|
|
- d.tok = 0
|
|
|
- d.c = containerArrayStart
|
|
|
- return -1
|
|
|
-}
|
|
|
-
|
|
|
func (d *jsonDecDriver) ContainerType() (vt valueType) {
|
|
|
// check container type by checking the first char
|
|
|
if d.tok == 0 {
|
|
|
@@ -548,10 +723,8 @@ func (d *jsonDecDriver) decNumBytes() (bs []byte) {
|
|
|
} else {
|
|
|
d.r.unreadn1()
|
|
|
bs = d.r.readTo(d.bs[:0], &jsonNumSet)
|
|
|
- // bs = d.r.readbUntilAny(d.bs[:0], " \t\n:,{}[]")
|
|
|
}
|
|
|
d.tok = 0
|
|
|
- // fmt.Printf(">>>> decNumBytes: returning: '%s'\n", bs)
|
|
|
return bs
|
|
|
}
|
|
|
|
|
|
@@ -567,10 +740,6 @@ func (d *jsonDecDriver) DecodeUint(bitsize uint8) (u uint64) {
|
|
|
|
|
|
func (d *jsonDecDriver) DecodeInt(bitsize uint8) (i int64) {
|
|
|
bs := d.decNumBytes()
|
|
|
- // if bytes.ContainsAny(bs, ".eE") {
|
|
|
- // d.d.errorf("json: decoding int, but found one or more of the chars: .eE: %s", bs)
|
|
|
- // return
|
|
|
- // }
|
|
|
i, err := strconv.ParseInt(stringView(bs), 10, int(bitsize))
|
|
|
if err != nil {
|
|
|
d.d.errorf("json: decode int from %s: %v", bs, err)
|
|
|
@@ -614,10 +783,15 @@ func (d *jsonDecDriver) DecodeBytes(bs []byte, zerocopy bool) (bsOut []byte) {
|
|
|
return
|
|
|
}
|
|
|
d.appendStringAsBytes()
|
|
|
- // if appendStringAsBytes returned a zero-len slice, then treat as nil.
|
|
|
- // This should only happen for null, and "".
|
|
|
+ // base64 encodes []byte{} as "", and we encode nil []byte as null.
|
|
|
+ // Consequently, base64 should decode null as a nil []byte, and "" as an empty []byte{}.
|
|
|
+ // appendStringAsBytes returns a zero-len slice for both, so as not to reset d.bs.
|
|
|
+ // However, it sets a fnull field to true, so we can check if a null was found.
|
|
|
if len(d.bs) == 0 {
|
|
|
- return nil
|
|
|
+ if d.fnull {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return []byte{}
|
|
|
}
|
|
|
bs0 := d.bs
|
|
|
slen := base64.StdEncoding.DecodedLen(len(bs0))
|
|
|
@@ -660,19 +834,21 @@ func (d *jsonDecDriver) appendStringAsBytes() {
|
|
|
d.tok = d.r.skip(&jsonCharWhitespaceSet)
|
|
|
}
|
|
|
|
|
|
+ d.fnull = false
|
|
|
if d.tok != '"' {
|
|
|
// d.d.errorf("json: expect char '%c' but got char '%c'", '"', d.tok)
|
|
|
// handle non-string scalar: null, true, false or a number
|
|
|
switch d.tok {
|
|
|
case 'n':
|
|
|
- d.readStrIdx(10, 13) // ull
|
|
|
+ d.readSymbol3('u', 'l', 'l') // d.readLiteralIdx(10, 13) // ull
|
|
|
d.bs = d.bs[:0]
|
|
|
+ d.fnull = true
|
|
|
case 'f':
|
|
|
- d.readStrIdx(5, 9) // alse
|
|
|
+ d.readSymbol4('a', 'l', 's', 'e') // d.readLiteralIdx(5, 9) // alse
|
|
|
d.bs = d.bs[:5]
|
|
|
copy(d.bs, "false")
|
|
|
case 't':
|
|
|
- d.readStrIdx(1, 4) // rue
|
|
|
+ d.readSymbol3('r', 'u', 'e') // d.readLiteralIdx(1, 4) // rue
|
|
|
d.bs = d.bs[:4]
|
|
|
copy(d.bs, "true")
|
|
|
default:
|
|
|
@@ -686,26 +862,38 @@ func (d *jsonDecDriver) appendStringAsBytes() {
|
|
|
|
|
|
d.tok = 0
|
|
|
r := d.r
|
|
|
- var cs []byte
|
|
|
+ var cs = r.readUntil(d.b2[:0], '"')
|
|
|
+ var cslen = len(cs)
|
|
|
+ var c uint8
|
|
|
v := d.bs[:0]
|
|
|
- // var c uint8
|
|
|
- for i := 0; ; i++ {
|
|
|
- if i == len(cs) {
|
|
|
+ // append on each byte seen can be expensive, so we just
|
|
|
+ // keep track of where we last read a contiguous set of
|
|
|
+ // non-special bytes (using cursor variable),
|
|
|
+ // and when we see a special byte
|
|
|
+ // e.g. end-of-slice, " or \,
|
|
|
+ // we will append the full range into the v slice before proceeding
|
|
|
+ for i, cursor := 0, 0; ; {
|
|
|
+ if i == cslen {
|
|
|
+ v = append(v, cs[cursor:]...)
|
|
|
cs = r.readUntil(d.b2[:0], '"')
|
|
|
- i = 0
|
|
|
+ cslen = len(cs)
|
|
|
+ i, cursor = 0, 0
|
|
|
}
|
|
|
- if cs[i] == '"' {
|
|
|
+ c = cs[i]
|
|
|
+ if c == '"' {
|
|
|
+ v = append(v, cs[cursor:i]...)
|
|
|
break
|
|
|
}
|
|
|
- if cs[i] != '\\' {
|
|
|
- v = append(v, cs[i])
|
|
|
+ if c != '\\' {
|
|
|
+ i++
|
|
|
continue
|
|
|
}
|
|
|
- // cs[i] == '\\'
|
|
|
+ v = append(v, cs[cursor:i]...)
|
|
|
i++
|
|
|
- switch cs[i] {
|
|
|
+ c = cs[i]
|
|
|
+ switch c {
|
|
|
case '"', '\\', '/', '\'':
|
|
|
- v = append(v, cs[i])
|
|
|
+ v = append(v, c)
|
|
|
case 'b':
|
|
|
v = append(v, '\b')
|
|
|
case 'f':
|
|
|
@@ -717,50 +905,68 @@ func (d *jsonDecDriver) appendStringAsBytes() {
|
|
|
case 't':
|
|
|
v = append(v, '\t')
|
|
|
case 'u':
|
|
|
- rr := d.jsonU4Arr([4]byte{cs[i+1], cs[i+2], cs[i+3], cs[i+4]})
|
|
|
+ var r rune
|
|
|
+ var rr uint32
|
|
|
+ c = cs[i+4] // may help reduce bounds-checking
|
|
|
+ for j := 1; j < 5; j++ {
|
|
|
+ c = jsonU4Set[cs[i+j]]
|
|
|
+ if c == jsonU4SetErrVal {
|
|
|
+ d.d.errorf(`json: unquoteStr: invalid hex char in \u unicode sequence: %q`, c)
|
|
|
+ }
|
|
|
+ rr = rr*16 + uint32(c)
|
|
|
+ }
|
|
|
+ r = rune(rr)
|
|
|
i += 4
|
|
|
- // fmt.Printf("$$$$$$$$$: is surrogate: %v\n", utf16.IsSurrogate(rr))
|
|
|
- if utf16.IsSurrogate(rr) {
|
|
|
- // fmt.Printf(">>>> checking utf16 surrogate\n")
|
|
|
- if !(cs[i+1] == '\\' && cs[i+2] == 'u') {
|
|
|
+ if utf16.IsSurrogate(r) {
|
|
|
+ if !(cs[i+2] == 'u' && cs[i+i] == '\\') {
|
|
|
d.d.errorf(`json: unquoteStr: invalid unicode sequence. Expecting \u`)
|
|
|
return
|
|
|
}
|
|
|
i += 2
|
|
|
- rr = utf16.DecodeRune(rr, d.jsonU4Arr([4]byte{cs[i+1], cs[i+2], cs[i+3], cs[i+4]}))
|
|
|
+ c = cs[i+4] // may help reduce bounds-checking
|
|
|
+ var rr1 uint32
|
|
|
+ for j := 1; j < 5; j++ {
|
|
|
+ c = jsonU4Set[cs[i+j]]
|
|
|
+ if c == jsonU4SetErrVal {
|
|
|
+ d.d.errorf(`json: unquoteStr: invalid hex char in \u unicode sequence: %q`, c)
|
|
|
+ }
|
|
|
+ rr1 = rr1*16 + uint32(c)
|
|
|
+ }
|
|
|
+ r = utf16.DecodeRune(r, rune(rr1))
|
|
|
i += 4
|
|
|
}
|
|
|
- w2 := utf8.EncodeRune(d.bstr[:], rr)
|
|
|
+ w2 := utf8.EncodeRune(d.bstr[:], r)
|
|
|
v = append(v, d.bstr[:w2]...)
|
|
|
default:
|
|
|
- d.d.errorf("json: unsupported escaped value: %c", cs[i])
|
|
|
+ d.d.errorf("json: unsupported escaped value: %c", c)
|
|
|
}
|
|
|
+ i++
|
|
|
+ cursor = i
|
|
|
}
|
|
|
d.bs = v
|
|
|
}
|
|
|
|
|
|
-func (d *jsonDecDriver) jsonU4Arr(bs [4]byte) (r rune) {
|
|
|
- // u, _ := strconv.ParseUint(string(d.bstr[:4]), 16, 64)
|
|
|
- var u uint32
|
|
|
- for _, v := range bs {
|
|
|
- if '0' <= v && v <= '9' {
|
|
|
- v = v - '0'
|
|
|
- } else if 'a' <= v && v <= 'z' {
|
|
|
- v = v - 'a' + 10
|
|
|
- } else if 'A' <= v && v <= 'Z' {
|
|
|
- v = v - 'A' + 10
|
|
|
- } else {
|
|
|
- d.d.errorf(`json: unquoteStr: invalid hex char in \u unicode sequence: %q`, v)
|
|
|
- return 0
|
|
|
- }
|
|
|
- u = u*16 + uint32(v)
|
|
|
- }
|
|
|
- // fmt.Printf(">>>>>>>> jsonU4Arr: %v, %s\n", rune(u), string(rune(u)))
|
|
|
- return rune(u)
|
|
|
-}
|
|
|
+// func (d *jsonDecDriver) jsonU4Arr(bs [4]byte) (r rune) {
|
|
|
+// // u, _ := strconv.ParseUint(string(d.bstr[:4]), 16, 64)
|
|
|
+// var u uint32
|
|
|
+// for _, v := range bs {
|
|
|
+// if '0' <= v && v <= '9' {
|
|
|
+// v = v - '0'
|
|
|
+// } else if 'a' <= v && v <= 'f' {
|
|
|
+// v = v - 'a' + 10
|
|
|
+// } else if 'A' <= v && v <= 'f' {
|
|
|
+// v = v - 'A' + 10
|
|
|
+// } else {
|
|
|
+// // d.d.errorf(`json: unquoteStr: invalid hex char in \u unicode sequence: %q`, v)
|
|
|
+// return utf8.RuneError
|
|
|
+// }
|
|
|
+// u = u*16 + uint32(v)
|
|
|
+// }
|
|
|
+// return rune(u)
|
|
|
+// }
|
|
|
|
|
|
func (d *jsonDecDriver) DecodeNaked() {
|
|
|
- z := &d.d.n
|
|
|
+ z := d.d.n
|
|
|
// var decodeFurther bool
|
|
|
|
|
|
if d.tok == 0 {
|
|
|
@@ -768,24 +974,20 @@ func (d *jsonDecDriver) DecodeNaked() {
|
|
|
}
|
|
|
switch d.tok {
|
|
|
case 'n':
|
|
|
- d.readStrIdx(10, 13) // ull
|
|
|
+ d.readSymbol3('u', 'l', 'l') // d.readLiteralIdx(10, 13) // ull
|
|
|
z.v = valueTypeNil
|
|
|
case 'f':
|
|
|
- d.readStrIdx(5, 9) // alse
|
|
|
+ d.readSymbol4('a', 'l', 's', 'e') // d.readLiteralIdx(5, 9) // alse
|
|
|
z.v = valueTypeBool
|
|
|
z.b = false
|
|
|
case 't':
|
|
|
- d.readStrIdx(1, 4) // rue
|
|
|
+ d.readSymbol3('r', 'u', 'e') // d.readLiteralIdx(1, 4) // rue
|
|
|
z.v = valueTypeBool
|
|
|
z.b = true
|
|
|
case '{':
|
|
|
- z.v = valueTypeMap
|
|
|
- // d.tok = 0 // don't consume. kInterfaceNaked will call ReadMapStart
|
|
|
- // decodeFurther = true
|
|
|
+ z.v = valueTypeMap // don't consume. kInterfaceNaked will call ReadMapStart
|
|
|
case '[':
|
|
|
- z.v = valueTypeArray
|
|
|
- // d.tok = 0 // don't consume. kInterfaceNaked will call ReadArrayStart
|
|
|
- // decodeFurther = true
|
|
|
+ z.v = valueTypeArray // don't consume. kInterfaceNaked will call ReadArrayStart
|
|
|
case '"':
|
|
|
z.v = valueTypeString
|
|
|
z.s = d.DecodeString()
|
|
|
@@ -795,10 +997,7 @@ func (d *jsonDecDriver) DecodeNaked() {
|
|
|
if len(bs) == 0 {
|
|
|
d.d.errorf("json: decode number from empty string")
|
|
|
return
|
|
|
- } else if d.h.PreferFloat ||
|
|
|
- bytes.IndexByte(bs, '.') != -1 ||
|
|
|
- bytes.IndexByte(bs, 'e') != -1 ||
|
|
|
- bytes.IndexByte(bs, 'E') != -1 {
|
|
|
+ } else if d.h.PreferFloat || jsonIsFloatBytesB3(bs) { // bytes.IndexByte(bs, '.') != -1 ||...
|
|
|
// } else if d.h.PreferFloat || bytes.ContainsAny(bs, ".eE") {
|
|
|
z.v = valueTypeFloat
|
|
|
z.f, err = strconv.ParseFloat(stringView(bs), 64)
|
|
|
@@ -821,7 +1020,6 @@ func (d *jsonDecDriver) DecodeNaked() {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
- // fmt.Printf("DecodeNaked: Number: %T, %v\n", v, v)
|
|
|
}
|
|
|
// if decodeFurther {
|
|
|
// d.s.sc.retryRead()
|
|
|
@@ -829,14 +1027,6 @@ func (d *jsonDecDriver) DecodeNaked() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// func jsonAcceptNonWS(b byte) bool {
|
|
|
-// return !jsonCharWhitespaceSet[b]
|
|
|
-// }
|
|
|
-
|
|
|
-// func jsonAcceptDQuote(b byte) bool {
|
|
|
-// return b == '"'
|
|
|
-// }
|
|
|
-
|
|
|
//----------------------
|
|
|
|
|
|
// JsonHandle is a handle for JSON encoding format.
|
|
|
@@ -891,8 +1081,17 @@ type JsonHandle struct {
|
|
|
// If not set, we will examine the characters of the number and decode as an
|
|
|
// integer type if it doesn't have any of the characters [.eE].
|
|
|
PreferFloat bool
|
|
|
+
|
|
|
+ // TermWhitespace says that we add a whitespace character
|
|
|
+ // at the end of an encoding.
|
|
|
+ //
|
|
|
+ // The whitespace is important, especially if using numbers in a context
|
|
|
+ // where multiple items are written to a stream.
|
|
|
+ TermWhitespace bool
|
|
|
}
|
|
|
|
|
|
+func (h *JsonHandle) hasElemSeparators() bool { return true }
|
|
|
+
|
|
|
func (h *JsonHandle) SetInterfaceExt(rt reflect.Type, tag uint64, ext InterfaceExt) (err error) {
|
|
|
return h.SetExt(rt, tag, &setExtWrapper{i: ext})
|
|
|
}
|
|
|
@@ -942,11 +1141,32 @@ func (d *jsonDecDriver) reset() {
|
|
|
// d.n.reset()
|
|
|
}
|
|
|
|
|
|
-var jsonEncodeTerminate = []byte{' '}
|
|
|
+// func jsonIsFloatBytes(bs []byte) bool {
|
|
|
+// for _, v := range bs {
|
|
|
+// // if v == '.' || v == 'e' || v == 'E' {
|
|
|
+// if jsonIsFloatSet.isset(v) {
|
|
|
+// return true
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return false
|
|
|
+// }
|
|
|
+
|
|
|
+func jsonIsFloatBytesB2(bs []byte) bool {
|
|
|
+ return bytes.IndexByte(bs, '.') != -1 ||
|
|
|
+ bytes.IndexByte(bs, 'E') != -1
|
|
|
+}
|
|
|
|
|
|
-func (h *JsonHandle) rpcEncodeTerminate() []byte {
|
|
|
- return jsonEncodeTerminate
|
|
|
+func jsonIsFloatBytesB3(bs []byte) bool {
|
|
|
+ return bytes.IndexByte(bs, '.') != -1 ||
|
|
|
+ bytes.IndexByte(bs, 'E') != -1 ||
|
|
|
+ bytes.IndexByte(bs, 'e') != -1
|
|
|
}
|
|
|
|
|
|
+// var jsonEncodeTerminate = []byte{' '}
|
|
|
+
|
|
|
+// func (h *JsonHandle) rpcEncodeTerminate() []byte {
|
|
|
+// return jsonEncodeTerminate
|
|
|
+// }
|
|
|
+
|
|
|
var _ decDriver = (*jsonDecDriver)(nil)
|
|
|
var _ encDriver = (*jsonEncDriver)(nil)
|