package gojay// TODO @afiune for now we are using the standard json unmarshaling but in// the future it would be great to implement one here inside this repoimport// DecodeInterface reads the next JSON-encoded value from the decoder's input (io.Reader) and stores it in the value pointed to by i.//// i must be an interface poiterfunc ( *Decoder) ( *interface{}) error {if .isPooled == 1 {panic(InvalidUsagePooledDecoderError("Invalid usage of pooled decoder")) } := .decodeInterface()return}func ( *Decoder) ( *interface{}) error { , , := .getObject()if != nil { .cursor = return }// if start & end are equal the object is a null, don't unmarshalif == {returnnil } := .data[:]if = json.Unmarshal(, ); != nil {return } .cursor = returnnil}// @afiune Maybe return the type as well?func ( *Decoder) () ( int, int, error) {// start cursorfor ; .cursor < .length || .read(); .cursor++ {switch .data[.cursor] {case' ', '\n', '\t', '\r', ',':continue// is nullcase'n': .cursor++ = .assertNull()if != nil {return }// Set start & end to the same cursor to indicate the object // is a null and should not be unmarshal = .cursor = .cursorreturncase't': = .cursor .cursor++ = .assertTrue()if != nil {return } = .cursor .cursor++return// is falsecase'f': = .cursor .cursor++ = .assertFalse()if != nil {return } = .cursor .cursor++return// is an objectcase'{': = .cursor .cursor++ , = .skipObject() .cursor = return// is stringcase'"': = .cursor .cursor++ , , = .getString() -- .cursor = return// is arraycase'[': = .cursor .cursor++ , = .skipArray() .cursor = returncase'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-': = .cursor , = .skipNumber() .cursor = returndefault: = .raiseInvalidJSONErr(.cursor)return } } = .raiseInvalidJSONErr(.cursor)return}// Add Values functions// AddInterface decodes the JSON value within an object or an array to a interface{}.func ( *Decoder) ( *interface{}) error {return .Interface()}// Interface decodes the JSON value within an object or an array to an interface{}.func ( *Decoder) ( *interface{}) error { := .decodeInterface()if != nil {return } .called |= 1returnnil}
The pages are generated with Goldsv0.8.2. (GOOS=linux 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 @zigo_101 (reachable from the left QR code) to get the latest news of Golds.