func (f *StreamFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error {
	if len(f.Data) == 0 && !f.FinBit {
		return errors.New("StreamFrame: attempting to write empty frame without FIN")
	}
	typeByte := byte(0x8)
	if f.FinBit {
		typeByte ^= 0x1
	}
	hasOffset := f.Offset != 0
	if f.DataLenPresent {
		typeByte ^= 0x2
	}
	if hasOffset {
		typeByte ^= 0x4
	}
	b.WriteByte(typeByte)
	utils.WriteVarInt(b, uint64(f.StreamID))
	if hasOffset {
		utils.WriteVarInt(b, uint64(f.Offset))
	}
	if f.DataLenPresent {
		utils.WriteVarInt(b, uint64(f.DataLen()))
	}
	b.Write(f.Data)
	return nil
}
Write writes a STREAM frame
package wire
import (
	"bytes"
	"errors"
	"io"
	"github.com/lucas-clemente/quic-go/internal/protocol"
	"github.com/lucas-clemente/quic-go/internal/qerr"
	"github.com/lucas-clemente/quic-go/internal/utils"
)
type StreamFrame struct {
	StreamID       protocol.StreamID
	FinBit         bool
	DataLenPresent bool
	Offset         protocol.ByteCount
	Data           []byte
}
func parseStreamFrame(r *bytes.Reader, version protocol.VersionNumber) (*StreamFrame, error) {
	typeByte, err := r.ReadByte()
	if err != nil {
		return nil, err
	}
	hasOffset := typeByte&0x4 > 0
	frame := &StreamFrame{
		FinBit:         typeByte&0x1 > 0,
		DataLenPresent: typeByte&0x2 > 0,
	}
	streamID, err := utils.ReadVarInt(r)
	if err != nil {
		return nil, err
	}
	frame.StreamID = protocol.StreamID(streamID)
	if hasOffset {
		offset, err := utils.ReadVarInt(r)
		if err != nil {
			return nil, err
		}
		frame.Offset = protocol.ByteCount(offset)
	}
	var dataLen uint64
	if frame.DataLenPresent {
		var err error
		dataLen, err = utils.ReadVarInt(r)
		if err != nil {
			return nil, err
		}
		if dataLen > uint64(r.Len()) {
			return nil, io.EOF
		}
	} else {
		dataLen = uint64(r.Len())
	}
	if dataLen != 0 {
		frame.Data = make([]byte, dataLen)
		if _, err := io.ReadFull(r, frame.Data); err != nil {
			return nil, err
		}
	}
	if frame.Offset+frame.DataLen() > protocol.MaxByteCount {
		return nil, qerr.Error(qerr.FrameEncodingError, "stream data overflows maximum offset")
	}
	return frame, nil
}