implement version-dependent parsing of the Public Header

This commit is contained in:
Marten Seemann
2017-08-03 15:13:23 +07:00
parent 1a8a012019
commit dd0daaaf1e
17 changed files with 311 additions and 124 deletions

View File

@@ -3,6 +3,8 @@ package utils
import (
"bytes"
"io"
"github.com/lucas-clemente/quic-go/protocol"
)
// A ByteOrder specifies how to convert byte sequences into 16-, 32-, or 64-bit unsigned integers.
@@ -23,3 +25,12 @@ type ByteOrder interface {
ReadUfloat16(io.ByteReader) (uint64, error)
WriteUfloat16(*bytes.Buffer, uint64)
}
// GetByteOrder gets the ByteOrder (little endian or big endian) used to represent values on the wire
// from QUIC 39, values are encoded in big endian, before that in little endian
func GetByteOrder(v protocol.VersionNumber) ByteOrder {
if v < protocol.Version39 {
return LittleEndian
}
return BigEndian
}

View File

@@ -0,0 +1,18 @@
package utils
import (
"github.com/lucas-clemente/quic-go/protocol"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Byte Order", func() {
It("says little Little Endian before QUIC 39", func() {
Expect(GetByteOrder(protocol.Version36)).To(Equal(LittleEndian))
Expect(GetByteOrder(protocol.Version37)).To(Equal(LittleEndian))
})
It("says little Little Endian for QUIC 39", func() {
Expect(GetByteOrder(protocol.Version39)).To(Equal(BigEndian))
})
})