Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions opendis/record/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ def recordLength(self) -> int:

@abstractmethod
def serialize(self, outputStream: DataOutputStream) -> None:
"""Serialize the record to the output stream."""
super().serialize(outputStream)
outputStream.write_uint32(self.recordType)
outputStream.write_uint32(self.recordLength)
"""Serialize the record to the output stream.

The record header (recordType u32 + recordLength u16, see 6.2.83)
is written by each subclass before its own fields.
"""

@abstractmethod
def parse(self, # pyright: ignore [reportIncompatibleMethodOverride]
Expand Down
2 changes: 2 additions & 0 deletions opendis/record/radio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ def marshalledSize(self) -> int:

def serialize(self, outputStream: DataOutputStream) -> None:
super().serialize(outputStream)
outputStream.write_uint32(self.recordType)
outputStream.write_uint16(self.recordLength)
outputStream.write_uint16(self.padding1)
self.netId.serialize(outputStream)
outputStream.write_uint8(self.todTransmitIndicator)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_StandardVariableRecord.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!python

import io
import unittest

from opendis.stream import DataOutputStream
from opendis.record.warfare import DirectedEnergyDamage


class TestStandardVariableRecord(unittest.TestCase):

def test_serialize_length_matches_marshalledSize(self):
record = DirectedEnergyDamage()
buffer = io.BytesIO()
record.serialize(DataOutputStream(buffer))
self.assertEqual(record.marshalledSize(), len(buffer.getvalue()))
self.assertEqual(record.recordLength, len(buffer.getvalue()))
self.assertEqual(40, len(buffer.getvalue()))


if __name__ == "__main__":
unittest.main()
Loading