// ReadFrom implements io.ReaderFrom interface. It deserializes
// the group statistics from the wire format.
328795
func (g *GroupStats) ReadFrom(r io.Reader) (int64, error) {
	var length uint16

	n, err := encoding.ReadFrom(r, &length, &defaultPad2,
		&g.Group, &g.RefCount, &defaultPad4, &g.PacketCount, &g.ByteCount,
		&g.DurationSec, &g.DurationNSec)

	if err != nil {
		return n, err
	}

	limrd := io.LimitReader(r, int64(length-groupStatsLen))
	counterMaker := encoding.ReaderMakerOf(BucketCounter{})

	nn, err := encoding.ReadSliceFrom(limrd, counterMaker, g.BucketStats)
	return n + nn, err
}
567166
func (w *Writer) ReadFrom(r io.Reader) (int64, error) {
	// anticipatory flush
	if err := w.Flush(); err != nil {
		return 0, err
	}

	w.buf = w.buf[0:cap(w.buf)] // expand buffer

	var nn int64  // written
	var err error // error
	var x int     // read

	// 1:1 reads and writes
	for err == nil {
		x, err = r.Read(w.buf)
		if x > 0 {
			n, werr := w.w.Write(w.buf[:x])
			nn += int64(n)

			if err != nil {
				if n < x && n > 0 {
					w.pushback(n - x)
				}
				return nn, werr
			}
			if n < x {
				w.pushback(n - x)
				return nn, io.ErrShortWrite
			}
		} else if err == nil {
			err = io.ErrNoProgress
			break
		}
	}
	if err != io.EOF {
		return nn, err
	}

	// we only clear here
	// because we are sure
	// the writes have
	// succeeded. otherwise,
	// we retain the data in case
	// future writes succeed.
	w.buf = w.buf[0:0]

	return nn, 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
}
1035939
func (p *PortStats) ReadFrom(r io.Reader) (int64, error) {
	return encoding.ReadFrom(r, &p.PortNo, &defaultPad4, &p.RxPackets,
		&p.TxPackets, &p.RxBytes, &p.TxBytes, &p.RxDropped, &p.TxDropped,
		&p.RxErrors, &p.TxErrors, &p.RxFrameErr, &p.RxOverErr, &p.RxCrcErr,
		&p.Collisions, &p.DurationSec, &p.DurationNSec,
	)
}
191099
func (m *ExperimenterMultipartHeader) ReadFrom(r io.Reader) (int64, error) {
	return encoding.ReadFrom(r, &m.Experimenter, &m.ExpType)
}
427710
func (q *QueuePropExperimenter) ReadFrom(r io.Reader) (int64, error) {
	var header queueProp
	n, err := encoding.ReadFrom(r, &header, &defaultPad4,
		&q.Experimenter, &defaultPad4)

	if err != nil {
		return n, err
	}

	limrd := io.LimitReader(r, int64(header.Len-queuePropLen))
	q.Data, err = ioutil.ReadAll(limrd)
	return n + int64(len(q.Data)), err
}
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
}
882913
func (d *Description) ReadFrom(r io.Reader) (int64, error) {
	var mfr, hw, sw, dp [descLen]byte
	var sn [serialNumLen]byte

	n, err := encoding.ReadFrom(r, &mfr, &hw, &sw, &sn, &dp)
	if err != nil {
		return n, err
	}

	d.Manufacturer = string(mfr[:])
	d.Hardware = string(hw[:])
	d.Software = string(sw[:])
	d.SerialNum = string(sn[:])
	d.Datapath = string(dp[:])
	return n, err
}
98289
func (h *Hello) ReadFrom(r io.Reader) (int64, error) {
	return encoding.ReadFrom(r, &h.Elements)
}
1357622
func (s *Chan) ReadFrom(r io.Reader) {
	s.readFrom(NewReader(r))
}
641222
func (b *Bucket) ReadFrom(r io.Reader) (int64, error) {
	// Read the header of the bucket to limit the count
	// of bytes used to unmarshal the list of actions.
	var length uint16
	n, err := encoding.ReadFrom(r, &length, &b.Weight,
		&b.WatchPort, &b.WatchGroup, &defaultPad4)
	if err != nil {
		return n, err
	}

	// Created a limited reader to not read more bytes
	// that it is allocated for the list of actions.
	limrd := io.LimitReader(r, int64(length-bucketLen))
	b.Actions = nil

	nn, err := b.Actions.ReadFrom(limrd)
	return n + nn, err
}
840305
func (m *Match) ReadFrom(r io.Reader) (n int64, err error) {
	var nn int64
	var length uint16

	// Initialize the structure attributes with default
	// values, so we could read multiple times into the
	// same variable.
	m.Type, m.Fields = 0, nil

	n, err = encoding.ReadFrom(r, &m.Type, &length)
	if err != nil {
		return
	}

	matchlen := int(length)

	// subtract the length of the already-read Type & Length fields
	rdlen := matchlen - 4

	// Limit the reader to the length of the extensible matches.
	limrd := io.LimitReader(r, int64(rdlen))
	nn, err = readAllXM(limrd, &m.Fields, true)
	if n += nn; err != nil {
		return
	}

	// Read the padding after the list of extensible matches.
	nn, err = encoding.ReadFrom(r, makePad(matchlen))
	return n + nn, err
}
26641
func (sc *SwitchConfig) ReadFrom(r io.Reader) (int64, error) {
	return encoding.ReadFrom(r, &sc.Flags, &sc.MissSendLength)
}
747262
func (a *AsyncConfig) ReadFrom(r io.Reader) (int64, error) {
	return encoding.ReadFrom(r, &a.PacketInMask,
		&a.PortStatusMask, &a.FlowRemovedMask)
}
351975
func (q *QueueGetConfigRequest) ReadFrom(r io.Reader) (int64, error) {
	return encoding.ReadFrom(r, &q.Port, &defaultPad4)
}
450306
func (w *Writer) ReadFrom(src io.Reader) (n int64, err error) {
	var nn int
	for err == nil {
		if w.Available() == 0 {
			err = w.FlushFragment()
			continue
		}

		// We copy the behavior of bufio.Writer here.
		// Also, from the docs on io.ReaderFrom:
		//   ReadFrom reads data from r until EOF or error.
		//
		// See https://codereview.appspot.com/76400048/#ps1
		const maxEmptyReads = 100
		var nr int
		for nr < maxEmptyReads {
			nn, err = src.Read(w.buf[w.n:])
			if nn != 0 || err != nil {
				break
			}
			nr++
		}
		if nr == maxEmptyReads {
			return n, io.ErrNoProgress
		}

		w.n += nn
		n += int64(nn)
	}
	if err == io.EOF {
		// NOTE: Do not flush preemtively.
		// See the Write() sources for more info.
		err = nil
		w.dirty = true
	}
	return n, err
}
1319052
func (t *TablePropWriteActions) ReadFrom(r io.Reader) (int64, error) {
	return readTablePropActions(r, &t.Actions, &t.Miss)
}