forked from quic-go/quic-go
introduce protocol/version.go and remove big endian functions
This commit is contained in:
13
protocol/protocol_suite_test.go
Normal file
13
protocol/protocol_suite_test.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package protocol_test
|
||||
|
||||
import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProtocol(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Protocol Suite")
|
||||
}
|
||||
15
protocol/version.go
Normal file
15
protocol/version.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package protocol
|
||||
|
||||
// VersionNumber is a version number as int
|
||||
type VersionNumber int
|
||||
|
||||
// VersionNumberToTag maps version numbers ('32') to tags ('Q032')
|
||||
func VersionNumberToTag(vn VersionNumber) uint32 {
|
||||
v := uint32(vn)
|
||||
return 'Q' + ((v/100%10)+'0')<<8 + ((v/10%10)+'0')<<16 + ((v%10)+'0')<<24
|
||||
}
|
||||
|
||||
// VersionTagToNumber is built from VersionNumberToTag in init()
|
||||
func VersionTagToNumber(v uint32) VersionNumber {
|
||||
return VersionNumber(((v>>8)&0xff-'0')*100 + ((v>>16)&0xff-'0')*10 + ((v>>24)&0xff - '0'))
|
||||
}
|
||||
18
protocol/version_test.go
Normal file
18
protocol/version_test.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package protocol_test
|
||||
|
||||
import (
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Version", func() {
|
||||
It("converts tags to numbers", func() {
|
||||
Expect(protocol.VersionTagToNumber('Q' + '1'<<8 + '2'<<16 + '3'<<24)).To(Equal(protocol.VersionNumber(123)))
|
||||
})
|
||||
|
||||
It("converts number to tag", func() {
|
||||
Expect(protocol.VersionNumberToTag(protocol.VersionNumber(123))).To(Equal(uint32('Q' + '1'<<8 + '2'<<16 + '3'<<24)))
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user