code: func (d *Decoder) Read() (Generic, error) {
  	// initial detection length
  	detectionLength := 2
  
  	for {
  		// check length
  		if detectionLength > 5 {
  			return nil, ErrDetectionOverflow
  		}
  
  		// try read detection bytes
  		header, err := d.reader.Peek(detectionLength)
  		if err == io.EOF && len(header) != 0 {
  			// an EOF with some data is unexpected
  			return nil, io.ErrUnexpectedEOF
  		} else if err != nil {
  			return nil, err
  		}
  
  		// detect packet
  		packetLength, packetType := DetectPacket(header)
  
  		// on zero packet length:
  		// increment detection length and try again
  		if packetLength <= 0 {
  			detectionLength++
  			continue
  		}
  
  		// check read limit
  		if d.Limit > 0 && int64(packetLength) > d.Limit {
  			return nil, ErrReadLimitExceeded
  		}
  
  		// create packet
  		pkt, err := packetType.New()
  		if err != nil {
  			return nil, err
  		}
  
  		// reset and eventually grow buffer
  		d.buffer.Reset()
  		d.buffer.Grow(packetLength)
  		buf := d.buffer.Bytes()[0:packetLength]
  
  		// read whole packet (will not return EOF)
  		_, err = io.ReadFull(d.reader, buf)
  		if err != nil {
  			return nil, err
  		}
  
  		// decode buffer
  		_, err = pkt.Decode(buf)
  		if err != nil {
  			return nil, err
  		}
  
  		return pkt, nil
  	}
  }
docs: // Read reads the next packet from the buffered reader.