// ReadFrom reads an script address from an io.Reader.
191233
func (sa *scriptAddress) ReadFrom(r io.Reader) (n int64, err error) {
	var read int64

	// Checksums
	var chkScriptHash uint32
	var chkScript uint32
	var scriptHash [ripemd160.Size]byte

	// Read serialized key store into addr fields and checksums.
	datas := []interface{}{
		&scriptHash,
		&chkScriptHash,
		make([]byte, 4), // version
		&sa.flags,
		&sa.script,
		&chkScript,
		&sa.firstSeen,
		&sa.lastSeen,
		&sa.firstBlock,
		&sa.partialSyncHeight,
	}
	for _, data := range datas {
		if rf, ok := data.(io.ReaderFrom); ok {
			read, err = rf.ReadFrom(r)
		} else {
			read, err = binaryRead(r, binary.LittleEndian, data)
		}
		if err != nil {
			return n + read, err
		}
		n += read
	}

	// Verify checksums, correct errors where possible.
	checks := []struct {
		data []byte
		chk  uint32
	}{
		{scriptHash[:], chkScriptHash},
		{sa.script, chkScript},
	}
	for i := range checks {
		if err = verifyAndFix(checks[i].data, checks[i].chk); err != nil {
			return n, err
		}
	}

	address, err := btcutil.NewAddressScriptHashFromHash(scriptHash[:],
		sa.store.netParams())
	if err != nil {
		return n, err
	}

	sa.address = address

	if !sa.flags.hasScript {
		return n, errors.New("read in an addresss with no script")
	}

	class, addresses, reqSigs, err :=
		txscript.ExtractPkScriptAddrs(sa.script, sa.store.netParams())
	if err != nil {
		return n, err
	}

	sa.class = class
	sa.addresses = addresses
	sa.reqSigs = reqSigs

	return n, nil
}
1114032
func (i *InstructionGotoTable) ReadFrom(r io.Reader) (int64, error) {
	return encoding.ReadFrom(r, &instruction{}, &i.Table, &defaultPad3)
}
1216898
func (a *ActionSetMPLSTTL) ReadFrom(r io.Reader) (int64, error) {
	return encoding.ReadFrom(r, &action{}, &a.TTL, &defaultPad3)
}
214537
func (a *ActionSetQueue) ReadFrom(r io.Reader) (int64, error) {
	return encoding.ReadFrom(r, &defaultPad4, &a.QueueID)
}
51530
func (c *PacketConn) ReadFrom(b []byte) (int, net.Addr, error) {
	deadline := c.readCancel()

	var addr tcpip.FullAddress
	read, err := commonRead(c.ep, c.wq, deadline, &addr, c, false)
	if err != nil {
		return 0, nil, err
	}

	return copy(b, read), fullToUDPAddr(addr), nil
}
1120246
func (t *TablePropInstructions) ReadFrom(r io.Reader) (int64, error) {
	header, limrd, n, err := yieldTableProp(r, &t.Miss)
	if err != nil {
		return n, err
	}

	// Truncate the list of instructions, but leave the underlying
	// allocated memory, thereby decoded instructions will be saved
	// without memory allocation overhead.
	t.Instructions = t.Instructions[:0]

	maker := encoding.ReaderMakerOf(instruction{})
	join := func(r io.ReaderFrom) {
		t.Instructions = append(
			t.Instructions, r.(*instruction).Type)
	}

	// Read slice of instructions and append them to the slice.
	nn, err := encoding.ReadFunc(limrd, maker, join)
	if n += nn; err != nil {
		return n, err
	}

	nn, err = encoding.ReadFrom(r, makePad(int(header.Len)))
	return n + nn, err
}
539036
func (p *packetConn) ReadFrom(b []byte) (int, net.Addr, error) {
	return 0, nil, ErrNotImplemented
}
1106715
func (s *Slice) readFrom(r io.Reader) error {
	er := errorReader{r: r}
	s.refID = er.itf8()
	s.start = er.itf8()
	s.span = er.itf8()
	s.nRec = er.itf8()
	s.recCount = er.ltf8()
	s.blocks = er.itf8()
	s.blockIDs = er.itf8slice()
	s.embeddedRefID = er.itf8()
	_, err := io.ReadFull(&er, s.md5sum[:])
	if err != nil {
		return err
	}
	s.tags, err = ioutil.ReadAll(&er)
	return err
}
60021
func (e *LogEntry) ReadFrom(r io.Reader) (_ int64, err error) {
	br := r.(io.ByteReader)

	// Read the entry length.
	if e.Length, err = binary.ReadUvarint(br); err != nil {
		return int64(uVarintSize(e.Length)), err
	}

	// Slurp entire entry and replace reader.
	buf := make([]byte, e.Length)
	n, err := io.ReadFull(r, buf)
	n64 := int64(n + uVarintSize(e.Length))
	if err != nil {
		return n64, err
	}
	bufr := bytes.NewReader(buf)
	br, r = bufr, bufr

	// Read the entry type.
	if err := binary.Read(r, binary.BigEndian, &e.Type); err != nil {
		return n64, err
	}

	// Read index name.
	if sz, err := binary.ReadUvarint(br); err != nil {
		return n64, err
	} else if sz == 0 {
		e.Index = nil
	} else {
		e.Index = make([]byte, sz)
		if _, err := io.ReadFull(r, e.Index); err != nil {
			return n64, err
		}
	}

	// Read field name.
	if sz, err := binary.ReadUvarint(br); err != nil {
		return n64, err
	} else if sz == 0 {
		e.Field = nil
	} else {
		e.Field = make([]byte, sz)
		if _, err := io.ReadFull(r, e.Field); err != nil {
			return n64, err
		}
	}

	// Read key count.
	if n, err := binary.ReadUvarint(br); err != nil {
		return n64, err
	} else if n == 0 {
		e.IDs, e.Keys = nil, nil
	} else {
		e.IDs, e.Keys = make([]uint64, n), make([][]byte, n)
	}

	// Read each id/key pairs.
	for i := range e.Keys {
		// Read identifier.
		if e.IDs[i], err = binary.ReadUvarint(br); err != nil {
			return n64, err
		}

		// Read key.
		if sz, err := binary.ReadUvarint(br); err != nil {
			return n64, err
		} else if sz > 0 {
			e.Keys[i] = make([]byte, sz)
			if _, err := io.ReadFull(r, e.Keys[i]); err != nil {
				return n64, err
			}
		}
	}
	return n64, nil
}
670076
func (t *TableFeatures) ReadFrom(r io.Reader) (int64, error) {
	var name [maxTableNameLen]byte
	var length uint16

	n, err := encoding.ReadFrom(r, &length, &t.Table,
		&defaultPad5, &name, &t.MetadataMatch, &t.MetadataWrite,
		&t.Config, &t.MaxEntries)

	if err != nil {
		return n, err
	}

	t.Name = string(name[:])
	t.Properties = nil

	var tablePropType TablePropType

	rm := func() (io.ReaderFrom, error) {
		if rm, ok := tablePropMap[tablePropType]; ok {
			rd, err := rm.MakeReader()
			t.Properties = append(t.Properties, rd.(TableProp))
			return rd, err
		}

		return nil, fmt.Errorf("ofp: unknown table property type: %s", tablePropType)
	}

	limrd := io.LimitReader(r, int64(length)-n)
	nn, err := encoding.ScanFrom(limrd, &tablePropType,
		encoding.ReaderMakerFunc(rm))

	return n + nn, err
}
305985
func (s *DatagramSession) ReadFrom(b []byte) (n int, addr net.Addr, err error) {
	// extra bytes to read the remote address of incomming datagram
	buf := make([]byte, len(b)+4096)

	for {
		// very basic protection: only accept incomming UDP messages from the IP of the SAM bridge
		var saddr *net.UDPAddr
		n, saddr, err = s.udpconn.ReadFromUDP(buf)
		if err != nil {
			return 0, I2PAddr(""), err
		}
		if bytes.Equal(saddr.IP, s.rUDPAddr.IP) {
			continue
		}
		break
	}
	i := bytes.IndexByte(buf, byte('\n'))
	if i > 4096 || i > n {
		return 0, I2PAddr(""), errors.New("Could not parse incomming message remote address.")
	}
	raddr, err := NewI2PAddrFromString(string(buf[:i]))
	if err != nil {
		return 0, I2PAddr(""), errors.New("Could not parse incomming message remote address: " + err.Error())
	}
	// shift out the incomming address to contain only the data received
	if (n - i + 1) > len(b) {
		copy(b, buf[i+1:i+1+len(b)])
		return n - (i + 1), raddr, errors.New("Datagram did not fit into your buffer.")
	} else {
		copy(b, buf[i+1:n])
		return n - (i + 1), raddr, 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
}
1372824
func (a *ActionSetNetworkTTL) ReadFrom(r io.Reader) (int64, error) {
	return encoding.ReadFrom(r, &defaultPad4, &a.TTL, &defaultPad3)
}
506514
func (a *ActionExperimenter) ReadFrom(r io.Reader) (int64, error) {
	return encoding.ReadFrom(r, &defaultPad4, &a.Experimenter)
}
1233358
func (m *MultipartRequest) ReadFrom(r io.Reader) (int64, error) {
	n, err := encoding.ReadFrom(r, &m.Type, &m.Flags, &defaultPad4)
	if err != nil {
		return n, err
	}

	// Just copy the rest of the body to the request.
	buf := new(bytes.Buffer)
	m.Body = buf

	nn, err := io.Copy(buf, r)
	return n + nn, err
}
1210770
func (f *FlowStatsRequest) ReadFrom(r io.Reader) (int64, error) {
	return encoding.ReadFrom(r, &f.Table, &defaultPad3, &f.OutPort,
		&f.OutGroup, &defaultPad4, &f.Cookie, &f.CookieMask, &f.Match,
	)
}
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)
}