introduce protocol/version.go and remove big endian functions

This commit is contained in:
Lucas Clemente
2016-04-15 18:46:39 +02:00
parent 052822aea5
commit b6c9c9b6a4
8 changed files with 57 additions and 74 deletions

View File

@@ -53,21 +53,6 @@ var _ = Describe("Utils", func() {
})
})
Context("ReadUint32BigEndian", func() {
It("reads a big endian", func() {
b := []byte{0x12, 0x35, 0xAB, 0xFF}
val, err := ReadUint32BigEndian(bytes.NewReader(b))
Expect(err).ToNot(HaveOccurred())
Expect(val).To(Equal(uint32(0x1235ABFF)))
})
It("throws an error if less than 4 bytes are passed", func() {
b := []byte{0x13, 0x34, 0xEA}
_, err := ReadUint32(bytes.NewReader(b))
Expect(err).To(HaveOccurred())
})
})
Context("WriteUint16", func() {
It("outputs 2 bytes", func() {
b := &bytes.Buffer{}
@@ -97,19 +82,4 @@ var _ = Describe("Utils", func() {
Expect(b.Bytes()).To(Equal([]byte{0x12, 0x35, 0xAC, 0xEF}))
})
})
Context("WriteUint32BigEndian", func() {
It("outputs 4 bytes", func() {
b := &bytes.Buffer{}
WriteUint32BigEndian(b, uint32(1))
Expect(b.Len()).To(Equal(4))
})
It("outputs a big endian", func() {
num := uint32(0xEFAC3512)
b := &bytes.Buffer{}
WriteUint32BigEndian(b, num)
Expect(b.Bytes()).To(Equal([]byte{0xEF, 0xAC, 0x35, 0x12}))
})
})
})