combine packetUnpackerBase and packetUnpacker

The split was only needed for unpacking gQUIC packets.
This commit is contained in:
Marten Seemann 2018-11-01 18:55:03 +07:00
parent a18b5c0335
commit 90c538bae4

View file

@ -20,43 +20,18 @@ type quicAEAD interface {
Open1RTT(dst, src []byte, pn protocol.PacketNumber, ad []byte) ([]byte, error)
}
type packetUnpackerBase struct {
version protocol.VersionNumber
}
func (u *packetUnpackerBase) parseFrames(decrypted []byte, hdr *wire.Header) ([]wire.Frame, error) {
r := bytes.NewReader(decrypted)
if r.Len() == 0 {
return nil, qerr.MissingPayload
}
fs := make([]wire.Frame, 0, 2)
// Read all frames in the packet
for {
frame, err := wire.ParseNextFrame(r, hdr, u.version)
if err != nil {
return nil, err
}
if frame == nil {
break
}
fs = append(fs, frame)
}
return fs, nil
}
// The packetUnpacker unpacks QUIC packets.
type packetUnpacker struct {
packetUnpackerBase
aead quicAEAD
aead quicAEAD
version protocol.VersionNumber
}
var _ unpacker = &packetUnpacker{}
func newPacketUnpacker(aead quicAEAD, version protocol.VersionNumber) unpacker {
return &packetUnpacker{
packetUnpackerBase: packetUnpackerBase{version: version},
aead: aead,
aead: aead,
version: version,
}
}
@ -97,3 +72,24 @@ func (u *packetUnpacker) Unpack(headerBinary []byte, hdr *wire.Header, data []by
frames: fs,
}, nil
}
func (u *packetUnpacker) parseFrames(decrypted []byte, hdr *wire.Header) ([]wire.Frame, error) {
r := bytes.NewReader(decrypted)
if r.Len() == 0 {
return nil, qerr.MissingPayload
}
fs := make([]wire.Frame, 0, 2)
// Read all frames in the packet
for {
frame, err := wire.ParseNextFrame(r, hdr, u.version)
if err != nil {
return nil, err
}
if frame == nil {
break
}
fs = append(fs, frame)
}
return fs, nil
}