code: func (w *PktlineWriter) Write(p []byte) (int, error) {
  	var n int
  
  	for len(p[n:]) > 0 {
  		// While there is still data left to process in "p", grab as
  		// much of it as we can while not allowing the internal buffer
  		// to exceed the MaxPacketLength const.
  		m := tools.MinInt(len(p[n:]), MaxPacketLength-len(w.buf))
  
  		// Append on all of the data that we could into the internal
  		// buffer.
  		w.buf = append(w.buf, p[n:n+m]...)
  
  		n += m
  
  		if len(w.buf) == MaxPacketLength {
  			// If we were able to grab an entire packet's worth of
  			// data, flush the buffer.
  
  			if _, err := w.flush(); err != nil {
  				return n, err
  			}
  
  		}
  	}
  
  	return n, nil
  }
docs: // Write implements the io.Writer interface's `Write` method by providing a
  // packet-based backend to the given buffer "p".
  //
  // As many bytes are removed from "p" as possible and stored in an internal
  // buffer until the amount of data in the internal buffer is enough to write a
  // single packet. Once the internal buffer is full, a packet is written to the
  // underlying stream of data, and the process repeats.
  //
  // When the caller has no more data to write in the given chunk of packets, a
  // subsequent call to `Flush()` SHOULD be made in order to signify that the
  // current pkt sequence has terminated, and a new one can begin.
  //
  // Write returns the number of bytes in "p" accepted into the writer, which
  // _MAY_ be written to the underlying protocol stream, or may be written into
  // the internal buffer.
  //
  // If any error was encountered while either buffering or writing, that
  // error is returned, along with the number of bytes written to the underlying
  // protocol stream, as described above.