2020-04-23 19:39:20 +03:00
|
|
|
package json
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2020-11-23 11:16:31 +03:00
|
|
|
type boolDecoder struct {
|
|
|
|
structName string
|
|
|
|
fieldName string
|
|
|
|
}
|
2020-04-23 19:39:20 +03:00
|
|
|
|
2020-11-23 11:16:31 +03:00
|
|
|
func newBoolDecoder(structName, fieldName string) *boolDecoder {
|
|
|
|
return &boolDecoder{structName: structName, fieldName: fieldName}
|
2020-04-23 19:39:20 +03:00
|
|
|
}
|
|
|
|
|
2021-02-18 13:05:06 +03:00
|
|
|
func (d *boolDecoder) decodeStream(s *stream, depth int64, p unsafe.Pointer) error {
|
2020-07-30 16:41:53 +03:00
|
|
|
s.skipWhiteSpace()
|
2020-07-31 11:10:03 +03:00
|
|
|
for {
|
|
|
|
switch s.char() {
|
|
|
|
case 't':
|
|
|
|
if err := trueBytes(s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-14 23:27:15 +03:00
|
|
|
**(**bool)(unsafe.Pointer(&p)) = true
|
2020-07-31 11:10:03 +03:00
|
|
|
return nil
|
|
|
|
case 'f':
|
|
|
|
if err := falseBytes(s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-14 23:27:15 +03:00
|
|
|
**(**bool)(unsafe.Pointer(&p)) = false
|
2020-07-31 11:10:03 +03:00
|
|
|
return nil
|
2020-12-24 12:30:11 +03:00
|
|
|
case 'n':
|
|
|
|
if err := nullBytes(s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-02-16 19:51:42 +03:00
|
|
|
return nil
|
2020-07-31 11:10:03 +03:00
|
|
|
case nul:
|
|
|
|
if s.read() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
goto ERROR
|
2020-07-30 16:41:53 +03:00
|
|
|
}
|
2020-07-31 11:10:03 +03:00
|
|
|
break
|
2020-07-30 16:41:53 +03:00
|
|
|
}
|
2020-07-31 11:10:03 +03:00
|
|
|
ERROR:
|
2020-07-30 16:41:53 +03:00
|
|
|
return errUnexpectedEndOfJSON("bool", s.totalOffset())
|
|
|
|
}
|
|
|
|
|
2021-02-18 13:05:06 +03:00
|
|
|
func (d *boolDecoder) decode(buf []byte, cursor, depth int64, p unsafe.Pointer) (int64, error) {
|
2020-05-06 20:37:29 +03:00
|
|
|
cursor = skipWhiteSpace(buf, cursor)
|
2020-04-23 19:39:20 +03:00
|
|
|
switch buf[cursor] {
|
|
|
|
case 't':
|
2021-05-08 21:05:36 +03:00
|
|
|
if err := validateTrue(buf, cursor); err != nil {
|
|
|
|
return 0, err
|
2020-04-23 19:39:20 +03:00
|
|
|
}
|
2020-05-06 20:37:29 +03:00
|
|
|
cursor += 4
|
2020-11-14 23:27:15 +03:00
|
|
|
**(**bool)(unsafe.Pointer(&p)) = true
|
2020-07-30 16:41:53 +03:00
|
|
|
return cursor, nil
|
2020-04-23 19:39:20 +03:00
|
|
|
case 'f':
|
2021-05-08 21:05:36 +03:00
|
|
|
if err := validateFalse(buf, cursor); err != nil {
|
|
|
|
return 0, err
|
2020-04-23 19:39:20 +03:00
|
|
|
}
|
2020-05-06 20:37:29 +03:00
|
|
|
cursor += 5
|
2020-11-14 23:27:15 +03:00
|
|
|
**(**bool)(unsafe.Pointer(&p)) = false
|
2020-07-30 16:41:53 +03:00
|
|
|
return cursor, nil
|
2020-12-24 12:30:11 +03:00
|
|
|
case 'n':
|
2021-05-08 21:05:36 +03:00
|
|
|
if err := validateNull(buf, cursor); err != nil {
|
|
|
|
return 0, err
|
2020-12-24 12:30:11 +03:00
|
|
|
}
|
|
|
|
cursor += 4
|
|
|
|
return cursor, nil
|
2020-04-23 19:39:20 +03:00
|
|
|
}
|
2020-07-30 16:41:53 +03:00
|
|
|
return 0, errUnexpectedEndOfJSON("bool", cursor)
|
2020-04-23 19:39:20 +03:00
|
|
|
}
|