Write reserved bits for short header

This commit is contained in:
Mark Spanbroek 2020-09-28 13:04:06 +02:00 committed by markspanbroek
parent 77e3a39e2f
commit 1d250c9715
3 changed files with 12 additions and 0 deletions

View File

@ -42,6 +42,7 @@ proc write*(datagram: var Datagram, packet: Packet) =
case packet.form case packet.form
of formShort: of formShort:
writer.writeSpinBit(datagram) writer.writeSpinBit(datagram)
writer.writeReservedBits(datagram)
of formLong: of formLong:
writer.writeKind(datagram) writer.writeKind(datagram)
writer.writeVersion(datagram) writer.writeVersion(datagram)

View File

@ -82,3 +82,7 @@ proc writePayload*(writer: var PacketWriter, datagram: var Datagram) =
proc writeSpinBit*(writer: var PacketWriter, datagram: var Datagram) = proc writeSpinBit*(writer: var PacketWriter, datagram: var Datagram) =
datagram[writer.next].bits[2] = Bit(writer.packet.spinBit) datagram[writer.next].bits[2] = Bit(writer.packet.spinBit)
proc writeReservedBits*(writer: var PacketWriter, datagram: var Datagram) =
datagram[writer.next].bits[3] = 0
datagram[writer.next].bits[4] = 0

View File

@ -133,6 +133,13 @@ suite "packet writing":
datagram.write(Packet(form: formShort, spinBit: true)) datagram.write(Packet(form: formShort, spinBit: true))
check datagram[0].bits[2] == 1 check datagram[0].bits[2] == 1
test "writes reserved bits for short packet":
datagram[0].bits[3] = 1
datagram[0].bits[4] = 1
datagram.write(Packet(form: formShort))
check datagram[0].bits[3] == 0
check datagram[0].bits[4] == 0
suite "packet reading": suite "packet reading":
var datagram: seq[byte] var datagram: seq[byte]