// ReadFrom implements io.ReaderFrom interface. It deserializes the
// version bitmap from the wire format.
968239
func (h *HelloElemVersionBitmap) ReadFrom(r io.Reader) (int64, error) {
	// Read the header of the version bitmaps to retrieve
	// the total length of the message.
	var header helloElem
	n, err := encoding.ReadFrom(r, &header)
	if err != nil {
		return n, err
	}

	// Calculate the length of the list of version bitmaps.
	bodyLen := header.Len - helloElemLen
	limrd := io.LimitReader(r, int64(bodyLen))

	// Allocate required amount of memory used to fit all
	// element version bitmaps (assuming that uint32 takes
	// 4 bytes of the memory).
	h.Bitmaps = make([]uint32, bodyLen/4)
	nn, err := encoding.ReadFrom(limrd, &h.Bitmaps)
	return n + nn, err
}
34900
func (g *GroupFeatures) ReadFrom(r io.Reader) (int64, error) {
	return encoding.ReadFrom(r, &g.Types, &g.Capabilities,
		&g.MaxGroups, &g.Actions)
}
528645
func (a *p2SHScript) ReadFrom(r io.Reader) (n int64, err error) {
	//read length
	var lenBytes [4]byte

	read, err := io.ReadFull(r, lenBytes[:])
	n += int64(read)
	if err != nil {
		return n, err
	}

	length := binary.LittleEndian.Uint32(lenBytes[:])

	script := make([]byte, length)

	read, err = io.ReadFull(r, script)
	n += int64(read)
	if err != nil {
		return n, err
	}

	*a = script

	return n, nil
}
127298
func (i *Int32) ReadFrom(r Reader, l int) error {
	if l != UNKNOWN_LEN && l != 4 {
		return errorsp.WithStacksAndMessage(ErrBadFormat, "l = %d", l)
	}

	var arr [4]byte
	if _, err := io.ReadFull(r, arr[:]); err != nil {
		return errorsp.WithStacks(err)
	}
	*i = Int32(arr[0]) | Int32(arr[1])<<8 | Int32(arr[2])<<16 |
		Int32(arr[3])<<24
	return nil
}
1030878
func (i *Instructions) ReadFrom(r io.Reader) (n int64, err error) {
	var instType InstructionType

	rm := func() (io.ReaderFrom, error) {
		if rm, ok := instructionMap[instType]; ok {
			rd, err := rm.MakeReader()
			*i = append(*i, rd.(Instruction))
			return rd, err
		}

		return nil, fmt.Errorf("ofp: unknown instruction type: %s", instType)
	}

	return encoding.ScanFrom(r, &instType,
		encoding.ReaderMakerFunc(rm))
}
13091
func (ba *RawByteSlice) ReadFrom(r Reader, sz int) error {
	if sz < 0 {
		return errorsp.WithStacksAndMessage(ErrBadFormat, "expecting a size but get %d", sz)
	}
	*ba = make(RawByteSlice, sz)

	n, err := io.ReadFull(r, *ba)
	if n != sz {
		log.Printf("RawByteSlice.ReadFrom: exp %d bytes act %d: %v", sz, n, err)
	}
	return errorsp.WithStacks(err)
}
98289
func (h *Hello) ReadFrom(r io.Reader) (int64, error) {
	return encoding.ReadFrom(r, &h.Elements)
}
1300182
func (ba *ByteSlice) ReadFrom(r Reader, l int) error {
	var sz VInt
	if err := sz.ReadFrom(r, UNKNOWN_LEN); err != nil {
		return errorsp.WithStacks(err)
	}
	*ba = make(ByteSlice, sz)

	_, err := io.ReadFull(r, *ba)
	return errorsp.WithStacks(err)
}
641191
func (s *Store) ReadFrom(r io.Reader) (n int64, err error) {
	s.mtx.Lock()
	defer s.mtx.Unlock()

	var read int64

	s.net = &netParams{}
	s.addrMap = make(map[addressKey]walletAddress)
	s.chainIdxMap = make(map[int64]btcutil.Address)

	var id [8]byte
	appendedEntries := varEntries{store: s}
	s.keyGenerator.store = s

	// Iterate through each entry needing to be read.  If data
	// implements io.ReaderFrom, use its ReadFrom func.  Otherwise,
	// data is a pointer to a fixed sized value.
	datas := []interface{}{
		&id,
		&s.vers,
		s.net,
		&s.flags,
		make([]byte, 6), // Bytes for Armory unique ID
		&s.createDate,
		&s.name,
		&s.desc,
		&s.highestUsed,
		&s.kdfParams,
		make([]byte, 256),
		&s.keyGenerator,
		newUnusedSpace(1024, &s.recent),
		&appendedEntries,
	}
	for _, data := range datas {
		var err error
		switch d := data.(type) {
		case readerFromVersion:
			read, err = d.readFromVersion(s.vers, r)

		case io.ReaderFrom:
			read, err = d.ReadFrom(r)

		default:
			read, err = binaryRead(r, binary.LittleEndian, d)
		}
		n += read
		if err != nil {
			return n, err
		}
	}

	if id != fileID {
		return n, errors.New("unknown file ID")
	}

	// Add root address to address map.
	rootAddr := s.keyGenerator.Address()
	s.addrMap[getAddressKey(rootAddr)] = &s.keyGenerator
	s.chainIdxMap[rootKeyChainIdx] = rootAddr
	s.lastChainIdx = rootKeyChainIdx

	// Fill unserializied fields.
	wts := appendedEntries.entries
	for _, wt := range wts {
		switch e := wt.(type) {
		case *addrEntry:
			addr := e.addr.Address()
			s.addrMap[getAddressKey(addr)] = &e.addr
			if e.addr.Imported() {
				s.importedAddrs = append(s.importedAddrs, &e.addr)
			} else {
				s.chainIdxMap[e.addr.chainIndex] = addr
				if s.lastChainIdx < e.addr.chainIndex {
					s.lastChainIdx = e.addr.chainIndex
				}
			}

			// If the private keys have not been created yet, mark the
			// earliest so all can be created on next key store unlock.
			if e.addr.flags.createPrivKeyNextUnlock {
				switch {
				case s.missingKeysStart == rootKeyChainIdx:
					fallthrough
				case e.addr.chainIndex < s.missingKeysStart:
					s.missingKeysStart = e.addr.chainIndex
				}
			}

		case *scriptEntry:
			addr := e.script.Address()
			s.addrMap[getAddressKey(addr)] = &e.script
			// script are always imported.
			s.importedAddrs = append(s.importedAddrs, &e.script)

		default:
			return n, errors.New("unknown appended entry")
		}
	}

	return n, nil
}
1090477
func (h *DBHashes) readFrom(r io.Reader) error {
	return binary.Read(r, binary.LittleEndian, h)
}
526692
func (e *ErrorExperimenter) ReadFrom(r io.Reader) (n int64, err error) {
	var etype ErrType
	n, err = encoding.ReadFrom(r, &etype, &e.ExpType, &e.Experimenter)
	if err != nil {
		return n, err
	}

	e.Data, err = ioutil.ReadAll(r)
	if err != nil {
		return
	}

	return n + int64(len(e.Data)), nil
}
425114
func (b *Buckets) ReadFrom(stream io.Reader) (int64, error) {
	var bucketSize, max uint8
	var count, len uint64
	err := binary.Read(stream, binary.BigEndian, &bucketSize)
	if err != nil {
		return 0, err
	}
	err = binary.Read(stream, binary.BigEndian, &max)
	if err != nil {
		return 0, err
	}
	err = binary.Read(stream, binary.BigEndian, &count)
	if err != nil {
		return 0, err
	}
	err = binary.Read(stream, binary.BigEndian, &len)
	if err != nil {
		return 0, err
	}
	data := make([]byte, len)
	err = binary.Read(stream, binary.BigEndian, &data)
	if err != nil {
		return 0, err
	}
	b.bucketSize = bucketSize
	b.max = max
	b.count = uint(count)
	b.data = data
	return int64(int(len) + 2*binary.Size(uint8(0)) + 2*binary.Size(uint64(0))), nil
}
1179619
func (s *Slice) ReadFrom(r io.Reader) (n int64, err error) {
	const buf_SIZE = 32 * 1024
	buf := make([]byte, buf_SIZE)
	for {
		nRead, err := r.Read(buf)
		if nRead == 0 {
			if err != io.EOF {
				return n, err
			}
			break
		}
		n += int64(nRead)
		*s = append(*s, buf[:nRead]...)
		if err == io.EOF {
			break
		}

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

	return n, nil
}
665482
func (ac *arrayContainer) readFrom(stream io.Reader) (int, error) {
	buf := uint16SliceAsByteSlice(ac.content)
	return io.ReadFull(stream, buf)
}
28204
func (b *Bytes) ReadNFrom(n int64, r io.Reader) (m int64, err error) {
	b.bytes, m, err = b.readNFrom(n, r)
	return m, err
}
1319052
func (t *TablePropWriteActions) ReadFrom(r io.Reader) (int64, error) {
	return readTablePropActions(r, &t.Actions, &t.Miss)
}
352759
func (l *List) ReadFrom(r io.Reader) (n int64, err error) {
	var nn int64

	// Read TagType
	nn, err = l.Typ.ReadFrom(r)
	if err != nil {
		return
	}
	n += nn

	// Read length-prefix
	var length Int32
	nn, err = length.ReadFrom(r)
	if err != nil {
		return
	}
	n += nn

	// Read list items
	if length.Int32 > 0 {
		l.Value = make([]Tag, length.Int32)
		for index, elem := range l.Value {
			elem = l.Typ.New()
			nn, err = elem.ReadFrom(r)
			if err != nil {
				return
			}
			l.Value[index] = elem
			n += nn
		}

	}

	return
}