forked from quic-go/quic-go
parse RST_STREAM frames
This commit is contained in:
@@ -18,6 +18,37 @@ func ReadUintN(b io.ByteReader, length uint8) (uint64, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// ReadUint64 reads a uint64
|
||||
func ReadUint64(b io.ByteReader) (uint64, error) {
|
||||
var b1, b2, b3, b4, b5, b6, b7, b8 uint8
|
||||
var err error
|
||||
if b1, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b2, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b3, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b4, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b5, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b6, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b7, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b8, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint64(b1) + uint64(b2)<<8 + uint64(b3)<<16 + uint64(b4)<<24 + uint64(b5)<<32 + uint64(b6)<<40 + uint64(b7)<<48 + uint64(b8)<<56, nil
|
||||
}
|
||||
|
||||
// ReadUint32 reads a uint32
|
||||
func ReadUint32(b io.ByteReader) (uint32, error) {
|
||||
var b1, b2, b3, b4 uint8
|
||||
|
||||
@@ -53,6 +53,21 @@ var _ = Describe("Utils", func() {
|
||||
})
|
||||
})
|
||||
|
||||
Context("ReadUint64", func() {
|
||||
It("reads a little endian", func() {
|
||||
b := []byte{0x12, 0x35, 0xAB, 0xFF, 0xEF, 0xBE, 0xAD, 0xDE}
|
||||
val, err := ReadUint64(bytes.NewReader(b))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(val).To(Equal(uint64(0xDEADBEEFFFAB3512)))
|
||||
})
|
||||
|
||||
It("throws an error if less than 8 bytes are passed", func() {
|
||||
b := []byte{0x13, 0x34, 0xEA, 0x00, 0x14, 0xAA}
|
||||
_, err := ReadUint64(bytes.NewReader(b))
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
Context("WriteUint16", func() {
|
||||
It("outputs 2 bytes", func() {
|
||||
b := &bytes.Buffer{}
|
||||
|
||||
Reference in New Issue
Block a user