Source File
stream.go
Belonging Package
encoding/json
package json
import (
)
func ( *Decoder) () { .d.disallowUnknownFields = true }
func ( *Decoder) ( interface{}) error {
if .err != nil {
return .err
}
if := .tokenPrepareForDecode(); != nil {
return
}
if !.tokenValueAllowed() {
return &SyntaxError{msg: "not at beginning of value", Offset: .InputOffset()}
}
.tokenValueEnd()
return
}
for >= 0 {
type Encoder struct {
w io.Writer
err error
escapeHTML bool
indentBuf *bytes.Buffer
indentPrefix string
indentValue string
}
func ( *Encoder) ( interface{}) error {
if .err != nil {
return .err
}
:= newEncodeState()
:= .marshal(, encOpts{escapeHTML: .escapeHTML})
if != nil {
return
}
.WriteByte('\n')
:= .Bytes()
if .indentPrefix != "" || .indentValue != "" {
if .indentBuf == nil {
.indentBuf = new(bytes.Buffer)
}
.indentBuf.Reset()
= Indent(.indentBuf, , .indentPrefix, .indentValue)
if != nil {
return
}
= .indentBuf.Bytes()
}
if _, = .w.Write(); != nil {
.err =
}
encodeStatePool.Put()
return
}
func ( *Encoder) (, string) {
.indentPrefix =
.indentValue =
}
func ( *Encoder) ( bool) {
.escapeHTML =
}
type RawMessage []byte
func ( *RawMessage) ( []byte) error {
if == nil {
return errors.New("json.RawMessage: UnmarshalJSON on nil pointer")
}
* = append((*)[0:0], ...)
return nil
}
var _ Marshaler = (*RawMessage)(nil)
var _ Unmarshaler = (*RawMessage)(nil)
type Token interface{}
const (
tokenTopValue = iota
tokenArrayStart
tokenArrayValue
tokenArrayComma
tokenObjectStart
tokenObjectKey
tokenObjectColon
tokenObjectValue
tokenObjectComma
)
switch .tokenState {
case tokenArrayComma:
, := .peek()
if != nil {
return
}
if != ',' {
return &SyntaxError{"expected comma after array element", .InputOffset()}
}
.scanp++
.tokenState = tokenArrayValue
case tokenObjectColon:
, := .peek()
if != nil {
return
}
if != ':' {
return &SyntaxError{"expected colon after object key", .InputOffset()}
}
.scanp++
.tokenState = tokenObjectValue
}
return nil
}
func ( *Decoder) () bool {
switch .tokenState {
case tokenTopValue, tokenArrayStart, tokenArrayValue, tokenObjectValue:
return true
}
return false
}
func ( *Decoder) () {
switch .tokenState {
case tokenArrayStart, tokenArrayValue:
.tokenState = tokenArrayComma
case tokenObjectValue:
.tokenState = tokenObjectComma
}
}
func ( *Decoder) () (Token, error) {
for {
, := .peek()
if != nil {
return nil,
}
switch {
case '[':
if !.tokenValueAllowed() {
return .tokenError()
}
.scanp++
.tokenStack = append(.tokenStack, .tokenState)
.tokenState = tokenArrayStart
return Delim('['), nil
case ']':
if .tokenState != tokenArrayStart && .tokenState != tokenArrayComma {
return .tokenError()
}
.scanp++
.tokenState = .tokenStack[len(.tokenStack)-1]
.tokenStack = .tokenStack[:len(.tokenStack)-1]
.tokenValueEnd()
return Delim(']'), nil
case '{':
if !.tokenValueAllowed() {
return .tokenError()
}
.scanp++
.tokenStack = append(.tokenStack, .tokenState)
.tokenState = tokenObjectStart
return Delim('{'), nil
case '}':
if .tokenState != tokenObjectStart && .tokenState != tokenObjectComma {
return .tokenError()
}
.scanp++
.tokenState = .tokenStack[len(.tokenStack)-1]
.tokenStack = .tokenStack[:len(.tokenStack)-1]
.tokenValueEnd()
return Delim('}'), nil
case ':':
if .tokenState != tokenObjectColon {
return .tokenError()
}
.scanp++
.tokenState = tokenObjectValue
continue
case ',':
if .tokenState == tokenArrayComma {
.scanp++
.tokenState = tokenArrayValue
continue
}
if .tokenState == tokenObjectComma {
.scanp++
.tokenState = tokenObjectKey
continue
}
return .tokenError()
case '"':
if .tokenState == tokenObjectStart || .tokenState == tokenObjectKey {
var string
:= .tokenState
.tokenState = tokenTopValue
:= .Decode(&)
.tokenState =
if != nil {
return nil,
}
.tokenState = tokenObjectColon
return , nil
}
fallthrough
default:
if !.tokenValueAllowed() {
return .tokenError()
}
var interface{}
if := .Decode(&); != nil {
return nil,
}
return , nil
}
}
}
func ( *Decoder) ( byte) (Token, error) {
var string
switch .tokenState {
case tokenTopValue:
= " looking for beginning of value"
case tokenArrayStart, tokenArrayValue, tokenObjectValue:
= " looking for beginning of value"
case tokenArrayComma:
= " after array element"
case tokenObjectKey:
= " looking for beginning of object key string"
case tokenObjectColon:
= " after object key"
case tokenObjectComma:
= " after object key:value pair"
}
return nil, &SyntaxError{"invalid character " + quoteChar() + , .InputOffset()}
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |