Example #1
0
func (e *codeNodeJSONDecoder) Decode(ptr **codeNode) error {
	s := e.s
	if tok, tokval, err := s.Scan(); err != nil {
		return err
	} else if tok == scanner.TNULL {
		*ptr = nil
		return nil
	} else if tok != scanner.TLBRACE {
		return fmt.Errorf("Unexpected %s at %d: %s; expected '{'", scanner.TokenName(tok), s.Pos(), string(tokval))
	}

	// Create the object if it doesn't exist.
	if *ptr == nil {
		*ptr = &codeNode{}
	}
	v := *ptr

	// Loop over key/value pairs.
	index := 0
	for {
		// Read in key.
		var key string
		tok, tokval, err := s.Scan()
		if err != nil {
			return err
		} else if tok == scanner.TRBRACE {
			return nil
		} else if tok == scanner.TCOMMA {
			if index == 0 {
				return fmt.Errorf("Unexpected comma at %d", s.Pos())
			}
			if tok, tokval, err = s.Scan(); err != nil {
				return err
			}
		}

		if tok != scanner.TSTRING {
			return fmt.Errorf("Unexpected %s at %d: %s; expected '{' or string", scanner.TokenName(tok), s.Pos(), string(tokval))
		} else {
			key = string(tokval)
		}

		// Read in the colon.
		if tok, tokval, err := s.Scan(); err != nil {
			return err
		} else if tok != scanner.TCOLON {
			return fmt.Errorf("Unexpected %s at %d: %s; expected colon", scanner.TokenName(tok), s.Pos(), string(tokval))
		}

		switch key {

		case "name":
			v := &v.Name

			if err := s.ReadString(v); err != nil {
				return err
			}

		case "kids":
			v := &v.Kids

			if err := NewcodeNodeJSONScanDecoder(s).DecodeArray(v); err != nil {
				return err
			}

		case "cl_weight":
			v := &v.CLWeight

			if err := s.ReadFloat64(v); err != nil {
				return err
			}

		case "touches":
			v := &v.Touches

			if err := s.ReadInt(v); err != nil {
				return err
			}

		case "min_t":
			v := &v.MinT

			if err := s.ReadInt64(v); err != nil {
				return err
			}

		case "max_t":
			v := &v.MaxT

			if err := s.ReadInt64(v); err != nil {
				return err
			}

		case "mean_t":
			v := &v.MeanT

			if err := s.ReadInt64(v); err != nil {
				return err
			}

		}

		index++
	}

	return nil
}
Example #2
0
func (e *codeResponseJSONDecoder) Decode(ptr **codeResponse) error {
	s := e.s
	if tok, tokval, err := s.Scan(); err != nil {
		return err
	} else if tok == scanner.TNULL {
		*ptr = nil
		return nil
	} else if tok != scanner.TLBRACE {
		return fmt.Errorf("Unexpected %s at %d: %s; expected '{'", scanner.TokenName(tok), s.Pos(), string(tokval))
	}

	// Create the object if it doesn't exist.
	if *ptr == nil {
		*ptr = &codeResponse{}
	}
	v := *ptr

	// Loop over key/value pairs.
	index := 0
	for {
		// Read in key.
		var key string
		tok, tokval, err := s.Scan()
		if err != nil {
			return err
		} else if tok == scanner.TRBRACE {
			return nil
		} else if tok == scanner.TCOMMA {
			if index == 0 {
				return fmt.Errorf("Unexpected comma at %d", s.Pos())
			}
			if tok, tokval, err = s.Scan(); err != nil {
				return err
			}
		}

		if tok != scanner.TSTRING {
			return fmt.Errorf("Unexpected %s at %d: %s; expected '{' or string", scanner.TokenName(tok), s.Pos(), string(tokval))
		} else {
			key = string(tokval)
		}

		// Read in the colon.
		if tok, tokval, err := s.Scan(); err != nil {
			return err
		} else if tok != scanner.TCOLON {
			return fmt.Errorf("Unexpected %s at %d: %s; expected colon", scanner.TokenName(tok), s.Pos(), string(tokval))
		}

		switch key {

		case "tree":
			v := &v.Tree

			if err := NewcodeNodeJSONScanDecoder(s).Decode(v); err != nil {
				return err
			}

		case "username":
			v := &v.Username

			if err := s.ReadString(v); err != nil {
				return err
			}

		}

		index++
	}

	return nil
}
func (e *MediaJSONDecoder) Decode(ptr **Media) error {
	s := e.s
	if tok, tokval, err := s.Scan(); err != nil {
		return err
	} else if tok == scanner.TNULL {
		*ptr = nil
		return nil
	} else if tok != scanner.TLBRACE {
		return fmt.Errorf("Unexpected %s at %d: %s; expected '{'", scanner.TokenName(tok), s.Pos(), string(tokval))
	}

	// Create the object if it doesn't exist.
	if *ptr == nil {
		*ptr = &Media{}
	}
	v := *ptr

	// Loop over key/value pairs.
	index := 0
	for {
		// Read in key.
		var key string
		tok, tokval, err := s.Scan()
		if err != nil {
			return err
		} else if tok == scanner.TRBRACE {
			return nil
		} else if tok == scanner.TCOMMA {
			if index == 0 {
				return fmt.Errorf("Unexpected comma at %d", s.Pos())
			}
			if tok, tokval, err = s.Scan(); err != nil {
				return err
			}
		}

		if tok != scanner.TSTRING {
			return fmt.Errorf("Unexpected %s at %d: %s; expected '{' or string", scanner.TokenName(tok), s.Pos(), string(tokval))
		} else {
			key = string(tokval)
		}

		// Read in the colon.
		if tok, tokval, err := s.Scan(); err != nil {
			return err
		} else if tok != scanner.TCOLON {
			return fmt.Errorf("Unexpected %s at %d: %s; expected colon", scanner.TokenName(tok), s.Pos(), string(tokval))
		}

		switch key {

		case "display_url":
			v := &v.DisplayURL

			if err := s.ReadString(v); err != nil {
				return err
			}

		case "expanded_url":
			v := &v.ExpandedURL

			if err := s.ReadString(v); err != nil {
				return err
			}

		case "id":
			v := &v.ID

			if err := s.ReadInt(v); err != nil {
				return err
			}

		case "id_str":
			v := &v.IDStr

			if err := s.ReadString(v); err != nil {
				return err
			}

		case "media_url":
			v := &v.MediaURL

			if err := s.ReadString(v); err != nil {
				return err
			}

		case "media_url_https":
			v := &v.MediaURLHTTPS

			if err := s.ReadString(v); err != nil {
				return err
			}

		case "type":
			v := &v.Type

			if err := s.ReadString(v); err != nil {
				return err
			}

		case "url":
			v := &v.URL

			if err := s.ReadString(v); err != nil {
				return err
			}

		}

		index++
	}

	return nil
}