// Read data into the spec from DbfTable.
183658
func (dt *DbfTable) Read(row int, spec interface{}) error {
	v := reflect.ValueOf(spec)
	if v.Kind() != reflect.Ptr {
		panic("dbf: must be a pointer")
	}
	s := v.Elem()
	if s.Kind() != reflect.Struct {
		panic("dbf: spec parameter must be a struct")
	}

	typeOfSpec := s.Type()
	for i := 0; i < s.NumField(); i++ {
		f := s.Field(i)
		if f.CanSet() {
			var fieldName string
			alt := typeOfSpec.Field(i).Tag.Get("dbf")

			// ignore '-' tags
			if alt == "-" {
				continue
			}
			fieldName = typeOfSpec.Field(i).Name
			value := dt.FieldValueByName(row, fieldName)

			switch f.Kind() {
			default:
				panic("dbf: unsupported type for database table schema, use dash to omit")

			case reflect.String:
				f.SetString(value)

			case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
				reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
				intValue, err := strconv.ParseInt(value, 0, f.Type().Bits())
				if err != nil {
					return fmt.Errorf("fail to parse field '%s' type: %s value: %s",
						fieldName, f.Type().String(), value)
				}
				f.SetInt(intValue)

			case reflect.Bool:
				if value == "T" || value == "t" || value == "Y" || value == "y" {
					f.SetBool(true)
				} else {
					f.SetBool(false)
				}

			case reflect.Float32, reflect.Float64:
				floatValue, err := strconv.ParseFloat(value, f.Type().Bits())
				if err != nil {
					return fmt.Errorf("fail to parse field '%s' type: %s value: %s",
						fieldName, f.Type().String(), value)
				}
				f.SetFloat(floatValue)
			}
		}
	}
	return nil
}
75894
func (c *Connector) read(
	ctx context.Context,
	ei *dosa.EntityInfo,
	keys map[string]dosa.FieldValue,
	source map[string]dosa.FieldValue,
	sourceErr error,
	methodName string,
) (values map[string]dosa.FieldValue, err error) {
	if dosa.ErrorIsNotFound(sourceErr) {
		return source, sourceErr
	}

	ckey := createCacheKey(ei, keys)
	value, err := c.getValueFromFallback(ctx, ei, ckey)
	c.logFallback(methodName, ei.Def.Name, err)
	if err != nil {
		return source, sourceErr
	}
	result := map[string]dosa.FieldValue{}
	err = c.encoder.Decode(value, &result)
	if err != nil {
		return source, sourceErr
	}
	return rawRowAsPointers(ei, result), err
}
830242
func (c *Conn) Read(b []byte) (int, error) {
	n, err := c.fd.Read(b)
	if err != nil {
		return n, c.opError(opRead, err)
	}

	return n, nil
}
864836
func (dt *DbfTable) Create(spec interface{}) error {
	s := reflect.ValueOf(spec)
	if s.Kind() == reflect.Ptr {
		s = s.Elem()
	}
	if s.Kind() != reflect.Struct {
		panic("dbf: spec parameter must be a struct")
	}

	var err error
	typeOfSpec := s.Type()
	for i := 0; i < s.NumField(); i++ {
		var sz uint8 = 50 // text fields default to 50 unless specified
		f := s.Field(i)
		if typeOfSpec.Field(i).PkgPath != "" || typeOfSpec.Field(i).Anonymous {
			continue // ignore unexported or embedded fields
		}
		fieldName := typeOfSpec.Field(i).Name
		alt := typeOfSpec.Field(i).Tag.Get("dbf")
		// ignore '-' tags
		if alt == "-" {
			continue
		}
		if alt != "" {
			n, err := strconv.ParseUint(alt, 0, 8)
			if err != nil {
				panic("dbf: invalid struct tag " + alt)
			}
			sz = uint8(n)
		}

		switch f.Kind() {
		default:
			panic("dbf: unsupported type for database table schema, use dash to omit")

		case reflect.String:
			err = dt.AddTextField(fieldName, sz)

		case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
			reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
			err = dt.AddIntField(fieldName)

		case reflect.Bool:
			err = dt.AddBoolField(fieldName)

		case reflect.Float32, reflect.Float64:
			err = dt.AddFloatField(fieldName)
		}

		if err != nil {
			return err
		}
	}
	return nil
}
690752
func (f *KbfsReadCloseResetter) Read(p []byte) (int, error) {
	content, err := f.client.SimpleFSRead(f.ctx, keybase1.SimpleFSReadArg{
		OpID:   f.opid,
		Offset: atomic.LoadInt64(&f.offset),
		Size:   len(p),
	})
	if err != nil {
		return 0, err
	}
	if len(content.Data) == 0 {
		// Unfortunately SimpleFSRead doesn't return EOF error.
		return 0, io.EOF
	}
	atomic.AddInt64(&f.offset, int64(len(content.Data)))
	copy(p, content.Data)
	return len(content.Data), nil
}
304751
func (bufc *bufConn) Read(b []byte) (int, error) {
	if bufc.bufr == nil {
		return bufc.conn.Read(b)
	}

	n := len(b)
	if m := bufc.bufr.Buffered(); m < n {
		n = m
	}
	p, err := bufc.bufr.Peek(n)
	n = copy(b, p)
	bufc.bufr.Discard(n)
	if err == bufio.ErrBufferFull {
		err = nil
	}
	if bufc.bufr.Buffered() == 0 {
		// TODO: useful? bufc.bufr.Reset(nil)
		bufc.bufr = nil
	}
	return n, err
}
1122399
func LoadFile(fileName string) (table *DbfTable, err error) {
	s, err := readFile(fileName)
	if err != nil {
		return nil, err
	}
	// Create and pupulate DbaseTable struct
	dt := new(DbfTable)
	dt.loading = true
	// set DbfTable dataStore slice that will store the complete file in memory
	dt.dataStore = s

	// read dbase table header information
	dt.fileSignature = s[0]
	dt.updateYear = s[1]
	dt.updateMonth = s[2]
	dt.updateDay = s[3]
	dt.numberOfRecords = uint32(s[4]) | (uint32(s[5]) << 8) | (uint32(s[6]) << 16) | (uint32(s[7]) << 24)
	dt.headerSize = uint16(s[8]) | (uint16(s[9]) << 8)
	dt.recordLength = uint16(s[10]) | (uint16(s[11]) << 8)

	// create fieldMap to taranslate field name to index
	dt.fieldMap = make(map[string]int)

	// Number of fields in dbase table
	dt.numberOfFields = int((dt.headerSize - 1 - 32) / 32)

	// populate dbf fields
	for i := 0; i < int(dt.numberOfFields); i++ {
		offset := (i * 32) + 32

		fieldName := strings.Trim(string(s[offset:offset+10]), string([]byte{0}))
		dt.fieldMap[fieldName] = i

		var err error
		switch s[offset+11] {
		case 'C':
			err = dt.AddTextField(fieldName, s[offset+16])
		case 'N':
			err = dt.AddNumberField(fieldName, s[offset+16], s[offset+17])
		case 'L':
			err = dt.AddBoolField(fieldName)
		case 'D':
			err = dt.AddDateField(fieldName)
		}

		if err != nil {
			return nil, err
		}
	}

	// memorize deleted rows
	sz := int(dt.numberOfRecords)
	for i := 0; i < sz; i++ {
		if dt.IsDeleted(i) {
			dt.delRows = append(dt.delRows, i)
		}
	}

	dt.frozenStruct = true
	return dt, nil
}
1264595
func (c *CountMinSketch) ReadDataFrom(stream io.Reader) (int, error) {
	var (
		count          uint64
		epsilon, delta float64
	)

	err := binary.Read(stream, binary.LittleEndian, &epsilon)
	if err != nil {
		return 0, err
	}
	err = binary.Read(stream, binary.LittleEndian, &delta)
	if err != nil {
		return 0, err
	}

	// check if serialized and target cms configurations are same
	if c.epsilon != epsilon || c.delta != delta {
		return 0, fmt.Errorf("expected cms values for epsilon %f and delta %f", epsilon, delta)
	}

	err = binary.Read(stream, binary.LittleEndian, &count)
	if err != nil {
		return 0, err
	}

	for i := uint(0); i < c.depth; i++ {
		err = binary.Read(stream, binary.LittleEndian, c.matrix[i])
	}
	// count size of matrix and count
	size := int(c.depth*c.width)*binary.Size(uint64(0)) + binary.Size(count) + 2*binary.Size(float64(0))

	c.count = count

	return size, err
}
447468
func (tr trimReader) Read(buf []byte) (int, error) {
	n, err := tr.rd.Read(buf)
	t := bytes.TrimLeftFunc(buf[:n], unicode.IsSpace)
	n = copy(buf, t)
	return n, err
}
1041163
func (t *tunDev) Read(d []byte) (n int, err error) {
  return fdRead(C.int(t.fd), d)
}
404148
func (s *FillableStdin) Read(p []byte) (n int, err error) {
	s.Lock()
	i := len(s.buf)
	if len(p) < i {
		i = len(p)
	}
	if i > 0 {
		n := copy(p, s.buf)
		s.buf = s.buf[:0]
		cerr := s.bufErr
		s.bufErr = nil
		s.Unlock()
		return n, cerr
	}
	s.Unlock()
	n, err = s.stdin.Read(p)
	return n, err
}
1185442
func (clnt *Clnt) Read(fid *Fid, offset uint64, count uint32) ([]byte, error) {
	if count > fid.Iounit {
		count = fid.Iounit
	}

	tc := clnt.NewFcall()
	err := PackTread(tc, fid.Fid, offset, count)
	if err != nil {
		return nil, err
	}

	rc, err := clnt.Rpc(tc)
	if err != nil {
		return nil, err
	}

	return rc.Data, nil
}
501459
func (r *Reader) Read(b []byte) (int, error) {
	// if we have data in the buffer, just
	// return that.
	if r.buffered() != 0 {
		x := copy(b, r.data[r.n:])
		r.n += x
		return x, nil
	}
	var n int
	// we have no buffered data; determine
	// whether or not to buffer or call
	// the underlying reader directly
	if len(b) >= cap(r.data) {
		n, r.state = r.r.Read(b)
	} else {
		r.more()
		n = copy(b, r.data)
		r.n = n
	}
	if n == 0 {
		return 0, r.err()
	}
	return n, nil
}
1198086
func (c *SCSICmd) Read(b []byte) (n int, err error) {
	toRead := len(b)
	boff := 0
	for toRead != 0 {
		if c.vecoffset == len(c.vecs) {
			return boff, io.EOF
		}
		read := copy(b[boff:], c.vecs[c.vecoffset][c.offset:])
		boff += read
		toRead -= read
		c.offset += read
		if c.offset == len(c.vecs[c.vecoffset]) {
			c.vecoffset++
			c.offset = 0
		}
	}
	return boff, nil
}
129443
func (c *Client) ReadBlob(handle, offset uint16) ([]byte, error) {

	// Acquire and reuse the txBuf, and release it after usage.
	txBuf := <-c.chTxBuf
	defer func() { c.chTxBuf <- txBuf }()

	req := ReadBlobRequest(txBuf[:5])
	req.SetAttributeOpcode()
	req.SetAttributeHandle(handle)
	req.SetValueOffset(offset)

	b, err := c.sendReq(req)
	if err != nil {
		return nil, err
	}

	// Convert and validate the response.
	rsp := ReadBlobResponse(b)
	switch {
	case rsp[0] == ErrorResponseCode && len(rsp) == 5:
		return nil, ble.ATTError(rsp[4])
	case rsp[0] == ErrorResponseCode && len(rsp) != 5:
		fallthrough
	case rsp[0] != rsp.AttributeOpcode():
		fallthrough
	case len(rsp) < 1:
		return nil, ErrInvalidResponse
	}
	return rsp.PartAttributeValue(), nil
}
431569
func (s *syntheticByteStream) Read(p []byte) (int, error) {
	s.mu.Lock()
	defer s.mu.Unlock()

	start := s.offset
	end := start + int64(len(p))
	var err error
	if end >= s.size {
		err = io.EOF
		end = s.size
	}

	for idx := start; idx < end; idx++ {
		p[idx-start] = s.factory(idx)
	}

	s.offset = end

	return int(end - start), err
}
42714
func (c *Connector) Read(ctx context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue, minimumFields []string) (map[string]dosa.FieldValue, error) {
	if c.Next == nil {
		return nil, NewErrNoMoreConnector()
	}
	return c.Next.Read(ctx, ei, values, minimumFields)
}