// NewCSVDecoder returns a Decoder that decodes CSV encoded Results.
14755
func NewCSVDecoder(rd io.Reader) Decoder {
	dec := csv.NewReader(rd)
	dec.FieldsPerRecord = 9
	dec.TrimLeadingSpace = true

	return func(r *Result) error {
		rec, err := dec.Read()
		if err != nil {
			return err
		}

		ts, err := strconv.ParseInt(rec[0], 10, 64)
		if err != nil {
			return err
		}
		r.Timestamp = time.Unix(0, ts)

		code, err := strconv.ParseUint(rec[1], 10, 16)
		if err != nil {
			return err
		}
		r.Code = uint16(code)

		latency, err := strconv.ParseInt(rec[2], 10, 64)
		if err != nil {
			return err
		}
		r.Latency = time.Duration(latency)

		if r.BytesOut, err = strconv.ParseUint(rec[3], 10, 64); err != nil {
			return err
		}

		if r.BytesIn, err = strconv.ParseUint(rec[4], 10, 64); err != nil {
			return err
		}

		r.Error = rec[5]
		r.Body, err = base64.StdEncoding.DecodeString(rec[6])

		r.Attack = rec[7]
		if r.Seq, err = strconv.ParseUint(rec[8], 10, 64); err != nil {
			return err
		}

		return err
	}
}
1053381
func (msg *MsgPing) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error {
	// There was no nonce for BIP0031Version and earlier.
	// NOTE: > is not a mistake here.  The BIP0031 was defined as AFTER
	// the version unlike most others.
	if pver > BIP0031Version {
		err := readElement(r, &msg.Nonce)
		if err != nil {
			return err
		}
	}

	return nil
}
1255247
func NewDecoder(r io.Reader) (*Decoder, error) {
	s := &source{
		reader: r,
	}
	d := &Decoder{
		source: s,
		length: invalidLength,
	}

	if err := s.skipTags(); err != nil {
		return nil, err
	}
	// TODO: Is readFrame here really needed?
	if err := d.readFrame(); err != nil {
		return nil, err
	}
	d.sampleRate = d.frame.SamplingFrequency()

	if err := d.ensureFrameStartsAndLength(); err != nil {
		return nil, err
	}

	return d, nil
}
217577
func NewAttributeDecoder(b []byte) (*AttributeDecoder, error) {
	attrs, err := UnmarshalAttributes(b)
	if err != nil {
		return nil, err
	}

	return &AttributeDecoder{
		// By default, use native byte order.
		ByteOrder: nlenc.NativeEndian(),

		attrs: attrs,
	}, nil
}
1070257
func NewDecoder(r io.Reader) *Decoder {
	return &Decoder{
		called:   0,
		cursor:   0,
		keysDone: 0,
		err:      nil,
		r:        r,
		data:     make([]byte, 512),
		length:   0,
		isPooled: 0,
	}
}
1197197
func stringAsBoolDecoder(dv, sv reflect.Value) error {
	b, err := strconv.ParseBool(sv.String())
	if err == nil {
		dv.SetBool(b)
	} else if sv.String() == "" {
		dv.SetBool(false)
	} else {
		return &DecodeTypeError{dv.Type(), sv.Type(), err.Error()}
	}
	return nil
}
744124
func NewDecoder(r io.Reader, opts ...Option) *Decoder {
	return &Decoder{
		r:   r,
		opt: applyOptions(opts),
	}
}
1226846
func NewReader(r io.Reader) (io.Reader, error) {
	d, err := newDecoder(r)
	if err != nil {
		return nil, err
	}
	offset := int64(d.features[tStripOffsets][0])
	n := int64(d.features[tStripByteCounts][0])
	switch d.firstVal(tCompression) {
	case cJPEG, cJPEGOld:
	default:
		return nil, UnsupportedError("compression")
	}

	return io.NewSectionReader(d.r, offset, n), nil
}
657755
func (j *GoGoJSONPb) NewDecoder(r io.Reader) Decoder {
	d := json.NewDecoder(r)
	return DecoderFunc(func(v interface{}) error { return decodeGoGoJSONPb(d, v) })
}
938131
func NewNativeJSONDecoder(r io.Reader) JSONDecoder {
	return &jsonDecoder{
		r:  r,
		bo: NativeEndian,
	}
}
438817
func NewDecoder(encodedAs EncodedAs, r io.Reader) Decoder {
	if encodedAs == EncodedAsJSON {
		return json.NewDecoder(r)
	} else if encodedAs == EncodedAsXML {
		return xml.NewDecoder(r)
	}
	return nil
}
42762
func NewUserDicRecords(r io.Reader) (UserDicRecords, error) {
	var text []string
	scanner := bufio.NewScanner(r)
	for scanner.Scan() {
		line := scanner.Text()
		if line == "" || strings.HasPrefix(line, "#") {
			continue
		}
		text = append(text, line)
	}
	if err := scanner.Err(); err != nil {
		return nil, err
	}

	var records UserDicRecords
	for _, line := range text {
		vec := strings.Split(line, ",")
		if len(vec) != dic.UserDicColumnSize {
			return nil, fmt.Errorf("invalid format: %s", line)
		}
		tokens := strings.Split(vec[1], " ")
		yomi := strings.Split(vec[2], " ")
		if len(tokens) == 0 || len(tokens) != len(yomi) {
			return nil, fmt.Errorf("invalid format: %s", line)
		}
		r := UserDicRecord{
			Text:   vec[0],
			Tokens: tokens,
			Yomi:   yomi,
			Pos:    vec[3],
		}
		records = append(records, r)
	}
	return records, nil
}
759974
func NewJSONDecoder(r io.Reader) Decoder {
	rd := bufio.NewReader(r)
	return func(r *Result) (err error) {
		var jl jlexer.Lexer
		if jl.Data, err = rd.ReadSlice('\n'); err != nil {
			return err
		}
		(*jsonResult)(r).decode(&jl)
		return jl.Error()
	}
}
1093581
func NewChainedCCFilter(filters ...CCFilter) CCFilter {
	return func(ccID string) bool {
		for _, filter := range filters {
			if !filter(ccID) {
				return false
			}
		}
		return true
	}
}
1037288
func NewDecoder(r io.Reader) *Decoder {
	return &Decoder{r, defaultDelimiter, defaultEscape, false, false}
}
930524
func (r *RDBDriver) GetCveIDsByCpeURI(uri string) ([]string, error) {
	filtered, err := r.getMatchingCpes(uri)
	if err != nil {
		return nil, err
	}

	cveIDs := make([]string, len(filtered))

	// The cpes table is de-normalized. So the `First` is correct, don't be mislead.
	for i, cpe := range filtered {
		if cpe.JvnID != 0 {
			jvn := models.Jvn{}
			err = r.conn.Select("cve_id").Where("ID = ?", cpe.JvnID).First(&jvn).Error
			if err != nil && err != gorm.ErrRecordNotFound {
				return nil, err
			}
			cveIDs[i] = jvn.CveID
		} else if cpe.NvdXMLID != 0 {
			nvd := models.NvdXML{}
			err = r.conn.Select("cve_id").Where("ID = ?", cpe.NvdXMLID).First(&nvd).Error
			if err != nil && err != gorm.ErrRecordNotFound {
				return nil, err
			}
			cveIDs[i] = nvd.CveID
		} else if cpe.NvdJSONID != 0 {
			json := models.NvdJSON{}
			err = r.conn.Select("cve_id").Where("ID = ?", cpe.NvdJSONID).First(&json).Error
			if err != nil && err != gorm.ErrRecordNotFound {
				return nil, err
			}
			cveIDs[i] = json.CveID
		}

		// If we didn't find a CVE something is weird.
		if cveIDs[i] == "" {
			log.Infof("Missing cve_id for %s (id: %d)", cpe.URI, cpe.ID)
		}
	}

	return cveIDs, nil
}
857238
func (j *JSONPb) NewDecoder(r io.Reader) Decoder {
	d := json.NewDecoder(r)
	return DecoderWrapper{Decoder: d}
}